Reading code from top to bottom (1999)
1–10 of 15 posts
Re: Reading code from top to bottom (1999)
#2Tom Duff: Reading Code From Top to Bottom (1999) - https://news.ycombinator.com/item?id=2620872 - June 2011 (22 comments)
Not sure how the 1999 ended up there but it looks plausible enough so I'll copy it.
Re: Reading code from top to bottom (1999)
#3 if something:
return something
if something else:
return something else
return default
It's not applicable everywhere, but where it is, it seems tidier to me than the alternative: if something:
return something
elif something else:
return something else
else:
return default
Edit: The article basically says the same thing. I just had a hard time parsing all that C at first.Re: Reading code from top to bottom (1999)
#4Related: Tom Duff: Reading Code From Top to Bottom (1999) - https://news.ycombinator.com/item?id=2620872 - June 2011 (22 comments) Not sure how the 1999 ended up there but it looks plausible enough so I'll copy it.
Yesterday (Feb 21, 1999) I rewrote [...]
Re: Reading code from top to bottom (1999)
#5I’m indifferent in practice (whatever’s readable to others is usually best), but I like the limit approach in theory.
Re: Reading code from top to bottom (1999)
#6Re: Reading code from top to bottom (1999)
#7Re: Reading code from top to bottom (1999)
#8I prefer code in this style too: if something: return something if something else: return something else return default It's not applicable everywhere, but where it is, it seems tidier to me than the alternative: if something: return something elif something else: return something else else: return default Edit: The article basically says the same thing. I just had a hard time parsing all that C at first.
The former is often not possible (or idiomatic) in expression based languages however.
Re: Reading code from top to bottom (1999)
#9> The best reference on programming in a disciplined way using goto is still D. E. Knuth's paper Structured Programming with go to Statements, ACM Computing Surveys, Vol. 6, No. 4, December 1974, pp. 261-302. I think that everything I have to say about goto is in his paper.
https://scholar.google.com/scholar_lookup?title=Structured%2...
It has received only very little discussion here on HN
https://hn.algolia.com/?dateRange=all&page=0&prefix=false&qu...
Re: Reading code from top to bottom (1999)
#10Similar thing with avoiding nesting and else clauses - generally a good idea, but occasionally they're the right choice, so better not to be dogmatic about it.