News for hackers. Stuff that matters.
Re:Effect of Perceptual Load on Performance Within IDE in Pe... by sodapopcan on Friday July 14, 2023 @01:05PM (#36726717)
> why I try to keep functions/modules as simple as possible and ideally not longer in length than I can see on my screen at once (when possible)

This is the paradox of "readable" code. Each person has a different definition of it. I also prefer to write as dumb code as possible (well, these days I do, I of course tried to be extra clever in my earlier days). But for me it's the jumping around that makes me lose focus. My limit is about 3-4 jumps. This is not to say I write long meandering functions, but I personally couldn't imagine a codebase I'd be happy working in that is made up of modules that fit on a screen. Maybe it's possible! But the projects I've worked on that have a linter rule of "100 lines per file" or whatever end up being these rabbit holes. It's so hard to come up with code design guidelines everyone can agree on.

As a side note, I despise things like imports and aliases. I'd prefer that when I do jump to a function, I can read it without having to check if anything is imported or not. I always opt for fully qualified function calls, regardless of how many characters it is.

Re:Effect of Perceptual Load on Performance Within IDE in Pe... by seabass-labrax on Friday July 14, 2023 @01:39PM (#36727298)
> As a side note, I despise things like imports and aliases. I'd prefer that when I do jump to a function, I can read it without having to check if anything is imported or not.

One idea might be to use an LSP (Language Server Protocol) interface. It could describe the fully qualified symbol for you when you, say, select the abbreviated symbol or press a keyboard shortcut. I've been working on a moderately large C program with Emacs and clangd[1] recently and have been amazed at how 'immersive' it feels, and that's from someone who's used to the comfort of a Lisp REPL!

[1]: https://clangd.llvm.org/

Re:Effect of Perceptual Load on Performance Within IDE in Pe... by sodapopcan on Friday July 14, 2023 @01:57PM (#36727559)
I work in Elixir and there are LSPs available. I'd still rather be able to just read and take as little action as possible to have to figure out where something is coming from. But as a sibling commenter says, they hate long names, so it's impossible to please everyone and comes down to teams making agreements.
Re:Effect of Perceptual Load on Performance Within IDE in Pe... by ziml77 on Friday July 14, 2023 @01:50PM (#36727475)
For me it's not just the jumps but also overly long names. My ability to quickly scan the code is hindered by names that all jumble together because they aren't visually distinct enough. And when they read like a book, I'm going to have the same problems I have when reading books where I'm somehow reading all these words across the page but at the same time not actually processing any of it.
Re:Effect of Perceptual Load on Performance Within IDE in Pe... by sodapopcan on Friday July 14, 2023 @01:59PM (#36727584)
What constitutes an overly long name for you? Are you talking Java-y things likes `UserAccountBuilderFactoryFactory` or even just something like `operation` instead of `op`?
Re:Effect of Perceptual Load on Performance Within IDE in Pe... by jacoblambda on Friday July 14, 2023 @03:13PM (#36728592)
not OP but I think even just `operation` vs `op` should be self explanatory for the majority of devs. And documentation can dispel any doubt regarding the interpretation of the name.

Terse naming is just fine as long as the names are visually distinct from those in the same scope/namespace and as long as engineers/developers are religious about proper documentation.

i.e. members/classes/types/fn/etc getting a doxy/doc description and local variables getting a `//` comment if their meaning and use isn't easily derivable from the immediate context.

If that isn't happening however, you probably need to be pushing for more descriptive names or better docs during code review.

Re:Effect of Perceptual Load on Performance Within IDE in Pe... by sodapopcan on Friday July 14, 2023 @03:27PM (#36728769)
It's self-explanatory for sure, but I would prefer the actual domain term be Op as well. IE, I really dislike `op = Operation.new()` or whathaveyou. This breaks stuff like editor highlighting and whatnot. It's also harder to keep consistency through a codebase. Like maybe some people do `o = Operation.new()`. I find very high cohesion here helps my code-scanning a ton.

I'm not saying that would be true for anyone, just furthering my premise that it's different for everyone.

Re:Effect of Perceptual Load on Performance Within IDE in Pe... by ziml77 on Friday July 14, 2023 @07:45PM (#36731498)
For the `operation` vs `op` example, it's highly contextual. If it's used in a narrow scope or if it's repeated many times (like I've seen in functions that copy fields of one structure to another), `op` is preferable. Otherwise I'm fine with `operation`.

The Java naming is one cause of what I really have a problem with. Like that name on it's own isn't the worst because the key info is right at the start and I'm probably not going to see the type name in function bodies I'm trying to follow. It's when that naming is combined with other overly verbose naming that it gets really gets bad: `CreateUserFromUserAccountBuilderFactoryFactoryOnBackgroundThread()` By the time I've read "BackgroundThread" I'm glancing backwards to see what is happening on the background thread.

Other places where longer names make reading harder are when the names are very similar. With `textBoxXPosition` and `textBoxYPosition` the X and Y get lost too easily. You could rearrange the letters to the front to help with that, but it can still make computations harder to read: `sqrt(xTextBoxPosition * xTextBoxPosition + yTextBoxPosition * yTextBoxPosition)` vs `sqrt(x * x + y * y)` or `sqrt(tbx * tbx + tby * tby)`

Re:Effect of Perceptual Load on Performance Within IDE in Pe... by sodapopcan on Saturday July 15, 2023 @11:09AM (#36737497)
I think we're mostly in agreement here, thanks for sharing!

I actually always write full variable names, even in narrow scopes. This is mostly because I'm used to programming in dynamic languages and it makes renaming much easier. I've also become so accustom to it that it makes scanning incredibly fast. For example:

    Enum.map(operations, fn operation ->
      execute(operation)
    end)
I can pretty much just read the left-hand side of that if I'm scanning really quickly, ie, ignore everything after `fn`. I'm talking micro-optimizations here, but I have been tripped up before when someone did something like `optn`.

Elixir allows for a shorthand notation for anonymous functions like so:

    Enum.map(operations, &execute(&1))
Some people hate that but again I like it due to the refactoring advantages (it becomes very simple to read once you get used to it).

I hear you on the x/y thing. You example is actually why I really prefer snake case, though I don't want to start a flame war there, haha. But ideally when you're dealing with points and dimensions you wrap them in a type or object that you can pass around and the receivers can extract simple `x` and `y` variables from them.

Re:Effect of Perceptual Load on Performance Within IDE in Pe... by Saturn5 on Friday July 14, 2023 @04:53PM (#36729785)
I have a colleague that loves to call functions things like ‘convert_object_type_from_mm_to_m’ and ‘convert_object_type_from_m_to_mm’ . It’s unscannable. They’re the same to me.

He does not like my ‘meter_to_mm’ and ‘mm_to_meter’ because the abbreviations are inconsistent, no verb is used and he needs to go all the way to the typehint to know the input. We both have a point, but there is not really a clear middle ground without writing a novel in function names.

Re:Effect of Perceptual Load on Performance Within IDE in Pe... by sodapopcan on Friday July 14, 2023 @05:42PM (#36730330)
Ya, that is ridiculous, honestly. While it's still all subjective, you gotta draw the line somewhere! I'm a stickler for consistency myself and would be ok with `meter_to_millimeter` but the `convert_object_type_from_` is pure nonsense. Like, assuming you're talking about a language with objects, what the heck else would you be converting?? EDIT: requiring verbs in function names is also overrated. It's one of those things that's usually a good idea, but if comes down to employing some taste to decide when it might not be. EDIT 2: I'm now upset for you for having to put up with that, lol.
Re:Effect of Perceptual Load on Performance Within IDE in Pe... by s_trumpet on Sunday July 16, 2023 @06:09AM (#36745273)
I’d personally go with a single function like “convert_object_type” and pattern match into different clauses such as “convert_object_type(obj, from: m, to: mm)” and so on.
[dead]
Re:Effect of Perceptual Load on Performance Within IDE in Pe... by sodapopcan on Friday July 14, 2023 @03:37PM (#36728886)
When I was working in Ruby, I think the default function length for functions was 5 lines. I used to be on board with this until I helped write a whole system adhering to this.

Small functions aren't bad per se, especially if they are re-used a lot, but I no longer believe that they are inherently good. Especially awful are having a lot of tiny single-use private functions.

I think that developers often want an easy way to say "we must do this" and have a tool tell them to do so. Tools can get us pretty far but at some point writing good code is going to come down to taste. This is of course very hard in many large project situations where its every team for themselves, and often every developer for themselves within a team.

Re:Effect of Perceptual Load on Performance Within IDE in Pe... by scns on Saturday July 15, 2023 @10:19AM (#36737007)
IntelliJ recommends inlining single use functions.
Re:Effect of Perceptual Load on Performance Within IDE in Pe... by s_trumpet on Sunday July 16, 2023 @06:05AM (#36745260)
At my firm we’ve standardized on import being used only for a short list of well known first/third party modules (e.g. Ecto.Query and Plug.Conn).

Application modules can be aliased, but not library modules. This is so that we don’t need to keep repeating the name of the application throughout the codebase while preserving clarity as much as possible.