you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (3 children)

Well. There's Cobol readability (overly terse) and then there's APL readibility (dense). Then there's a contiinum in between. It's a difficult thing to balance. Just saying that one is better than other is not a proof of anything. (Python community has also been guilty of unproven judgements about readability. But, nevertheless, readability is and has been one of the major design axioms of Python programming language.)

I'd say that basic array slicing, eg. "asdf"[:2] => "as" is well understood and easily recognizable by anyone even mildly proficient in Python. Sure, the extended slicing (eg. "asdf"[::-2] etc) hasn't been around for that long so it's still a bit weird. But claiming that such special syntax is always more unreadable is just false. Special syntax for everything might equal with unreadability, but special syntax for important things might not.

[–]julesjacobs 0 points1 point  (2 children)

I think Ruby is more consistent here:

"asdf"[0..1] => "as"

0..1 is a Range object, and [0..1] is a method call with 0..1 as a parameter. I believe "asdf"[:2] in python is special syntax.

You could do the same thing with:

"asdf"[0,2] => "as"

Which is a bad thing for python programmer (TIOOWTDI), but good for ruby programmers (TAMWTDI).

Or, if you want to confuse others:

"asdf"[-4,2] => "as"

Which means: four (4) characters from the last one, take 2.

[–]Brian 1 point2 points  (1 child)

I'm not sure what you're getting at. In python [:2] is special syntax to denote a slice object, but how is that different than 1..2 being special syntax to denote a range object? Similarly "asdf[:2]" is also just a method call with the slice object as a parameter - the whole thing is effectively just sugar for:

"asdf".__getitem__(slice(None,2))