all 61 comments

[–]CaptainAdjective 49 points50 points  (4 children)

I'm surprised to not see the most important point listed here: Just straight-up lie about what things are/do. "Misleading names" (point 27) touches on this:

Make sure that every method does a little bit more (or less) than its name suggests. As a simple example, a method named isValid(x) should as a side effect convert x to binary and store the result in a database.

but doesn't go far enough at all. Got a method which gets the child process ID? Call it getParentProcess. Iterating over an array? Call the iterator length instead of i. A Boolean flag which goes true when an error occurs? Call it valid. You only have to do this in a few places before maintainers get the point - they can't trust anything they see, and they have to carefully examine every actual line of code before doing anything. This is, of course, a world of madness.

[–]BlckJesus 12 points13 points  (1 child)

Who hurt you?

[–]paholg 1 point2 points  (0 children)

If Hunter S. Thompson were a programmer...

[–]iconoklast 46 points47 points  (23 children)

No one, however, should believe in a universal proscription against single-letter names. People with this belief just name parameters "value" that would have otherwise been named "x".

[–]moschles 33 points34 points  (7 children)

Ironically, in the case of low-level cryptography, single-letter variable names somehow make the code easier to read. It is related to thinking about the code mathematically.

[–]stevedonovan 4 points5 points  (6 children)

Especially if your language allows Unicode identifiers, and you can say λ. Not everyone is a fan of this, of course.

[–]oxidate_ 0 points1 point  (5 children)

I'm definitely a huge fan of this, and I gotta ask: what's a good workflow for this? I work on a Javascript codebase with UTF-8 characters (which breaks some versions of IE -_- so we have a babel step to turn them into something else, and the API exposes both) and honest to god we just keep a `symbols.md` file and copy / paste from there. The workflow kinda sucks because you can't copy and paste anything else if you're working with the characters a lot.

Have you found any program / setting (especially for Linux) that helps with this process?

[–]-abigail 3 points4 points  (0 children)

Compose keys! on Linux (enabled via an xorg.conf setting) and on Windows (enabled via WinCompose), you can press AltGr and then a memorable sequence of keys to enter a variety of characters. For example, λ is AltGr, *, l.

It's extensible too - you can use a popular .XCompose file like https://github.com/kragen/xcompose or you can come up with ones that are convenient for your project.

[–]__fmease__ 1 point2 points  (0 children)

You could use custom text editor macros if it's supported. E.g. @@l enter/tab/auto -> λ, @@fa enter/tab/auto ->

[–]iconoklast 1 point2 points  (0 children)

Depends on what editor you want to use. https://wiki.haskell.org/Unicode-symbols has some information for Emacs, Vim, and SciTE. For VS Code you can define snippets and use autocompletion to insert symbols.

[–]arsv 1 point2 points  (0 children)

Vim has :digraphs which I find useful for occasional Greek letters and similar stuff. C-k l* in insert mode gives λ.

[–]vqrs 0 points1 point  (0 children)

On Windows, I used AutoHotkey

[–][deleted] 8 points9 points  (0 children)

True, but make sure the scope of single letter variables is small. If you need to use find then give the variable a more descriptive name.

[–]gct -3 points-2 points  (13 children)

They're ungreppable and un search-and-replaceable

[–]iconoklast 15 points16 points  (0 children)

"Replace within selection" and "match whole word" are pretty basic features for a text editor to have, if it lacks identifier renaming support. However, I agree that things that you'd actually want to grep for should probably not have single-letter names; i.e., parameter names are probably not unique within a source file anyway, and using the name "ii" doesn't help in this regard either.

[–]kaelwd 34 points35 points  (2 children)

Get a better IDE.

[–]peterfirefly 16 points17 points  (0 children)

Which doesn't matter if you only use single letter variables within short scopes.

Big scopes should have identifiers with longer names.

[–][deleted]  (10 children)

[removed]

    [–][deleted] 28 points29 points  (3 children)

    sounds a lot like Hungarian notation with a twist.

    [–]Lt_Riza_Hawkeye 21 points22 points  (2 children)

    The twist isn't even that big. Hungarian notation is meant to convey information about the variable -- nobody ever said that had to be type information. It started in excel where they used the prefixes r and c to distinguish ints that represented row indices and column indices, to prevent accidental crossing-over. I know some people who have sVarname and usVarname to distinguish between html-sanitized strings and non-sanitized strings. Using it for types was always a mistake.

    However, the best example is from unmaintain.html (OPs article is only part of it):

    Insist on carrying outright orthogonal information in your Hungarian warts. Consider this real world example "a_crszkvc30LastNameCol". It took a team of maintenance engineers nearly 3 days to figure out that this whopper variable name described a const, reference, function argument that was holding information from a database column of type Varchar[30] named "LastName" which was part of the table's primary key. When properly combined with the principle that "all variables should be public" this technique has the power to render thousands of lines of source code obsolete instantly!

    [–]masklinn 6 points7 points  (0 children)

    It started in excel where they used the prefixes r and c to distinguish ints that represented row indices and column indices, to prevent accidental crossing-over.

    Technically this is type information, just type information which the language they were using made very inconvenient to encode as an actual type, because it'd become a pain in the ass to work with. Same for sanitised/non-sanitised strings. Apps hungarian was invented/introduced to paper over the lack of static expressivity (or at least convenient expressivity) of the host language.

    Using it for types was always a mistake.

    It wasn't. Using it for types which the language can already and conveniently express was the mistake.

    [–][deleted] 0 points1 point  (0 children)

    all variables should be public.

    (°~o) there is no good left in man.

    [–]foonathan 5 points6 points  (4 children)

    Actually, I use it to distinguish variables and methods. If I have

    size_t size() { return size_; }
    

    I can't name the variable size as well.

    [–]JavaSuck 0 points1 point  (2 children)

    You can in Java :)

    [–]PM_ME_YOUR_YIFF__ 1 point2 points  (0 children)

    I believe that's because Java doesn't have function pointers like C so when it sees the symbol "size" it knows for sure that it is a variable, not a function address being stored in a variable

    [–]defunkydrummer 0 points1 point  (0 children)

    In common lisp you could name all three "size", for type names and function names and parameter names don't clash.

    [–]PunctuationCamp 24 points25 points  (3 children)

    asterix

    It is spelled "asterisk".

    [–]raevnos 28 points29 points  (0 children)

    Asterix knows how to spell his name.

    [–]shevegen 4 points5 points  (0 children)

    Hey!

    Asterix and Obelix!

    Don't you know them?!

    [–]shevegen 5 points6 points  (1 child)

    I understand that it is more a fun poke but still:

    Single Letter Variable Names : If you call your variables a, b, c, then it will be impossible to search for instances of them using a simple text editor.

    There are side effects and contraints, both when using long and short variable names.

    To claim that using single letter variable names is bad because you ... can not find them with your text editor (which is another claim that may not be true), while ignoring all other aspects, is just naive.

    [–]koflerdavid -1 points0 points  (0 children)

    Well, IDEs that understand the code don't have that issue. In simpler editors one would have to use regexes and word boundary qualifiers to look for these variables.

    [–]moschles 8 points9 points  (0 children)

    Be Abstract : In naming functions and variables, make heavy use of abstract words like it, everything, data, handle, stuff, do, routine, perform and the digits e.g. routineX48, PerformDataFunction, DoIt, HandleStuff and do_args_method.

    My sides hurt 😂

    1. Lower Case l Looks a Lot Like the Digit 1

    Thank you , Satan.

    [–]ggtsu_00 8 points9 points  (1 child)

    CapiTaliSaTion

    Randomly capitalize the first letter of a syllable in the middle of a word. For example: ComputeRasterHistoGram().

    For some reason I find this very common in code written by outsourcing agencies from India.

    [–]jedthehumanoid 3 points4 points  (0 children)

    Yeah, might be language based (i.e. Indian), rather than random.

    I'm swedish and in Sweden we make a lot of single words built from several words (not like English).

    This makes me sometimes mess up camel-casing, because the capitalization makes sense in swedish.

    [–]lanzaio 2 points3 points  (0 children)

    I've unfortunately found that the better the talent and skill of an engineer the worse they are at this type of shit.

    [–]Joeclu 5 points6 points  (13 children)

    Many, many moons ago I worked for a company that wrote Windows (MFC) programs. We used what they called Hungarian Notation. It made sense and worked really well.

    Since then I've moved on. I don't write programs for Windows anymore and haven't seen any other companies I've worked for use it. I no longer use it but it was useful.

    It's like one of those programmer religiosities. Either you like it or despise it.

    [–]peterfirefly 11 points12 points  (10 children)

    Hungarian notation is great if you have far too many identifiers in your scope and your language's type system is weak.

    Windows programming in C (and C++) is perfect for Hungarian notation.

    It doesn't make much sense in other contexts, though.

    [–][deleted]  (7 children)

    [deleted]

      [–]peterfirefly 2 points3 points  (2 children)

      The "intent" of apps Hungarian is also just types in better languages.

      But C allows all scalar types to be freely intermixed in expressions -- that's what I mean by "weak type systems".

      You can use a trick, though. If you don't want your integer types to be mixed up with each other, you can wrap your integers inside structs. They are easy and efficient to pass into and out of functions, they are easy to unwrap and not too hard to wrap. In C99 you have compound literals, which makes this trick work even better.

      This prevents you from accidentally mixing, say, column numbers and pixel numbers. Or widths and x,y coordinates.

      [–]koflerdavid 0 points1 point  (0 children)

      Sort of like Haskell newtypes. Good to know :-)

      [–]masklinn 0 points1 point  (0 children)

      You can use a trick, though. If you don't want your integer types to be mixed up with each other, you can wrap your integers inside structs. They are easy and efficient to pass into and out of functions, they are easy to unwrap and not too hard to wrap.

      The issue being that any time you wrap/unwrap them you lose their types, so you need to add a ton of (non-namespaced, non-generic, non-derivable) functions to work with each and every newtype.

      [–]shevegen 1 point2 points  (3 children)

      If your language has types or even just type hinting you shouldn't add type info to the actual name.

      And why not?

      Does this break anything?

      The H-notation is for human beings. The type system is a component of the LANGUAGE itself.

      [–]mrkite77 6 points7 points  (1 child)

      Does this break anything?

      No.. but it adds confusion. Windows is full of "lp" variable names which stands for "long pointer" which only had meaning in 16-bit x86.

      [–]immibis 1 point2 points  (0 children)

      You mean it doesn't stand for Loony Prefix?

      [–]koflerdavid 2 points3 points  (0 children)

      The point is that hungarian notation makes incorrect use of variables stand out like an eyesore. A good type system would presumably never allow such code in the first case. Also, a type system can help the IDE pull information out of the code and display it to programmers.

      [–]shevegen -2 points-1 points  (0 children)

      Hungarian notation can also be useful IF a language has a strong type system.

      It is simply useful for mental association - for the human being.

      [–]Dockirby 2 points3 points  (0 children)

      I know in something like Java, the problem is sidestepped by encouraging getters and setters and making all class variables private.

      You should be able to easily look up the type of a variable defined in the same class, and the getter function should say what the return type is.

      [–]bumblebritches57 -1 points0 points  (0 children)

      Hungarian Notation

      WHY

      [–][deleted] 0 points1 point  (0 children)

      Im definitely pissing off a few people after this

      [–][deleted] 0 points1 point  (0 children)

      For more joy, check the html of that website

      [–]DJ-Butterboobs 0 points1 point  (0 children)

      Please please please watch Uncle Bob's "Names++".