Hacker News new | ask | show | jobs
by edudobay 2924 days ago
Cool idea! Clear and nicely organized too :)

Wouldn’t it be more readable and less error-prone to have separate commands for turning hex mode on and off? Such as `hex on` and `hex off`?

3 comments

I think it might be more intuitive as an explicit stream modifier: hex, decimal, etc. No reason to turn anything “off”, which is actually the activation of a diffferent mode.

Edit: What I mean is

  hex
  00
  dec
  00
  utf8
  00
Definitely, that's probably the best way, considering all the other commands are "stream-y" as-is.
Why have hex mode toggles at all? Just use 0xa1b2, and so on. 0x... -> hex, 0... -> octal -- invent a syntax for binary.
0 for octal was a huge mistake. Most sane languages use 0o now, or just forget octal. How often do you use octal anyway? Like, once a year for file permissions?
OK, sure. As long as we don't have to toggle number bases...
syntax for binary: 0b11010011
Believe it or not, I didn't even consider that. That's definitely a better way to do it.
Was the first thing that stood out to me as well. Toggled modes like this are also quite annoying when shuffling around sections of the file. Copy one hex too many and suddenly your numbers in another part are all wrong. And due to the toggle you'll have a hard time finding the place where it all went wrong.

As far as I could tell it's been more or less the only mode. At that point I'd probably get rid of it because global state (which modes are) has to be remembered at all times and in this case its invisible until you see output. The suggestion to use different operators or modifiers for a single numbers was a good one in that direction IMO.

In addition, global modes lead to hairy things like

    if ...
       hex off
    endif
It surprised me that an octal mode wasn't available, or a binary one. But that's a minor gripe.

The only other thing I could see being useful is the ability to define "structs", for binary-headers, etc.

But agreed, this is a neat tool.