Hacker Newsnew | past | comments | ask | show | jobs | submit | augustk's commentslogin

Postconditions are in conflict with programmers' love of early returns.

Formally, it doesn't appear to be so (tests can be added to each early return); in practice, encouraging the reorganization of messy early returns would be zero cost developer reeducation.

It's also worth noting that statements like

  for (i = 1; i <= 100; i++) {
    S;
    if (P) {
      break;
    }
  }
are just as bad since `break' (and `continue' and early `return') are a just gotos in disguise.


They are just gotos, but does that mean that they are bad (along with their friend try/catch, who is also a goto?), or does that mean that gotos can be useful when used with restraint?

Gotos get a bad rep because they become spaghetti when misused. But there are lots of cases where using gotos (or break/continue/early return/catch) makes your code cleaner and simpler.

Part of a programmer's job is to reason about code. By creating black and white rules like "avoid gotos", we attempt to outsource the thinking required of us out to some religious statement. We shouldn't do that.

Gotos can be useful and can lead to good code. They can also be dangerous and lead to bad code. But no "rule of thumb" or "programming principle" will save you from bad code.


Yes, break, continue, and return are all "just" gotos in disguise. But they restrict the power of the goto enough to not cause the problems that goto causes while providing a good deal of semantic power to users. Namely, all of these are essentially variations on early return (you can also throw in the logical && and || operators here, albeit they are slightly different in having two exit points rather than one--they're a fusion of if and break, essentially). And it sort of turns that there are a lot of cases where "return when any of these conditions, tested in a particular order, holds" turns out to be the most natural way to express an algorithm, and these goto-like constructs are the most natural way to write them.

(FWIW, this is essentially the argument that Knuth makes in his defense of goto paper)


The argument in the article was that the for loop is (potentially) "lying" and that is still true in my example. Niklaus Wirth's Modula-2 had a LOOP statement in which an EXIT statement could occur anywhere. That statement was at least not misleading. In Wirth's last revision of his last programming language Oberon the loop statement is removed and return is no longer a statement but a clause at the end of a function procedure. This makes Oberon a purely structured language.

https://miasap.se/obnc/oberon-report.html


"universal access to a large universe of documents"

It's a sad fact that a large part of the web doesn't work without Javascript, a technology which enables privacy-invasive practices (and surveillance capitalism). It wasn't as bad when progressive enhancement was the norm.

https://en.wikipedia.org/wiki/Progressive_enhancement


With so many ready meals to choose from I don't understand why anyone nowadays would cook anything from scratch.


Should be easy to correct the default behavior for the next release if the issue is reported.


In the best scenario the developers are also active users of the software they produce. Then a design flaw or an error that affects the users will also affect the developers and will (hopefully) motivate the latter to correct it.


Its also useful for developers to have a way of bypassing customer support to have direct visibility into what issues the actual users are experiencing. This can come in the form of browsing tickets, online forums, or social media.

Often something that's easily brushed off by a support rep will ring a bell in the mind of a developer who has recently worked in the area of the code related to the issue.


XP putting a customer on the team was the best thing in the methodology. Replacing those with business representatives is one of Scrum's original sins.


> XP putting a customer on the team was the best thing in the methodology.

Recently my boss said to me: "Customers want something that WORKS. If you deliver something, and it doesn't work, what's the customer going to think?" The huge drawback to putting a customer on the team is that the customer probably doesn't want to know, let alone be involved with, how the sausage is made. They want a turnkey solution unveiled to them on the delivery date, all ready to go, with no effort on their part.

Generally what you want is a customer proxy in that role, who knows or can articulate what the customer needs better than the customer themselves can. Steve Jobs was a fantastic example of someone who filled this role.


It's also worth noting that a customer is not necessarily a user. As a developer I don't care so much about the customer but I care wholeheartedly about the users.


Progressive enhancement is the way to go if you care about technical excellence. For some reason it fell out of fashion.

https://en.wikipedia.org/wiki/Progressive_enhancement


It fell out of fashion because the entire web was consumed by react.


> if you care about technical excellence

Or accessibility.



And also bring back progressive enhancement.

https://en.wikipedia.org/wiki/Progressive_enhancement


Or create the family


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: