5 ms·
One is left with very little doubt about the quality of such resources, when you see examples like [0]: def sum(list): sum = 0 for l in list:
by 0xmohit 10y ago
One is left with very little doubt about the quality of such resources, when you see examples like [0]:
def sum(list):
sum = 0
for l in list:
sum = sum + l
return sum
mylist = [1,2,3,4,5]
print(sum(mylist))
Hint: Observe the name of (1) the function, (2) the parameter therein.
[0] http://askpython.com/functions/ http://askpython.com/functions/
- burkaman 10y agoWhat's wrong with that
- fucking_tragedy 10y agoThey're shadowing builtins. Python's list type can't be referenced by its name in the defined sum function and Python's sum function can't be used in or after the new function's definition. One could argue that in a source meant to teach Python, it shouldn't use examples that don't follow best practices. I feel that as a resource to, from the page, "learn how to write code, the basics and see examples" that it doesn't really matter too much.
- scrapcode 10y agoI learned to program in PHP and builtins tripped me up a LOT as a new programmer. Talk about wrapping your head around some things when you're brand new.
- ATsch 10y agoI thought GP's issue was that the function is shadowing itself within itself, which I think is worse than shadowing a builtin with a similar function.
- fucking_tragedy 10y agoI had completely missed that one. That is pretty bad and confusing.
- wlesieutre 10y agoAnd using "list", which IIRC is a reserved keyword
- sporkologist 10y agoThis kind of thing leads to many "wait, what?" moments... confusing and aggravating to someone just learning syntax.
- deleted 10y ago[deleted]
- lolc 10y agoI agree that the choice of names is unfortunate. Still I think it's permissible in example code to redefine functions with your own implementation. At this point shadowing built-ins is unlikely to confuse anybody.
- Jugurtha 10y agoLearning things is fun. Having to unlearn things seldom is. This set bad habits in a discipline where a lot is muscle memory. I don't think it's a good idea. Furthermore, I tried hard to ignore the glaring similarities between this and Zed Shaw's "Learn Python the Hard Way" from the way the course is structured down to some expressions. This would have been cool if it at least mentioned the course on the right side pane with the other recommendations.
- _RPM 10y agoI recently failed a Google interview. I used Python. I believe I did solve the problem, but my code might have been the deciding factor in rejecting me. My code looked similar to this. For example, I implemented my own `min`. Which did a O(N) walk of the array. Probably a horrible choice on my end. Looking back I should have used more builtins.
- guessmyname 10y agoFor a company that takes around two months to review your profile and/or compare it with other candidates (or whatever they do during that time) I expect less arrogance during these code challenges because I am yet to find a developer who can write code like a robot.
- _RPM 10y agoWhat do you mean arrogance?
- tveita 10y agoNitpick: The built-in min() is also O(n) on the length of the array, though it will be a bit faster as a built-in C function. You're probably right that you shouldn't have reimplemented it though - knowing how to use the language and its standard library is a good indicator for real-word experience.
- _RPM 10y agoThis was for a new grad role though. I'm just about to get out of college. Looking back , I really fucked up by not using Pythonic style. The only reason I chose python is because of it's string handling capabilities, etc as opposed to C - where I'd have to implement boiler plate stuff most likely, and worry about resizing arrays, etc.
- deleted 10y ago[deleted]