4 ms·
Just as with everything there is a sweet spot. I personally feel some things need to stay verbose while some things are implementation and not inherently needed
by gravypod 10y ago
Just as with everything there is a sweet spot. I personally feel some things need to stay verbose while some things are implementation and not inherently needed. Before college, I didn't do any python. After touching the language because of a class I like some of the things they do. For instance:
for i in range(10):
print(i)
This is a great way to show a way to print 0-9 to stdout. This is great. Contrary to this, you have a more c-like method of writing this.
for (int i = 0; i < 10; i++) printf("%d\n", i);
This is the same code, but we have a lot more stuff here that convey a lot of meaning. This is fine for me. The construct is dense, but it's not overly dense. It is simple because once you see it the first time, you will understand it and it will always make sense to you no matter how many years pass. I'm fine with this extra verbosity.
On the other side of the spectrum you have this:
map(print, range(10))
This is far fewer characters, but it's more difficult to understand. There are more things to understand if you've never done any functional programming. This sort of dense solution is frowned upon in many cases, especially since this sort of thing rarely scales efficiently in the sense of cognitive load. I did all of my CS labs using map/reduce formulas for CS100 and it did nothing but make things harder and drive a large appreciation for expanding statements into my heart.
- chaoxu 10y agoThat map is doing an impure operation. The order of application matters. Otherwise, for people who learned functional programming from the start, it's much easier to understand.
- witty_username 10y agoI find the map solution simpler than the for loop as there is no loop variable.
- gravypod 10y agoIt's simpler, much simpler, in this context. It's not simpler when you scale up the implementation being used. After you scale it up it stops being simpler and starts being `clever`. "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." − Brian W. Kernighan