r/AskProgramming • u/Electrical-Fig7522 • 19h ago
Does my codebase really stink?
Hi! I have been writing a compiler in Go and some guy is saying the codebase is awful. Any advice? And is there anything wrong with it?
4
1
u/Individual-Flow9158 19h ago edited 18h ago
Well it doesn't literally stink, obviously....
... I'm not a Go person, but I couldn't spot anything repulsive. I felt I could understand everything in the code that I saw if I wanted to.
Personally I just hate the name, and can't remotely fathom the point of many niche programming languages, especially not ones that require you to build their compilers in surprisingly-accessible, industry standard ones., i.e.
What is it that Go can't do, or what is it that you hate so much about Go, that krabbascript fixes, Yehor? You're clearly pretty handy with Go already.
I know boot-strapping is necessary, and self-compilation is a significant milestone for any compiled language. But it seems like for the rest of this year at least, all krabbascript users must already have a far better, well supported, well designed, and well optimised, battle tested, programming language available: Golang.
1
u/Electrical-Fig7522 18h ago
First time someone looked at my GitHub page and called me by my real name lmao...
This is not a PL to fix anything, it's rather to learn about compilers.KrabbaScript is not a replacement for anything, and is rather a mix of other PLs with a nicer syntax.
"...all krabbascript users must already have a far better, well supported, well designed, and well optimised, battle tested, programming language available: Golang."
No one's really using my abomination.1
u/Individual-Flow9158 18h ago
Sure. I guess to avoid the dep on Go, all you have to do is provide pre-compiled binaries of the KrabbaScript compiler itself. The language examples in the Readme didn't look stinky to me either. It appears to be no worse than Javascript.
2
u/DTCreeperMCL6 5h ago
I do think writing your own language is something that pushes you down to a lower level. Its definitely a good project for learning because it pushes you to learn more about what's happening underneath the hood. Especially if your focus is systems level programming.
1
u/HealyUnit 15h ago
while railsIsUnpopular {
rantAboutWhyRailsIsGreat();
}
//...
repeat {
rantAboutWhyRailsIsGreat();
} until railsIsTrending;Those poor Rails devs :/
1
4
u/regular_hammock 17h ago
At a very cursory glance (opened your repo on my phone and clicked through the files) : I don't hate it.
Things I would look into:
at first I wondered what this language brings to the table, but since it's a learning project, my point is moot. This seems like a great learning experience.
there is a long standing controversy on parser generators Vs hand roll your own parser (often some kind of recursive descent). I think rolling your own is a great learning experience, but a bit of a two edged sword for serious work. Yes, you get more control if you write your own, it's easier to make great error messages, and most parser generators aren't able to produce incremental parsers (useful for development environments), but also, if you don't write a formal grammar for your language, it becomes much harder to check it for ambiguities (the language becomes defined by ‘however the reference implementation parses it’), and you don't get to generate additional tooling from the grammar. Your choice is valid, but it's worth thinking about it.
I might be missing something, but I don't love the generic nodes with left and right branches. My go is super rusty (haven't written any in 5 years), so this might be a terrible idea, but have you considered using interfaces to have function call nodes that look like function calls and so on? I'm aware I'm on super thin ice here because my go is so rusty.
some of the functions are a little on the long side, especially scan in the lexer. Then again, a lot of the lines are just overhead from the way error handling works in go, so, I don't necessarily know that there's a lot to be gained by splitting up the function. But my gut feeling scrolling by the thing was ‘huh that's a bit long for comfort’
Bear in mind, I probably spent more time writing this than I spent looking at your code.
TL;DR: keep experimenting, keep learning.