r/AskProgramming • • Oct 24 '26

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?

https://github.com/khytryy/krabbascript

2 Upvotes

12 comments sorted by

View all comments

4

u/regular_hammock Oct 24 '26

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.