[HN Gopher] My Favourite Diff ___________________________________________________________________ My Favourite Diff Author : jwatzman Score : 19 points Date : 2020-04-05 17:25 UTC (5 hours ago) (HTM) web link (essays.jwatzman.org) (TXT) w3m dump (essays.jwatzman.org) | ChrisMarshallNY wrote: | Cool story. | | I use Swift. It does not have default switch fallthrough. After a | couple of versions, they (reluctantly, I'm sure) added one (but | you have to ask for it explicitly). | | I remember being frustrated by it, at first, but, like so many | Swift oddities, it rapidly became second nature; thus, proving | out that one of the goals of Swift is to train developers to | write code properly. | JadeNB wrote: | Since there's not much context here: the article, which I | enjoyed, ends with "Be the change you want to see in the world", | and shows how the author exemplified this by coding a fix to a | persistent source of PHP bugs at $WORK. | aasasd wrote: | As a technical aside (I know it's not the main point, but still): | with the ubiquity of Git workflows employing pre-merge checking | on the platform of choice (e.g. Github or a CI tool), this is | rather easily done via a rule in an off-the-shelf linter. No | `break` in a `case`? Can't merge it. | | As a language-design aside, `switch` in general is stinky stuff. | Not just with the fall-through: it also violates the regular | C-style syntax for no particular reason, having a mini-syntax of | its own instead. | | But the most perverse thing I've seen done with `switch` is using | it as `if`: switch (true) { case | ($a == $b): ... case ($c == $d): ... case | (itsFullMoonToday()): ... default: ... } | jacobparker wrote: | We think like this at $WORK a lot at. Sometimes the language you | want is a subset of the language you have. | | SQL allows "blind inserts" ("INSERT INTO MyTable VALUES (1, 2)" | vs. "INSERT INTO MyTable(colA, colB) VALUES (1, 2)") but this | causes grief when the definition of MyTable changes over time... | so we just don't allow that. Here's a blog post by a coworker | with some more details: | https://michaeljswart.com/2017/02/a-program-to-find-insert-s... | We also have some in-house static analysis tooling we run on our | SQL. | | C# allows method parameters to supply default values. There is | some reasons to be wary of this feature generally, but there is | something extra-bad about it: with inheritance and interfaces | some declarations could have defaults and some not... and even | worse, they can be inconsistent. It's not always obvious to | everyone which method declaration is relevant at a call site | (especially with stuff like var). This is some extremely | uninteresting trivia that no one actually wants, so we just block | it. Source: | https://github.com/Brightspace/D2L.CodeStyle/blob/master/src... | and some literate-style test cases (imagine the stuff between the | block-style comments is drawn as a red-squiggle in Visual | Studio): | https://github.com/Brightspace/D2L.CodeStyle/blob/master/tes... ___________________________________________________________________ (page generated 2020-04-05 23:00 UTC)