I honestly think this is ridiculous. Sure, this is an incredible feat, and congrats. But serioulsy, I would be ashamed to publish such unreadable code under my name. What about naming your variables with descriptive names? What about extracting complex conditions into well named function to understand what is going on (thus defeating the purpose of the "4 functions") ? This list could go on forever... Writing softwar…
C4 – C in 4 functions
41–50 of 142 posts
Re: C4 – C in 4 functions
#42Earlier quoted context omitted.
Scanner has to have access to the symbol table, emit 'ident' or 'type' as appropriate. So not a pure context-free parser.
Yes. This is the reason it is way easier to hand-build a parser for C than try to use any kind of parser generator.
Re: C4 – C in 4 functions
#43I honestly think this is ridiculous. Sure, this is an incredible feat, and congrats. But serioulsy, I would be ashamed to publish such unreadable code under my name. What about naming your variables with descriptive names? What about extracting complex conditions into well named function to understand what is going on (thus defeating the purpose of the "4 functions") ? This list could go on forever... Writing softwar…
The variable names thing really annoyed me too - a habit of code golf, and people who were originally trained in an old FORTRAN edition that had a 6 or 7 char limit on names.
The same goes for symbolic constants. Sometimes (but not exactly "often"), use of numeric literals can vastly improve the maintainability of some code, assuming the reader understands how to maintain it in the first instance.
As for increasing reader comprehension, carefully thought out comments are a better mechanism by far.
In this case, it is sufficient to know that the file is a compiler/interpreter for its entirety to make sense, assuming the reader has implemented (or at least understood the principles behind) a compiler/interpreter in their past. Expanding the function/variable names, splitting "complicated" expressions out into their own functions, etc., does not magically improve the uninitiated's chance of understanding what is going on
Re: C4 – C in 4 functions
#44Earlier quoted context omitted.
It compiles a c subset to byte code, then executes in a virtual machine. I think generally an intepreter can refer to either a byte code interpreter (ie virtual machine) or an AST walking interpreter. I didn't see a way to embed c4 into a host language, so maybe not a scripting language? IMO the real value of exhibits like this are boiling the problem (lexing, parsing, compiler, interpreting) down to their most basic…
I think generally an intepreter can refer to either a byte code interpreter (ie virtual machine) or an AST walking interpreter. This brings to mind how fuzzy "interpreter" is as terminology. What is a virtual machine that JIT compiles the byte code or the AST? Is it a JIT implementation of an interpreter? What of implementations that only JIT the most frequently used functions? Wouldn't those be half interpreter and…
Re: C4 – C in 4 functions
#45I honestly think this is ridiculous. Sure, this is an incredible feat, and congrats. But serioulsy, I would be ashamed to publish such unreadable code under my name. What about naming your variables with descriptive names? What about extracting complex conditions into well named function to understand what is going on (thus defeating the purpose of the "4 functions") ? This list could go on forever... Writing softwar…
> Writing software is not a contest for who can write the most amount of code in the most cryptic way. It can be: http://ioccc.org/
For example, my entry http://www.ioccc.org/2012/tromp/hint.html is a 25 line "BLC in 7 functions".
Similar to C4, but completely unmaintainable, it compiles Binary Lambda Calculus to bytecode which is then interpreted by a virtual machine.
Re: C4 – C in 4 functions
#46Re: C4 – C in 4 functions
#47Re: C4 – C in 4 functions
#48Edit: OTCC (http://www.bellard.org/otcc/ ) is another extremely tiny (to the point of being obfuscated) example of a compiler using a recursive-descent parser.
Re: C4 – C in 4 functions
#49Earlier quoted context omitted.
I think generally an intepreter can refer to either a byte code interpreter (ie virtual machine) or an AST walking interpreter. This brings to mind how fuzzy "interpreter" is as terminology. What is a virtual machine that JIT compiles the byte code or the AST? Is it a JIT implementation of an interpreter? What of implementations that only JIT the most frequently used functions? Wouldn't those be half interpreter and…
Most interpreters (not all, but most) are actually a compiler and a VM, yes. The difference between a "compiler" and an "interpreter", in practise, seems to be that "compilers" lack a built-in interpreter.
Any interpreter vs. VM distinction is mostly a social construct. Looked at technically, it's a mishmash.
Re: C4 – C in 4 functions
#50I honestly think this is ridiculous. Sure, this is an incredible feat, and congrats. But serioulsy, I would be ashamed to publish such unreadable code under my name. What about naming your variables with descriptive names? What about extracting complex conditions into well named function to understand what is going on (thus defeating the purpose of the "4 functions") ? This list could go on forever... Writing softwar…
> I honestly think this is ridiculous. Sure, this is an incredible feat, and congrats. It's not that bad (or difficult), really. It's a hand-written parser for a subset of C that emits assembly code right away. This is how compilers like Turbo Pascal used to work (see http://www.pcengines.ch/tp3.htm for an explanation of what's happening). Sure, you could apply cosmetic changes like making "*++e = bla;" into "emit(bl…