Hacker News new | past | comments | ask | show | jobs | submit login
Let's build an entire programming environment around Brainfuck (malone.cc)
141 points by malonedotcc on May 30, 2013 | hide | past | favorite | 85 comments



He's 27... As someone who's 47, I'd like to say: take that energy and try to build a company, join a few start-ups, try to change the world, travel a lot, drink in some far away land, etc. This place is a lot of fun :-): http://www.cafenose.com/


Your comment really hit a nerve with me, probably because I'm the same age as the OP and playing around with programming language implementations is a bit of a hobby for me, so I'll apologize for my reaction ahead of time, I tried to tone down what follows from the screed I initially wrote.

Your comment comes off as a little bit condescending and presumptuous. There's this underlying judgement about the relative worth of writing a Brainfuck interpreter and environment versus drinking in some bar in Guatemala or starting a company, like the latter is obviously a better use of time and energy. Aside from the fact that doing the things you mention aren't mutually exclusive with this little project, it's really tiring to hear (older) people constantly beat the drum of "you're young! go travel! drink!" on top of the "start your own company!" startup mantra. Maybe you wish you did more of those things when you were younger, or maybe you wish you were doing more of them now, and maybe I will wish the same thing when I'm older...

But they are absolutely not for everyone. I think it's disingenuous to just throw out "take that energy and try to build a company" as an alternative. Not everyone has it in them to do all the schlep work required to succeed at their own startup, so why assume this person hasn't considered it and chosen not to follow that path? Furthermore, I would personally prefer to tinker with a Brainfuck implementation than spend any amount of time in any bar, even it's in Guatemala or Colombia. I usually find them noisy and unpleasant, and I would find "partying the night away" to be a boring waste of time. But I would never suggest someone else shouldn't spend their time that way because that would be assuming a great deal about what's important to them.

Maybe this was just a little flip remark on your behalf, not meant to be taken seriously. I'm probably projecting a little bit, and reacting to something you may not have intended to imply. For that, I apologize again.


On the flip side - I would say, 20+ years into a reasonably successful career in IT/Network Engineering, that one of the best uses of my time in the last couple decades was spending hundreds of hours grokking awk. I've had my share of travelling, socializing, and startups - but I certainly don't, for a second, regret my days and late weekend nights staring into the face of awk.

I don't know if this is a "when you have a hammer, everything appears to be a nail" - but I continually am shocked at how few of my six-figure salary colleagues in the IT industry (networking, unix, systems integration) are incapable of slicing and dicing a large text file and reporting on it. Activities that take them the better part of day in Excel, can sometimes be done in a few minutes with a fast awk script.

Knowing awk (and all the regex associated joy) has brought me (personally) great pleasure, and I'll die a happy man knowing the time I put into it was well spent.

We each have to find joy in life where we can.


Awk is definitely one of my top 10 useful utilities.


But they are absolutely not for everyone.

Why not? I'm not saying I disagree, but your argument is weak. Sometimes it's not the accomplishment that matters, but the attempt. Whether the attempt at these actions is beneficial or not hasn't been addressed at all. That seems to me to be an important omission in an discussion about what are essentially life experiences.

But I would never suggest someone else shouldn't spend their time that way because that would be assuming a great deal about what's important to them.

In some respect, what important to them does not matter. Who they are and what they feel is important at that moment may very well be small subset of what they will consider important throughout their life. In the dispensing of advice for the purpose of changing someone's outlook on life, whether their current outlook agrees with it or not is irrelevant.


After all, this site is called Hacker News, not Startup Lifestyles.


Hey, that travel advice thing about been around for a couple thousand years:

http://en.wikiquote.org/wiki/Augustine_of_Hippo

And the idea of traveling isn't to spend it all in a bar. Anyway, spend your time as you please...


That's not at all what I heard in the parent comment. It's not that tinkering with programming languages is bad at all. Rather, what OP proposes is a veritable shitton of work, and really won't be as much fun as he imagines right now; it'll be work. Hard, hard work, with tons of organizational overhead. If OP wants to do work of this caliber, the parent comment suggests that OP first seek out more productive, equally exciting and technically challenging ways to channel that energy.

That's my interpretation, anyway. Not that hobbies are bad, but that this is gonna be a life-consuming hobby, will likely detract from other pursuits, and may not pay off as well as OP thinks it will.


You assume that:

a) I'm going to be doing this "work" (which, okay yeah it is) full-time or even constantly, when I'm probably just going to hack on it for the next few months or years; whenever I've got a coding itch. I doubt I'll ever go into crunch mode on this or get "burned out". I'll just put it aside for a while and do something else.

b) That I can't just say "Whelp, it was fun but I'm done" at some point during the project and find something else to do. There's no hardcore commitment here; like all projects, everything beyond the first step is a pipe dream.

I get what you're saying though and it could definitely be a shitton of work that's probably not usable IRL. But it's still a fun plaything.


> proposes is a veritable shitton of work

Perhaps I missed something in the post, but I don't see a "shitton" of work there.

The first step is easily a one weekend (if not one day) project. None of what was described is particularly difficult, complicated, or labor intensive. I wonder if people are making assumptions about all sorts of fancy extras that the post doesn't mention being included.

That's the time for pure code-work. Thinking/design/testing will eat up more time, but not that much more time. As described it's a pretty reasonable weekend project to last a couple months.


> I think it's disingenuous to just throw out "take that energy and try to build a company" as an alternative.

As someone who's just read your comment, I'd like to say: calm down, and re-read the parent comment with an open mind. It's dripping with life experience.


One life's experience. Another 47 year-old would say, "Ray Croc started McDonalds in his fifties. You don't need a lot of mathematical thinking to start a company, you need people skills and judgment. But the focus required to fiddle with Brainfuck degrades rapidly as you age.

You can always build another skateboard ride-sharing site with photo uploads and Raspberry Pi integration later. Now might be your best shot at Brainfuck."


Because of their life experience, I wouldn't be so quick to reject either of these fellows' advice out of hand.


Precisely!


I feel like my ability to focus is better now than it was 20 years ago, but my motivation is lower.


+1 just because of "I would personally prefer to tinker with a Brainfuck implementation than spend any amount of time in any bar"


Having been 27... As someone who's 45, I'd like to say: I've long wanted to write exactly such an IDE etc (right down to dedicated custom hardware) for some esoteric language, so take that energy and plunge in, learn a lot about the development stack without taking on the full weight of a serious heavyweight language. This place is a lot of fun :-): http://news.ycombinator.com


People are getting touchy because of this response, but let me answer it myself.

To me, coding is like painting or cooking. It's a fun activity done for leisure and self-improvement. I do silly things like code Brainfuck environments because I mostly do these things for me.

I'm not in a startup or building a company because I don't want to give my leisure activity a work stigma. I don't want to code for money because it'll strip away everything I like about programming: the fun of untangling a problem, the casual pace of piecing together a solution and the independence of being able to code whatever I want whenever I want.

In the future I can see myself doing open source projects or writing professionally but I can't see myself coding for 9 to 5 or swapping out my silly activities for a dayjob where I build someone else's thing.


If you don't mind my curiosity, what do you do for money?


I'm a high-level office contractor, I work six-month contracts in corporate roles. Right now I'm an expediting officer, but I've been many things before that.


You know, your comment made me think a lot. You're both right and wrong at the same time, but I couldn't find a good way to express why and how.

In the end, I believe Michael Ende described it the best in "The Neverending Story" (the book, not the movies). The essence of what I would recommend to anyone is expressed by the words on the back of AURYN: "Do what thou wilt". As Bastian is told, it's not about doing anything you want, it's about finding out what it is that you truly wish for, "and nothing is more difficult".

Maybe OP will spend years working on this project and end up realizing that it was "a waste of time" and that what he really wants is something else. But even then, it might end up being more valuable to him than doing things you recommended. Who knows?


Small world. I was just thinking of Cafe No Se this morning because of a brochure of Antigua that I have from a trip there. Cafe No Se advertised on the back of it with a catchy phrase along the lines of "Every dive needs a good town."

But yes, I would agree with the general sentiment of experiencing the world. For me, there is not much that is more satisfying than exploring - be it traveling to new places, climbing a mountain or just trying something new.

That said, if this project removes the boredom and is interesting/fun to the OP, there is value in that as well.


Any project like that is going to be a lot of work. It would probably turn into many man years. Sure, do it if you want. Time is your most valuable asset. Choose wisely.

Since Antigua isn't too far off the beaten path, let me throw out Colombia.

Spend the night in a hammock near the ocean.

http://wikitravel.org/en/Tayrona_National_Park

Party into the night:

http://www.lonelyplanet.com/colombia/northwest-colombia/mede...


There is something to be said for pursuing things that have absolutely no practical application. There is nothing wrong with amusing one's self and perhaps even learning things along the way.

I don't agree with the "I'm older and smarter than you" and "you should travel the world drinking on exotic beaches" points. That's not everybody's bag. Though, I would tend to agree with about the value of one's time and energy.

The thing about this project is that you could just switch the language from Brainfuck to literally anything that isn't an academic gag. You would do the same work and gain the exact same experiences. In the end, in addition to simply the learning experience, you will have produced something that may likely be usable to many people. Of course you won't be able to get the same lulz as you would telling people that you spent a year of your life writing a Brainfuck interpreter.


The process of creating a startup varies widely. And for some, a startup is part of a larger process, that of exploring (or capitalizing on) one's passions and curiosities and intuitions. The startup in this case is not the end, but one of many means. Who knows if the knowledge, pain, or relationships his project bears will result in a startup, or maybe even something more world-changing.


If you are not able to enjoy the present moment in your present place you can travel around the whole world and you will not find enjoyment anywhere, that's what sages have been repeating for centuries.


I would say: travel and code :D


This is the best, "stop wasting your time" comment ever. I loved it.


Blog entry describing my 100-line x86-64 Brainfuck JIT (built on DynASM): http://blog.reverberate.org/2012/12/hello-jit-world-joy-of-s...

(Direct link to the code: https://github.com/haberman/jitdemo/blob/master/jit3.dasc)


I've been looking for a DynASM tutorial for ages, and wanted to use it to make a fast BF interpreter-- this is great!

I added some optimizations using Flex to identify patterns, and got a 3.8x speedup on the Mandelbrot benchmark -- https://github.com/rmmh/beefit


Very nice! I wouldn't have thought to use flex to recognize optimizable patterns. :) It crashes for me on OS X but I'll have to try it on Linux.

You may have tried this already, but where you have:

    mov al, byte [PTR]
Usually you want to write this instead to avoid a partial register stall (also in case there's junk sitting in the register).

    movzx  eax, byte [PTR]


Hm, the OSX crash is probably because they have a different ABI from Linux -- Google "osx ia32 abi" for details-- I'm probably violating stack alignment.

Partial register stalls are where you write part of the register, then read the full register:

    mov al, byte [PTR]
    add ebx, eax
But I am emitting this:

    mov al, byte [PTR]
    add byte [PTR+3], al
So there's no stall.

I got jit4 about as far as is reasonable for a single-pass compiler, but I intend to implement a proper BF->IR->ASM compiler to implement some more complex multi-pass optimizations I have in mind.


Yes, I have encountered the problem before that OS X crashes on incorrect stack alignment even where other platforms tolerate it.

Good point about the stall -- I always thought that partial register stall happened at the point that you do the partial write, since the logical contents of the register now depend on its previous contents. I didn't realize that the dependency logic was sophisticated enough to allow the partial read without depending on the entire register's value.


Sounds like fun, but maybe you should wait with submitting it until you have something going? In case you lose interest for some reason.


There’s a follow-up post detailing some first steps: http://malone.cc/posts/lobe_1.html


> In case you lose interest for some reason.

I think it's that very reason he's submitting it so early.


There are two camps (I think I'm in the latter):

- telling everyone motivates you: you made a public commitment, you get early feedback, "if your idea is any good people will reject it at first"

- don't tell anyone motivates you: the idea is yours, you want to build something beautiful and show to the world, you don't like to be criticized when starting up


I recall reading an article in which a psychologist written about a study that aimed to prove which method was more affective.

The conclusion of the study was that people are more likely to stick to a goal they keep to themselves. This is because often telling people a goal they will reward you with praise as if you already achieved it making it prematurely gratifying which causes you to lose motivation.

Also from my own experience public commitment is a bad motivational tool. This is because the motivator of public commitment is usually fear (failure etc) and fear is a terrible mindset to draw motivation from which (in my experience) can cause a lot of procrastination.


It does sound cool, and it's no small undertaking. A high-level language like a Lisp requires GC, for one example.

It'll be neat to see what he comes up with.


GC doesn't have to be terribly complex: https://gist.github.com/JohnEarnest/4522067


You can prototype with the null-GC until you run out of memory...


++++++++++[ > +++++ +++ > +++++ +++++ << - ] > -- . > +++++ . ----- - . ++ . > +++++ +++++ .



Wow thats a cool tool… Makes sense also, after all not many operators to worry about :)


I think you want two more > characters in your loop. As written now, you're decrementing negative-indexed memory.


Oops, brainfucked!

Fixed BTW


Nice\0


I think there real questions here are:

1) How long have you been insane?

2) Static or Dynamic typing?


1) I don't think I'm that crazy, I mean this isn't Temple OS or anything (http://www.templeos.org/).

2) Integers! Strings are integers, arrays are tapes of integers, etc... I guess this means it's dynamic, but at the bottom levels I'm not (yet) concerned with typing.


3) Generics?


4) Iterators?

5) ???

6) Web framework?


4) Already got 'em. A Brainfuck iterator is just a bracket loop with an ascend command before the closer.

5) !!!

6) I am but a mere mortal, sir.



The name of that project is horribly relevant.


I feel pretty safe in assuming that it is intentionally ironic.


I wrote some kind of assembler on top of Brainfuck: Basically tweaked a Brainfuck interpreter that I wrote in C.

So instead of: +++++++. You would write 7+. or something similar... can't remember now.


I started writing a simple parser/interpreter to convert a C-like language to brainfuck[1]. Simple sample code with a loop at [2] and result code [3]

I never quite got around to functions, but there is basic support for arithmetic, for loops and rand()

[1] https://github.com/qix/c2brainfuck [2] https://github.com/qix/c2brainfuck/blob/master/samples/beer.... [3] https://github.com/qix/c2brainfuck/blob/master/samples/beer....


Interesting project ... but what about hardware?

It would be pretty trivial to create a uP out of high-speed logic that would execute each instruction in a single clock cycle. Add a PIC uC to actually load the program memory and you could have a nice little console machine.

As a side note, I've spent most of my career building uC systems that communicate via RS-232 or RS-485 (if they communicated with the outside world at all), so imagine my surprise to find I couldn't buy a laptop with a serial port. It's like the end of an era (yes ... I know about USB-to-serial adapters).


Is there a place where embedded systems job listings tend to be posted?


The industry rag is "Embedded" ( http://www.embedded.com/ ) which replaced the print version published as "Embedded Systems Programming". There used to be three to four pages of "Help Wanted" ads near the back of each issue and that was the best place to find embedded systems jobs. The reality is that most job boards have these listings now (and they're usually cross-listed) but you often have to search for embedded related topics to find them. Try PIC, Microchip, ARM, uC, uP, etc.


I have distant dreams of building a shell out of this and putting it on a Raspberry Pi...

Beyond that, it's far too young for me to decide.


Out of curiosity, am I correct (from your follow-up post) that your cell size is 16-bits (integer range of [0..65535]) and that your tape size is only 256?

I suppose it works but convention seems to be 30,000+ bytes and 8-bit cells. Of course, getting pedantic about brainfuck conventions is a bit beside the point (like Orthodox Discordianism). I just want to know if I'm correct and, if so, I'm curious about what is gained through such nonconventional decisions.


I want the core Brainfuck to be as simple and clear-cut as possible. I can implement negative numbers when I get to the assembly stage, and I limited tape size because I'm implementing multiple tapes in the future. I'd rather have many smaller tapes instead of fewer large ones.


That makes a lot of sense. However, I'd still consider your work a success if it broke the 30,000 barrier in cell count. The brainfuck spec says at least 30k cells. It's not an upper limit.

I get why you excluded negative numbers. I was wondering if I was correct in understanding the cell size to be 2 bytes because it's typical for it to be 1 byte.

Am I correct that - on a cell at 0 (or + on a cell at MaxVal) is a no-op, just like < and > at the end of the tape?


You are correct.

Also, we will actually be breaking 30,000 cells. Just not with a single tape :).


brainfuck is a wonderful toy language. it is so simple - the entire language fits easily in your head, even though it is difficult to do anything useful with it.

more generally, compilers are fun to learn about. i found Jack Crenshaw's "Let's build a compiler" series a good starting reference and source of inspiration [1].

i built a brainfuck to GNU assembly compiler in brainfuck. to be able to write that compiler, i first built a higher-level macro language that could target brainfuck, and wrote a compiler for that. the macro language was implemented as a horrible DSL in python [2].

later i built an implementation in haskell that could parse and compile the macro DSL to brainfuck, so things ended up entirely python-free [3]. Haskell's Parsec parser combinator library was fun to learn about too [4].

[1] http://compilers.iecc.com/crenshaw/

[2] https://github.com/fcostin/abfc

[3] https://github.com/fcostin/abfc_hs

[4] http://www.haskell.org/haskellwiki/Parsec


Some time ago I tried writing an extended Brainfuck interpreter (m4bf - macro brainfuck)[1] .

In addition to the basic language it had a stack and, with a bit of c preprocessor trickery, i devised a hackish way to have macros (despite the cpp man page saying not to use this for anything but as a c preprocessor).

[1] https://github.com/federicoculloca/m4bf/


Why not just write an LLVM to brainfuck compiler ?



This looks like brainfuck compiler (frontend, as in, it takes brainfuck and makes executable), not brainfuck to llvm (backend) compiler.


You could write (or re-use) a RPython brainfuck interpreter, so you'd get a JIT for free :)


There is a tutorial on how to add JIT to the interpreter written in RPython (if CPython 3 happens to be slow) http://morepypy.blogspot.ru/2011/04/tutorial-part-2-adding-j...


Before this goes any further, can we change the name of the language to something inoffensive. The name makes it impossible to mention it in many environments. Some alternatives I can think of is BrainF, Brainfreeze, Brainscrew.


Nothing wrong with Brainfuck, or fuck for that matter. If anything, it'll get the people that are bothered by it desensitised :)


Not brainscrew, please. I find that offensive.


This reminds me of Urbit: https://github.com/cgyarvin/urbit

Which is at least as weird, more serious, further along, and orders of magnitude more ambitious.


Here's an interpreter of mine made in Lisp: https://github.com/fabriceleal/Brainfuck


In the same vein, here's my JS interpreter: https://github.com/mgoeppner/brainfuck.js


Lisp on top? Why not Perl 6?


Relevant xkcd: http://xkcd.com/224/


Announcing things that will never get finished. How exciting.


craziness


OP, this seems cool and might be of use to you when you include functions: http://en.wikipedia.org/wiki/Binary_lambda_calculus


What good does a body if a soul makes a soul?


Let's not. The offensive name, suitable only for inside jokes. Slow as hell. No chance to achieve any usable insights.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: