Open Menu
AllLocalCommunitiesAbout
lotide
AllLocalCommunitiesAbout
Login

Clever code is probably the worst code you could write

⁨17⁩ ⁨likes⁩

Submitted ⁨⁨11⁩ ⁨months⁩ ago⁩ by ⁨bot@lemmy.smeargle.fans [bot]⁩ to ⁨hackernews@lemmy.smeargle.fans⁩

https://read.engineerscodex.com/p/clever-code-is-probably-the-worst

HN Discussion

source

Comments

Sort:hotnewtop
  • porous_grey_matter@lemmy.ml ⁨11⁩ ⁨months⁩ ago

    Everyone’s level of clever/readable is different

    source
  • mindbleach@sh.itjust.works ⁨11⁩ ⁨months⁩ ago

    Code golf’s more sensible cousin is code bonsai. You don’t remove something unless the outcome is more elegant.

    Don’t do stupid shit like single-letter variables, or cramming everything into one line, or functionifying anything that happens twice. But if you can generalize something that happens a bunch and turn a lot of copy-paste boilerplate into slightly magic-looking function calls, absolutely chop all those blocks down to one name and a couple references.

    And then comment on it, you fucking animal.

    source
  • Nevoic@lemm.ee ⁨11⁩ ⁨months⁩ ago

    Coding happens in languages. This works much the same way as natural language, sometimes you’ll speak in a way that is very clear to you and people who speak that language, but not to others.

    sumSquares = sum . map (^ 2)
    

    vs

    def sumSquares(numbers):
        result = 0
        for number in numbers:
            result += number ** 2
        return result
    

    Function composition is clear to people who speak Haskell, and eliminating mutation/untracked side effects helps to keep behavior local and gives equational reasoning. You can ask your IDE what the type of sumSquares is, and immediately know without looking at the implementation that there are no side effects, and what the types are.

    On the flip side, most programmers can read basic Python, the C family of languages has seen more adoption, and Python simplifies a lot of the syntax/concepts down to their most basic forms. Python tries to be the most like English, and this is both its greatest strength and weakness (English can be an abysmal language for structured data processing).

    source