Remix.run Logo
jacquesm 3 days ago

As a very long time C programmer: don't try to be smart. The more you rely on fancy preprocessor tricks the harder it will be to understand and debug your code.

The C preprocessor gives you enough power to shoot yourself in the foot, repeatedly, with anything from small caliber handguns to nuclear weapons. You may well end up losing control over your project entirely.

One nice example: glusterfs. There are a couple of macros in use there that, when they work are magic. But when they don't you lose days, sometimes weeks. This is not the way to solve coding problems, you only appear smart as long as you remember what you've built. Your other self, three years down the road is going to want to kill the present one, and the same goes for your colleagues a few weeks from now.

5- 3 days ago | parent | next [-]

> as long as you remember what you've built

yes! like any craft, this works only if you keep practising it.

various implementations of k, written in this style (with iterative improvements), have been in constant development for decades getting very good use out of these macros.

gitonthescene 3 days ago | parent | prev | next [-]

Losing control of a project is likely more due to the programmers on it than the tools they use. IMHO _anything_ done consistently can be reasoned about and if necessary undone.

jacquesm 3 days ago | parent | next [-]

Not necessarily. Sometimes the rot goes so deep that there is really no way out.

And the C pre-processor has figured prominently in more than one such case in my career. And it was precisely in the kind of way that is described in TFA.

For something to be doable it needs to make economic sense as well and that's the problem with nightmare trickery like this. Initially it seems like a shortcut, but in the long run the price tag keeps going up.

gitonthescene 3 days ago | parent [-]

Best guess is that your analysis is missing some detail. People not tools write programs. Also any serious discussion here ends up in politics. If you design your software so that the programmers are fungible then the software suffers regardless of your choices.

jacquesm 3 days ago | parent [-]

> Best guess is that your analysis is missing some detail.

What do you base that guess on?

I'm not saying it couldn't be done, I'm just saying that it sometimes just isn't worth it.

> People not tools write programs.

Yes. And just like people sometimes write crazy manifestos there isn't much point in fixing them, the purpose that they might have served is most likely better addressed by replacing them entirely.

> Also any serious discussion here ends up in politics.

Everybody knows HN doesn't do politics ;)

> If you design your software so that the programmers are fungible then the software suffers regardless of your choices.

Programmers are fungible not because they are cast from the same mold, but because - assuming they are responsible people - they can look past their present day horizon to the future, where after a lot of context switching they have to revisit that which they have made before, or, where they have to take over someone else's project, either because that person moved to a different role or because they've moved on entirely.

It is with such a future in mind that you can, if you want, make the life of that person a little bit easier by focusing on clarity of thought rather than terseness in expression. Nobody ever died for want of a few keystrokes more, but I'd have been a lot happier if some people made a habit of writing down first what the pile of executable spaghetti they wrought was supposed to be doing in the first place.

If you have not seen how bad it can get then more power to you.

Just one anecdote, which I may have posted on HN before, but a long time ago I worked for a game studio where there was a programmer who got into a fight with management. He left and I had to take over his project. All of the variable names were fruits and all of the functions were vegetables (or the reverse, as I said, it is long ago). There were no comments. But there were some bugs that needed fixing.

Clearly in his mind programmers were not fungible, and in my view the software suffered from his choices. So the one isn't necessarily a guarantee of the other (ok, n=1), though you might find them together every now and then.

I've seen some absolutely brilliant code that was clever and clear. That's the kind of thing that I aspire to, not to see how far I can push the CPP to do stuff it was never intended to do in the first place. We have contests for that sort of thing but it isn't the kind of construct that you should foist off on others in your line of work. Not if we're ever going to get serious about that engineering thing.

Recreational programming, that's a different story. Go wild, and I really hope you enjoy it. But if you submit your preprocessor based magical DSL as a pull request I'll nix it.

gitonthescene 2 days ago | parent [-]

All good decisions are a product of the particular circumstances in which they arise. This post seemed to be about generalizing that process which I would guess comes out of a supposition of fungiblity.

As much as one can use a given style for a personal project so can one for a professional one so long as it fills the given need. Too often (in my view) fungibility is seen as a preeminent requirement and layers and layers of self justifying processes are built on top of that. I’m only saying that’s a choice and the costs and benefits are not as obvious as most suppose.

Also you can minimize risks with redundancy but most presume those costs to be too high. But again this quickly becomes about politics.

jacquesm 2 days ago | parent [-]

I think the main question is whether or not you want to reach your goal and see programming as a means to an end or as the end itself. Usually, even when working on my own projects I have a goal, and the software is just a means to an end. So I tend to work on my own as though I am a team of one rather than that I am working 'just for myself'. This means I set up a whole pile of superstructure that isn't strictly a requirement, force myself to try to abstract as cleanly as I can think of and even refactor my code (when there is no project lead telling me to do so), write tests and abstain from trying to be too clever because it gives me better and faster results.

I'd imagine a chef or a competent musician would still use their hard won skill when cooking for themselves or making music for their own enjoyment.

gitonthescene 2 days ago | parent [-]

Who said code written in this style is lazy?

gitonthescene a day ago | parent | prev [-]

Just to double down here I took a code base written in this style (not exactly atw but inspired by him) and spent about a day expanding it to this point: https://codeberg.org/growler/k/src/branch/expand/a.c My guess is it would only take a week to get it to what people here are calling “acceptable”.

ryao 3 days ago | parent | prev | next [-]

ZFS has a very nice set of macros that work very well:

https://github.com/openzfs/zfs/blob/master/include/os/freebs...

See P2PHRASE() and friends. They were inherited from OpenSolaris.

switchbak 3 days ago | parent | prev [-]

Seems to me that this is now exponentially true with AI coding assistants. If you don't understand what you're adding, and you're being clever - you can quickly end up in a situation where you can't reason effectively about your system.

I'm seeing this on multiple fronts, and it's quickly becoming an unsustainable situation in some areas. I expect I'm not alone in this regard.

gitonthescene 3 days ago | parent [-]

I’d bet that a lot of the work done with AI assistants is decidedly _not_ clever.