Re:Programmers are confessing their sins to protest a broken...
by jghn on Tuesday February 28, 2017 @06:19PM
(#13759241)
As someone who has worked with a lot of languages over the years I can never remember which one is `length(x)`, `len(x)`, `x.length`, `x.len`, and so on.
For me the answer is "never", apparently. Then again I tend to struggle with basic syntax no matter what language I'm using or how frequently I use it.
Re:Programmers are confessing their sins to protest a broken...
by mdinstuhl on Wednesday March 01, 2017 @09:41AM
(#13763941)
You forgot sizeOf()!
If it makes you feel any better, I am in the same boat.
Re:Programmers are confessing their sins to protest a broken...
by sp332 on Tuesday February 28, 2017 @04:37PM
(#13758187)
I used Python for years, although I'm a little rusty now. I ran into that kind of problem all the time. Your first two examples are what came to mind first.
Re:Programmers are confessing their sins to protest a broken...
by Izmaki on Tuesday February 28, 2017 @05:32PM
(#13758838)
Just as many things I love about python, I hate about python.
Each time I get to the part where I need to modify the path which the import mechanism uses to look for modules, clean up the loaded modules to make sure I'm not reimporting an already loaded module by the same name, in order to import a module which is in the SAME DIRECTORY as - get this -__file__, I need another coffee.
Also "len(...)" is not obvious.
Re:Programmers are confessing their sins to protest a broken...
by adsims2001 on Tuesday February 28, 2017 @04:36PM
(#13758163)
Seems overly harsh. Why is the actual code, "len(s)" so much worse than your suggestion of "length(s)"?
Re:Programmers are confessing their sins to protest a broken...
by Fargren on Tuesday February 28, 2017 @04:50PM
(#13758346)
And I can't count the times I tried to do s.len() or s.length().
Re:Programmers are confessing their sins to protest a broken...
by charles-salvia on Tuesday February 28, 2017 @06:18PM
(#13759230)
Of course, s.__len__() actually works.
<sarcasm> The problem with Python is the arcane, arbitrary and nonsensical syntax. It sure as hell isn't anything as obvious as length(str) or string.length like any reasonable language.
And god help you if you want to do something complicated like define a function. </sarcasm>
But seriously: I have no problems with the rest of the article, but that one just seems silly. How many times do you have to look something like that up before it sticks? For those of you not versed in the more esoteric secrets of Python, you would use the built-in function len, as in len(str).
Of course there are alternatives: http://stackoverflow.com/questions/3992192/string-length-wit...
Edit: Added <sarcasm> tags for clarity.