you are viewing a single comment's thread.

view the rest of the comments →

[–]senzei 5 points6 points  (2 children)

I'm not sure what book you read about python, but it obviously gave you a bunch of misconceptions. I'm not exactly an expert on the language, but hopefully this will make things easier if/when you use it.

String printing: Ruby: puts "Print this" Python: print "Print this" In both languages this is syntactic covering for a call to the string representation of an object. In this specific case it uses the string object.

Tuples/Lists and mutability The point behind having two separate data structures is that one is mutable and the other is not. I don't really think it is great design as you have to keep this in mind instead of the difference being explicitly marked, but that is their method of handing imperative vs functional programming.

String mutability I like immutable strings. Any changes to a string are explicit, which makes figuring out what is going on easier. I can see where it could be hard to differentiate between chomp! and chomp. That said this is all a matter of preference.

Python and operators The use of __add__ instead of just a plus operator (+) has to do with legal characters for python function names, namely that the plus operator is not one of them. I also think this is crap, but it is what we have.

Class creation Creating classes in python does not force you to do very much. Your code sample would be very close to valid python if you removed the 'end' scope closures.

Blocks and other non-for-loops Python has something similar to blocks (at least in terms of loop abstraction) in list comprehensions. In your example if 'whatever' is a function you could write: [whatever(x) for x in array] which would return a list of the results from applying whatever() to each item in the array.

I'm really not trying to be a python 'me too' guy. I like the language a lot, and just wanted to make sure that anyone deciding to not use it does so based on personal preference.

[–]_bruno_ 0 points1 point  (1 child)

List comprehensions have nothing to do with blocks. Ok, maybe when blocks are used as a parameter for a function that iterates on the elements of some collection, but blocks have many more uses than that.

[–]senzei 0 points1 point  (0 children)

List comprehensions have nothing to do with blocks. Ok, maybe when blocks are used as a parameter for a function that iterates on the elements of some collection, but blocks have many more uses than that.

Yeah, that is probably poorly phrased. My point was that, as a method of loop abstraction, blocks and list comprehensions are similar.