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

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.

10

u/YMK1234 Oct 24 '26

Can they argue why it is awful? Yes -> use the opportunity to learn something; No -> they are full of shit

1

u/gm310509 28d ago

This.

To be clear, I've never used Go, but that is irrelevant. If the other person is just whining and not offering anything constructive, they aren't doing much more than creating greenhouse gases from the electricity they are consuming and the oxygen they are converting to carbon dioxide while consuming the aforementioned electricity.

1

u/HealyUnit Oct 24 '26
while railsIsUnpopular {
  rantAboutWhyRailsIsGreat();
}
//...
repeat {
  rantAboutWhyRailsIsGreat();
} until railsIsTrending;

Those poor Rails devs :/

1

u/Electrical-Fig7522 Oct 25 '26

Yeah... Rail devs deserve better

4

u/deep_fucking_magick Oct 24 '26

Here's the thing. All code is awful.

3

u/Sbsbg Oct 25 '26

Not the one you just created, then it too gradually turns awful. Others code is awful from start.

I think we feel this way because unknown code is hard to understand and because of this looks awful.

0

u/[deleted] Oct 24 '26

[deleted] — view deleted comment

1

u/Electrical-Fig7522 Oct 24 '26

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.

2

u/DTCreeperMCL6 Oct 25 '26

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.