News for hackers. Stuff that matters.
Re:C-based Virtual Machine for Notch's DCPU-16 by dizidoro on Wednesday April 04, 2012 @06:37PM (#3800221)
I hate magic numbers, i believe comments should be made as last resort. The code should be self-documenting. It's about reading and understanding the code easier. One thing that i learned wit CS is that it's all about making higher abstractions, making the logic closer to the domain you are modeling. If there is a word that resumes CS, i would say abstraction. Thats why we have high level languages, OOP, Operating Sytems, folders and files and etc.
Re:C-based Virtual Machine for Notch's DCPU-16 by chj on Wednesday April 04, 2012 @11:17PM (#3801132)
Normally enum is better.

Here enum is not a good idea if you have a switch case like:

switch (val) { /* val is uint8_t / case OP_XXX: break; case OP_YYY: break; case OP_ZZZ: break; }

Looks nice, but in debugging, you have no idea where we are going when you set a breakpoint at the switch. because the val is not an enum type, so debugger can't make the job easier for you.

Now it is much better:

switch (val) { / val is uint8_t / case 0: / XXX / break; case 1: / YYY / break; case 2: / ZZZ */ break; }

Re:C-based Virtual Machine for Notch's DCPU-16 by Ralith on Thursday April 05, 2012 @02:06AM (#3801512)
> Looks nice, but in debugging, you have no idea where we are going when you set a breakpoint at the switch. because the val is not an enum type, so debugger can't make the job easier for you.

So .. move forward a step?

Re:C-based Virtual Machine for Notch's DCPU-16 by chj on Thursday April 05, 2012 @10:12AM (#3802596)
Things could be more complicated than that.

The val may be a corrupted value which are not covered by any of the listed case. However, you will be able to identify what's going wrong right away by comparing the value with listed cases.

Yes, it is rare. but sometimes I do wish I haven't used enum.

Re:C-based Virtual Machine for Notch's DCPU-16 by DanBC on Thursday April 05, 2012 @06:32AM (#3802013)

    putting three spaces in front of a line formats it as code and allows use of *
not putting those spaces means that text in asterisks become italics