News:

Having problems registering or logging in?
Contact us here.

Main Menu

programming

Started by carpediem, January 10, 2011, 10:19:40 PM

Previous topic - Next topic

carpediem

@Hitad: Matipid in a good way :). Ruby and Python are succinct languages. Kaya usually yung mga multi-line codes in other languages, pwedeng one-liner lang sa Ruby and Python.

For example (I'll use Python because it's the one I know), you want to extract the elements of a comma-delimited string to a list:

str = "apple, banana, cherry"
fruits = str.split(", ")


You variable friuits will be a 3-element list containing the fruits without the comma+space. (I think meron din ganyan sa PHP?)

Another example, suppose you want to multiply by 2 each of the element of an integer list that is even, and filter out the odd numbers:

int_list = [0, 1, 2, 3, 4, 5, 6]
int_list = [ n * 2 for n in int_list if n % 2 == 0 ]


The variable int_list will now contain 0, 4, 8, 12.

As you can see, succinctness is a beneficial characteristic that lets us wrap our understanding around the code more easily, and lets us focus on the intention of the code, without the need to wade though some unnecessary stuff. This also lets us do things more quickly.

Hitad

@eLgimiker0
Thanks sa pag-update! wew, bigyan ko muna time sarili ko. Ano nga pala yung SharePoint? hehehe bago lang sa tainga ko yan  ;D

@carpediem
Yep I was actually positive about that, if that was vague 8)
Quote from: carpediem on June 09, 2011, 06:28:13 PM
str = "apple, banana, cherry"
fruits = str.split(", ")

Yes meron na rin to sa php but the term is explode like:

$array = explode ('~',  'pinoy~guy~guide') ;

then to re-connect them it'll be:

implode($array);

about the second example, that's really neat lol, in php it will take a bit more effort to code:

$int_list  = array(0, 1, 2, 3, 4, 5, 6);

foreach($int_list as $value){
    print($value % 2 == 0 ? $value * 2 : NULL);
}

I'm quite familiar with the succinctness because of the demand of frameworks in the job description.
Frameworks like the following are almost omnipresent in any job description I see :/
Tapos baba pa sweldo dito lol.

[url = http://framework.zend.com/]zend[/url]
[url = http://codeigniter.com/]codeigniter[/url]
[url = http://www.symfony-project.org/]symfony[/url]




Hitad

Just discovered something new but still vague to me. The term is "closure"  :-[

carpediem

You have to have some experience with functional programming to get the purpose of closures.

A closure is a function defined with "free variables" inside it. These free variables are not local to the function or arguments (parameters) of the function.

Check the Wikipedia entry. There are some examples.

Hitad

Yep javascript is a prototype-based language.
Just discovered closure while exploring JS. Hate ko talaga to kahit simple lang, pero maraming "kakaiba"
meron daw kasi memory leak issues pag sa IE and some related matters kaya ko to na-encounter.
Iba naman ang definition sa php ng closure, anonymous functions daw but then that's not the same as the javascript case. geeez


carpediem


Hitad

wahehehe.. Matagal ko na rin nakita yan. I'm through with closures, naintindihan ko naman kahit papano  8)
btw how often do you guys make use of recursive functions? Palagi ba?  :'(
minsan ko lang kasi nagamit when I was making a file tree. I'm not really good with this technique since I'm not mathematician. Like the fibonacci thingy which drived me insane as fak!

carpediem

sometimes recursion is a great convenience, especially when the requirement can be expressed recursively. for example traversing a tree structure.

in practice, a recursive solution is usually less efficient than the corresponding iterative one because of the overhead.

medyo magulo sya at first, kasi kailangan mo i-keep track sa utak mo kung ano nangyayari or kung ano dapat mangyari. pero once nasanay ka, madali lang din. masmadali nga minsan kasi mas expressive nga ang recursive solution.

sabi nga nila, "To iterate is human. To recurse, divine."

eLgimiker0


Hitad

^I've never seen a female so good at programming. I hope I could see one. hohohoho...

P.S. Ay meron pala, yung classmate ko dati  :o

Quote from: carpediem on June 24, 2011, 03:26:33 PM
"To iterate is human. To recurse, divine."
Recursive functions are nightmare to visualize.
I would rather buy the first sentence.

carpediem

Some trivia:

The first computer programmer was Ada Lovelace, for whom the Ada language was named :)

Grace Hopper developed COBOL, the third oldest programming language I think.

Hitad

Wow di ko alam yan ah. Uhmazing!  :o

carpediem

Programming challenge:

Using Philippine Peso denominations (not including centavos), how many ways can you make a sum of 100 Pesos?

(The denominations to be used are 100, 50, 20, 10, 5, 1)

For example:
- one 100-Peso bill
- one 50-Peso bill + one 20-Peso bill + two 10-Peso coins + one 5-Peso coin + five 1-Peso coins.

Hitad

^
Are we going to make a program for that?
O sasabihin lang kung ilang posibilitad?  :)
Also ok lang mag recur yung isang no. ?

carpediem

^ Yes make a program to count the number of combinations. Well kung magaling ka sa math baka pwede i-solve mathematically, although I don't know how. :)

Not sure what you mean by recur yung isang no. Basically we want the number of ways we can form a sum of 100 pesos. The previous example gives two ways, another way is:

- one 50-Peso bill + ten 5-Peso coins.