Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

Really? Can you give some examples? I know compilers are amazing but this seems too much.


sort by: page size:

Compilers are hard.

My bad, I don't know why I typed extremely.

however, while yes the compiler does a lot of work, it's an entirely different method of programming than most coders are used to, which make it painful to change to.


This is my mostly terrible argument when people start claiming compilers are hard. :)

Unfortunately, we live in the real world where compilers do not do the things that you suggest that they ought to.

that's why you need a typed compiler for this kind of stuff

One of the problems with this in software is that the concepts can be straightforward, but when you try to translate it into code, the complexity explodes.

Case in point: compilers. This is a very well represented topic, both in print and online. But almost inevitably, what you do find in this space are “toy” compilers.

Pascal, for example, is a pretty simple language. By design, and by the nature of how Wirth does things. But slogging through even a full boat Pascal compiler is a slog for anyone. And none of the ones I know of offer much, if any, optimization. In fact most have pretty lousy error recovery as well.

I honestly don’t recall the state of, or how the original Oberon compiler was presented in the original Project Oberon book. And that’s about as close, I think, as you’ll get to a walk through and discussion of a “production” compiler.

Which is what would frustrate this kind of effort in software. Software is hard. The concepts can be straightforward but getting them implemented and a boatload of detail rears it’s ugly head, because while programming and programmers are all about abstractions, computers are all about details.

And those details bloat up the code something awful, to the point it’s hard to see the forest for the trees sometimes. How many times have we seen a snippet of code qualified with “but this isn’t production code, so don’t use this”, and, of naturally, half the plant cuts and pastes it into their next live release.

Mind there is an excellent example of this in action with Lion’s commentary on Unix v6. Someone sitting over your shoulder as you walk through the code. But v6 is stone knives simple, can you imagine a walk through a modern walk through a modern, production kernel with a qualified docent.

There are other examples, Implementation of 4.3 BSD for example, but even it, considering it’s size, is higher level. It’s not the source code.

I have a little program I wrote in Java. It’s a GUI wrapper for a 1000 line fractal generator. It wraps the options and the resulting image. But MY code on top of that is 4000 lines. For a GUI! By God, it must be doing SOMETHING! It was certainly more than I anticipated when I started. “How hard can thus be”.

I thought there might be value throwing up a YouTube going through it all, to show what happened and why, warts and bad decisions and all.

Not because it’s anything special, but it is “done”. It is “only” 4000 lines, so in actuality, rather short. And it’s not a contrived example. It was written to do something, and deal with all the imperfections in me, in the toolkit, and in the “real world” that it operates in.

Plus, as I was writing it, writing this “simple” thing, I was always saying “it’s almost done except for...”. So, perhaps there’s value in a commentary about how that manifest in this little thing.


You can't really write a compiler if you don't know all the "weird things" of the language.

i think this is most compilers.

That's pretty nifty, but it seems like something a really good compiler could achieve automatically. Of course I'm not sure if any compilers actually are that good.

Yeah, that's a fair assessment - compile time code generation is unnecessarily painful in many popular languages. Often even if there is a facility for it built in (e.g. C preprocessor macros, C++ templates), it's less powerful and more complex than it needs to be because the designers of the language for some reason decided not to just let you use the same language at compile time that you use at runtime.

Good points. I wish I knew more about compilers sometimes, and this is one of those times.

* the complexity of the compiler makes it hard to make it better

Writing a compiler is easy. Optimizing one, not so much, but setting "writing a compiler" as some kind of difficult thing that requires arcane magic irritates me.

Do you know of any work being done in this area? I'm not that familiar with compiler design but this sounds fascinating.

Compilers are smart at some things and not so smart at others. I can beat the compiler in tight inner loops almost every time, but it will also do insanely clever things that id never think of!

Fascinating, while I was reading that, it got 5 upvotes! Mindblowing.

This is a really awesome description too. The only thing I know about compilers is that I implemented one for class (without fancy optimisations) and I am surprised any software works, ever. Compiler are just ... mindbogglingly complex things. Almost as much voodoo dark magic as engineering.


Very nice work. I just wish that compilers did some of these things automatically. Seems like even with modern optimising compilers it's still up to the programmer to do a lot of the work manually.

Lord, that's an unhelpful comment. Some compilers do not do that eg. scala, and the cost is high hence my request.

Reminds me of C# Code Analyzers based on the Roslyn compiler. It is a deal breaker for a language to have a compiler (in the same language) which exposes the intermediate phases and allow to participate in them.
next

Legal | privacy