2 ms·
Anyone ever use brainf*k ?
http://en.wikipedia.org/wiki/Brainfuck#Language_design
I was googling something at work today and stumbled across brainf*k, a "minimalist", but still Turing complete language with only 8 instructions, including the io. "<" means decrement the pointer location, ">" means iterate the pointer location, "+" means iterate the pointer byte value, "-" means decrement the pointer byte value, "[" means enter a while type loop until pointer byte value is 0, "]" ends that while loop, "." means put a char to standard out, and "," means read a char from standard out.
Anything "real world" one can use this for? Like it is small, so I should imagine it is fast? So like maybe for large problems involving lots of "number crunching"?
- bkrausz 18y agoAt this point you may as well be writing in assembly, but compilers are advanced enough that it's usually more efficient to write in C and let the compiler convert to assembly. In short: no.
- alnayyir 18y agoYou realize the language is a programmer circle-jerk inside joke right? Disclaimer: asm coder. Also, if you want speed, write in C. Asm is for demi-gods and the masochistic alone.
- newt0311 18y agoSo... The compiler itself is insanely efficient (I have heard that it is on the order of ~200 bytes). However, the compiled code is probably nowhere near as efficient simply because the high level constructs are hidden from the compiler. Furthermore, the time that you will save in execution, you will lose many times over in writing the program (this by the way is why no one should ever develop in C/C++ unless it is absolutely necessary). BF is primarily a joke as well as an interesting exercise in what is needed for completeness.
- silentbicycle 18y agoIt's not "insanely efficient", it's just really small. Like Forth, but without the expressive power, conceptual elegance, efficiency, or speed of development. :) I wrote a bf interpreter a few weeks ago. (It's one of those things which is just tricky enough to be good for trying out languages, btw.) You can't call anything that makes you deal with strings by repeatedly incrementing cells to set ASCII codes efficient, seriously. One of my test programs was a rot-13 program, and it was slo-o-o-o-o-ow. Also (wear a helmet before you read this ;) ), there's an i386 native code brainfuck compiler, written in brainfuck: http://www.nada.kth.se/~matslina/awib/ http://www.nada.kth.se/~matslina/awib/
- Allocator2008 18y agoThanks for the tips! My day job is that I write in SilkTest for test automation, but occasionally have to do some c for stuff silk cannot handle. So I recently bought the K&R book on C programming, and have been enjoying that. If nothing else I suppose bf gives one a good "excuse" to learn c in some more depth by "translating" bf to c or vice-versa. :-)