Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Really cool!

I've never understood why modern software projects use names like `mw` or `mr`? What's wrong with `memory_read` / `memory_write`? Or `opcode_execute_fn opcode_executers[NOPS]` is magnitudes clearer than `op_ex_f op_ex[NOPS]`, and the only advantage of the latter is less time to write.

You will spend at least twice as much time reading your code as writing it, just take the extra time. Nobody needs another `vsnprintf_s`.

ETA: I have to repeat this is an insanely cool project idea, and very good execution



On one hand, the abbreviations are extra mental work. On the other hand, when you start composing fairly complicated chains together, all those extra letters are also extra mental work. Neither is inherently right, but I do prefer something like the former here (just making up something emulatorish):

    mw(cpu.r[0], mr(mr(cpu.r[1])));

    memory_write(processor.register[0], memory_read(memory_read(processor.register[1])));


This was exactly my reason to shorten the name, even if most of the feedback I've received is related to the "weird" naming conventions.

Initially mw was mem_write and mr was mem_read, and reg was registers, etc. But because I wanted to keep the functions as short as possible (to put them on the single line without making them totally unreadable), I've comeup with those names, which are confusing at first.


I think this boils down entirely to how comfortable the reader is with the concepts involved. If you have to stop and think for a sec about what "memory_write" actually does, the spelled-out words are a useful prompt and the time it takes to read them is not a bottleneck. But if you're used to thinking at level of abstraction, used to tossing the concepts around in your head like mathematical symbols - then the shorter version is preferable and the longer one feels boggy and pedantic. This is why regex is a thing and why people skilled in APL rave about it so much, and why nobody ever bothers to symlink rm, cp, and mv to remove, copy, and move respectively.


When you're optimizing for a metric like lines of code written, then abbreviations make sense. If you're optimizing for readability you could do something like (I'm not a C programmer so IDK if this is syntactically correct C):

` memory_write(

  processor.register[0],

  memory_read(

    memory_read(processor.register[1])

  )
) `

To me, multiline statements are much more readable than single line nested statements regardless of abbreviations used.


I do this sometimes when the line gets too long due to long names. I do not like it.


just making up something emulatorish

Double-indirect through memory? I think that's something only VAX has.


Since this code is dealing mostly with instruction mnemonics (br, jsr, lea), it makes sense for the rest of the code to comply with this style. The code has an inherently repetitive structure (implementing various opcodes) and therefore shorter global names contribute for its compactness. Mentioning "register_file" 30 times rather than "reg" wouldn't make it clearer when it is obvious that the short name serves the same purpose.


Same reason math uses letters rather than words.

It's easier to pattern match strings that are short.

Having one `mr`/`mw` is confusing, but taking up whole lines with long strings can obscure the logic of the code.


Alternate perspective: After you've briefly immersed yourself in context, you no longer need the longer names, the shorter ones make sense. In fact, it would be fatiguing the have to constantly read the longer names after you're familiar with them.


I think people are too used to huge projects. this one is 125 lines of C, in that space, you can express yourself shortly.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: