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…
> This list could go on forever... Yes it could. While you are adding to your list of coding rules, the OP will have written another fun, tiny compiler. Who is having more fun?
C4 – C in 4 functions
21–30 of 142 posts
Re: C4 – C in 4 functions
#22I 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 actually found the code surprisingly easy to read; "tk" stands for "token", "ty" for "type", and so forth. It's worth noting that compilers don't pop out of thin air -- you have to start with something simple in order to compile a more complicated compiler. Bootstrapping your own self-hosting compiler is a useful academic exercise, and you should try it sometime if you haven't already: http://en.wikipedia.org/wiki/…
Re: C4 – C in 4 functions
#23Re: C4 – C in 4 functions
#24I 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…
Re: C4 – C in 4 functions
#25Would you call this a compiler, an interpreter, a virtual machine, a scripting engine, or a combination of those?
IMO the real value of exhibits like this are boiling the problem (lexing, parsing, compiler, interpreting) down to their most basic parts. One could easily imagine this same language being implemented over 10's or 100's of class files in a more verbose language.
Re: C4 – C in 4 functions
#26Earlier quoted context omitted.
> This list could go on forever... Yes it could. While you are adding to your list of coding rules, the OP will have written another fun, tiny compiler. Who is having more fun?
Those are not rules, they are mostly common sense to help the next programmer who has to maintain your code.
In any case if someone were competent enough to work on it then the style is actually quite readable. It's even full of comments.
Re: C4 – C in 4 functions
#27Earlier quoted context omitted.
I actually found the code surprisingly easy to read; "tk" stands for "token", "ty" for "type", and so forth. It's worth noting that compilers don't pop out of thin air -- you have to start with something simple in order to compile a more complicated compiler. Bootstrapping your own self-hosting compiler is a useful academic exercise, and you should try it sometime if you haven't already: http://en.wikipedia.org/wiki/…
Well, if this particular compiler is defined in 4 functions, why couldn't it be made out of more functions, enhancing the readability and maintainability of the code?
Re: C4 – C in 4 functions
#28Re: C4 – C in 4 functions
#29Unfortunately, I cannot compile it on my OSX 10.10... here's what I get: http://pastebin.com/cVvaYFEH EDIT: just make next() function void and it works. EDIT2: still no fortune :( $ ./c4 hello.c [1] 33920 segmentation fault ./c4 hello.c
sizeof(int) == sizeof(void*)Re: C4 – C in 4 functions
#30Unfortunately, I cannot compile it on my OSX 10.10... here's what I get: http://pastebin.com/cVvaYFEH EDIT: just make next() function void and it works. EDIT2: still no fortune :( $ ./c4 hello.c [1] 33920 segmentation fault ./c4 hello.c
I think it doesn't work on x86-64, since the code assumes sizeof(int) == sizeof(void*)
➜ c4 git:(master) ✗ clang -m32 c4.c
...
➜ c4 git:(master) ✗ ./a.out hello.c
hello, world
exit(0) cycle = 9