viernes, 14 de mayo de 2010

Parameterizing

There are two ways to pass values to functions. I will state examples using PHP:
  1. showUser('Ignacio','Cortorreal');
  2. showUser(array('name'=>'Ignacio','last'=>'Cortorreal'));
Each one has advantages and drawbacks. At the end, when you are building an API, you must choose what to do. The first version is older, and I have started to valorate the older although, for analysis, it is too painful, but more efficient. Will the Old one version minimize "supposed logic errors" because of its strong typing? No! Neither the New one.

The power of the New one is that parameters can be expressed in any order!! For example, if you want to add the middle name and a second last name to showUser() function, we can add it, and it won't bring problems to other code using that function, but its interface and implementation stars to become a mess, something that is somewhat reduced with the Old method.

DOS
  • format /q/u/v/c/s
  • g++ -Wall hello.cpp -o hello.bin
  • type a.txt b.txt
  • grep -v " OK "
JS (PROGRAMMING)
  • save({a:1,b:2,c:3});
  • sum(1,2,3);
WEB
  • /products/view/5/1
  • /products/list/page:3/sort:desc/
  • script.php?first=john&last=doe
SQL
  • Horizontal Vs. Vertical Structures:

IDFirstLast
3IgnacioCortorreal

--Vs--

IDFieldValue
3FirstIgnacio
3LastCortorreal

In lambda calculus, each function has exactly one parameter. The process to emulate multiple parameters is called currying. It looks crazy, but I think it is the way to go if we want to find a new order for these Parameters' disorder. Python supports this kind of paradigm, and is my next language to study after I achieve a basic-intermediate level of my C++ abilities. I was looking to Haskell or LISP, but Python's documentation on the web is way too much better.

This is the strongest Yin-Yang I have found in programming. Which one to choose?

2 comentarios:

  1. What about ruby? It's gaining a lot of popularity lately.

    ResponderEliminar
  2. Its community. I don't like how they market it. They are like politicians... only stating faults of others, instead of all their supposed own features. Also, Python has some flexibilities for general programming and it's recommended by the author of "The Cathedral and The Bazaar" and "Why Python?", but in terms of communities, I think PHP is the best!

    ResponderEliminar