Live data from Hacker News

Code Runs on People

rachelbythebay.com

1–10 of 35 posts

Re: Code Runs on People

#2
I find this kind of exhortation to be useless in practice, because while everyone agrees that code shouldn't be too clever, no-one agrees on what kind of code is being too clever.

For example, I'd argue that using C/C++ at all is probably "too clever" - humans are good at simulating the happy path, but very bad at simulating all the possible different ways such code might actually be executed. But all too often people are seen as smart and rewarded for "using such an efficient low-level language".

Conversely, I'd argue that exposing a business constraint as an algebraic datatype that forces you to use it correctly reduces the cleverness required to understand the code.

But I'm sure there'll be someone here who thinks the exact opposite, and bringing "cleverness" into the conversation doesn't actually bring us any closer to agreement.

Re: Code Runs on People

#3
I've run into the opposite issue. I like macro lists in C/C++ (not sure what people call them). It's the idea that you create a pre-processor list and then use that list to effectively code generate. For example you can use the list to generate enums, enum to string tables, case statements for all cases, etc.... It's clever but it's also IMO best practice because it prevents bugs. The reason they're used is it prevents the various parallel tables from getting out of sync. It's also arguably better than some external code generator because there are less dependencies.

So, is that a "clever" solution that should be avoided because it's "clever" or is it a best practice because it actually solves real problems? Problems which have cost me hours of debugging that could have been avoided if I'd just used the "clever" solution. For me it's the latter.

In fact, speaking to the OP, it also encodes the original programmer's logic since without them, the new programmer has to know the 4 to 9 places they'd need to edit to add to the list where as with them they only need to know 1.

Re: Code Runs on People

#4
post #2

I find this kind of exhortation to be useless in practice, because while everyone agrees that code shouldn't be too clever, no-one agrees on what kind of code is being too clever. For example, I'd argue that using C/C++ at all is probably "too clever" - humans are good at simulating the happy path, but very bad at simulating all the possible different ways such code might actually be executed. But all too often peopl…

Yeah, I agree, it's the old complex/complicated conundrum. What's easier: a super compact representation of the problem that uses high-level concepts, or a verbose listing of dumb procedural code? Chances are it depends on both who you ask and the problem at hand.

Re: Code Runs on People

#5
code should always be written for other humans. it runs on the machine, but other humans will have to understand it.

dogma, in all circumstances, leads to intellectual laziness at best and malpractice as worst.

trying to express complicated ideas using simple constructs can result in complicated, verbose and very difficult to understand use of simple constructs. this is why we have complicated constructs, to simplify the expression of complicated ideas.

Re: Code Runs on People

#6
I agree with the larger point being made, but equally I’m getting a bit tired of statements like these:

> “ If it takes an hour to figure out what's going on, well, that's an hour that wasn't spent doing something else more useful and interesting.”

What exactly is “doing something else more useful”?

As a software engineer your main job (yes I know talking to stakeholders and blah) is to write and to read code. If as a software developer you optimise for writing as little code as possible and not having to spend much time reading code either then what exactly are you working on? It’s great if you’re a solo entrepreneur who wants to optimise their own time, but for most devs reading code for an hour is some of the best use of their time in their daily job.

Re: Code Runs on People

#7

I agree with the larger point being made, but equally I’m getting a bit tired of statements like these: > “ If it takes an hour to figure out what's going on, well, that's an hour that wasn't spent doing something else more useful and interesting.” What exactly is “doing something else more useful”? As a software engineer your main job (yes I know talking to stakeholders and blah) is to write and to read code. If as…

[deleted]

Re: Code Runs on People

#8

I've run into the opposite issue. I like macro lists in C/C++ (not sure what people call them). It's the idea that you create a pre-processor list and then use that list to effectively code generate. For example you can use the list to generate enums, enum to string tables, case statements for all cases, etc.... It's clever but it's also IMO best practice because it prevents bugs. The reason they're used is it preven…

it's a workaround for a lacking type system

Re: Code Runs on People

#9
post #8

I've run into the opposite issue. I like macro lists in C/C++ (not sure what people call them). It's the idea that you create a pre-processor list and then use that list to effectively code generate. For example you can use the list to generate enums, enum to string tables, case statements for all cases, etc.... It's clever but it's also IMO best practice because it prevents bugs. The reason they're used is it preven…

it's a workaround for a lacking type system

Not really. It'd be more accurate to say it's a workaround for an existing proper hygienic macro system built on static introspection and code generation.

Re: Code Runs on People

#10
post #9
post #8

Earlier quoted context omitted.

it's a workaround for a lacking type system

Not really. It'd be more accurate to say it's a workaround for an existing proper hygienic macro system built on static introspection and code generation.

Not really. It's not a workaround - it just works.

Maybe most uses of lexical macros could be done with hygienic macros / macro replacement bodies that are fully formed expressions (AST nodes), but not all of them.

For those macros, really the "hygienic" doesn't matter half as much as people pretend. Don't do complex macros where the "hygienic" is required. Don't generate code, write code. If you need to generate syntax to remove boilerplate, then sprinkle a few macros in. But to generate syntax, in general you'll need a lexical macro system.

Post reply on HN