6 ms·
> there is no such thing as good code definitely not true. this is good code: https://github.com/torvalds/linux/blob/master/fs/file.c https://github.com/torva
by 38 3y ago
> there is no such thing as good code
definitely not true. this is good code:
https://github.com/torvalds/linux/blob/master/fs/file.c https://github.com/torvalds/linux/blob/master/fs/file.c
this is good code:
https://github.com/golang/go/blob/master/src/strconv/atoc.go https://github.com/golang/go/blob/master/src/strconv/atoc.go
its formatted, commented, direct. the fact that you struggle with writing time tested code does not mean that everyone does.
- grepfru_it 3y agoI wrote some code that was years ahead of a distinguished engineer's existing code. He immediately saw where I was going and adjusted his code accordingly (by dropping my branch and authoring a new branch. I assume because he didn't understand git, but I believe he was protecting his future performance review). Some people won't admit someone else can write better than them.
- jiggawatts 3y agoBy linking to those examples you confirmed the point you were trying to refute. From my personal perspective this is mediocre code at best. It’s written in an unsafe language. Littered with macros, which in C are not hygienic and are land mines in waiting. Constants defined with lowercase and not actually marked as const. Double underscores everywhere, which are the bad alternative to namespaces seen in weak languages like C. WTF does “BITBIT_NR(nr)” do!? Does it “bit” the “bits”? What is NR? Is it a “number”? Then why not use “n” and drop it from the macro name? Abbreviations everywhere: ofdr, nfdt, fds, fs, etc… Then there is a long-winded explanation of how they pack bits into an array of longs. Okay, why not make this a reusable module of code? Because C is a weak language, or because the Linux kernel is spaghetti with a dozen implementations of bit maps? \* * Note that this can drive nr *below* what we had passed if sysctl_nr_open * had been set lower between the check in expand_files() and here. Deal * with that in caller, it's cheaper that way. Huuuurk. Sorry… did I just see a data race just casually commented as “okay because it is faster if it’s horrifically unsafe? Yes? No? Maybe? Do you even know?
- cookiengineer 3y agoI think I just fell in love with you. Finally a sane person <3 Honestly, I never understood why so many developers abbreviate function names or variables. Is it so much pain to type abc<tab> for auto completion? Why not simply name fd file_descriptor? Short names are a mental barrier and a level of abstraction that can easily be avoided.
- sudosysgen 3y agoIn some languages, that leads to terribly long lines that you then have to break down, add indentation, and it just becomes harder to read. There is happy middle.
- nemetroid 3y agoAnyone who has reason to read this file will have "fd" as a word in their vocabulary.
- buzer 3y agoShort names actually help with readability when they are commonly used. It's a lot quicker to go over the code when you don't need to read as much, similar to how one would write something like x+y=z in math instead of putting descriptive name for each variable in each step or using things "1€/kg" instead of "one euro per kilogram" (or let alone including kilogram's definition from SI standard).
- lcnPylGDnU4H9OF 3y agoDespite this, mathematical proofs still use a bunch of plain words to define things. In a programming context, if one has an “user” from the database, “user” is usually a better name than “u”.
- IggleSniggle 3y agoIt really is a context and frequency thing. For example: users.map(u => u.lastName) Nobody is going to have any questions about what 'u' is here. Do that in a codebase that has a 100% consistent and very frequently used User type, and it starts to feel quite reasonable to just use 'u'. It's as familiar as Apple π.
- imoverclocked 3y ago> the fact that you struggle with writing time tested code does not mean that everyone does Do you have a source on what I have managed to write or is this just guessing and calling it "fact?"
- 38 3y agopot: kettle you are black!
- voxelghost 3y agoReminds me of this good old rant from Peter Welch, Programming Sucks ... Every programmer occasionally, when nobody’s home, turns off the lights, pours a glass of scotch, puts on some light German electronica, and opens up a file on their computer. It’s a different file for every programmer. Sometimes they wrote it, sometimes they found it and knew they had to save it. They read over the lines, and weep at their beauty, then the tears turn bitter as they remember the rest of the files and the inevitable collapse of all that is good and true in the world. This file is Good Code. It has sensible and consistent names for functions and variables. It’s concise. It doesn’t do anything obviously stupid. It has never had to live in the wild, or answer to a sales team. It does exactly one, mundane, specific thing, and it does it well. It was written by a single person, and never touched by another. It reads like poetry written by someone over thirty. ... [ https://www.stilldrinking.org/programming-sucks https://www.stilldrinking.org/programming-sucks ]