Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

the book uses golang


Indeed. The Redis book was C/C++ so I was hopeful that this one would be as well. Given that database essentials are so closely tied to system calls, I would have hoped for a language that doesn't abstract them away. At least in the first fsync() call, the author does explicitly mention that `fp.Sync()` ends up invoking `fsync` system call, but as someone who has no intention of returning to Golang I'd rather not have to add complexity by requiring me to build and maintain a mental map of Golang calls to syscalls (the worst kind of abstraction layer IMHO: leaky and unnecesary).


It’s interesting that it doesn’t seem to actually say that anywhere.


write on the introduction it says https://build-your-own.org/database/00a_overview

Or if you see any chapter you can literally see Go code.


You're right, I missed the one place in the introduction where it mentions Golang.

Other than the "if err != nil" I wouldn't have recognized the code samples. Go's error handling is a big reason I've never taken a closer look.


never understood the issue with go error handling. As soon as you start dumping exceptions as a valid error forwarding mechanism ( which seems like a totally acceptable design decision), you end up manually having to check every call you make that can raise an error, on each line.

I don't really see any alternative. It also makes you carefully think about how you plan on managing errors in your codebase, which also seems like a very sane thing to enforce.


You don't have to trap exceptions separately on every line. You trap a whole block of code and match on the exception type to determine how to handle the problem. It isn't perfect, nothing is, but I prefer systems languages where typical failures cannot easily be ignored and yet you are not burdened with constantly thinking about it.


> I prefer systems languages where typical failures cannot easily be ignored and yet you are not burdened with constantly thinking about it

This is self-contradictory. In particular, the only way you can have reliable error handling is if you are forced to think about each possible failure.

I assume by "cannot easily be ignored" you mean the way exceptions blow up at runtime? I don't find that an acceptable default for any non-scripting language.


people who aren't used to actually handling their errors get annoyed at typing return err all the time.

They'd prefer an easier way to not bother dealing with them with them without outright ignoring them via _


I'd get annoyed too, because I know there are much simpler alternatives. Language design should encourage doing things right by making it more convenient than the shortcuts.

In Rust that entire check can be a single "?" symbol. How much syntactic sugar is too much is a matter of preference, but I personally think that properly handling all errors without syntactic sugar turns into an unreadable mess because there's just a lot of things which could go wrong.


almost 50% of the time i want to add some debugging info to the error before forwarding it one layer above, to provide more context.

I think just forwarding all low-level errors is a really bad habit, and go forces you to at least think about this.


> I think just forwarding all low-level errors is a really bad habit

Why exactly is that a bad habit? In almost all situations where I return an error I already have enough context, I'm just wondering what else I'd add to that.

> go forces you to at least think about this

Boilerplate code definitely doesn't incentivize thinking.


most errors you encounters are with i/o and are stupid "can't read, can't write or can't serialize".

In a network environment (which is originally what go was made for) you often need to add tracing information, business-level identifiers or processing information related to your state etc.

I'm currently writing a fairly complex api in go, and to be honest this really hasn't bothered me once.

Not to say it doesn't exists, but with time i've come very suspicious of people complaints over go. Most of the time those complaints come from people that didn't realize they missed an opportunity to have written a much much more elegant solution to their problem.


or usually just try again with backoff.


just returning the error isn't handling it.


I never said it is, but to handle an error you have to pass it to the caller that can actually do something with it, whether it's trying alternatives, repeating the step, just logging it, or whatever else - a lot of functions just need to pass it on a couple of times and making this verbose in every single case doesn't make sense to me.


My favorite language is Erlang, which is about as far from Go as it gets from an error handling perspective.


Interesting choice. I'd think that as the context is "As many of today’s (2023+) coders do not have a formal CS/SE education" and the goal is education, a more popular language like Javascript or Python (or, heck, even PHP[1] /s) would be used, instead.

I've taken a look at Go, and while it does seem pretty approachable, it's definitely not nearly as common as Python/JS, and it's always significantly harder for me to learn a new concept when the examples are also in a language I'm unfamiliar with. Maybe that's just me, though.

[1] https://survey.stackoverflow.co/2022/#most-popular-technolog...


I think Go is a pretty good choice for the purpose. It balances high-level ease of use and learning curve with decent access to the system-y parts of coding that are so important to databases. What you learn to do in Go will translate reasonably well to a true systems language if the user wanted to take database engine design to the next level.

Languages like Python or Javascript are so far removed from the system-y side of programming that the way you would implement the concepts in those languages would not translate to the way you would actually build a "real" database which is I think the purpose of the book. I think the objective isn't to teach the abstract concepts but how those concepts are expressed in real systems.


I'm a data engineer and I only know Python. It appears Golang hits a sweetspot on many metrics such as performance, parallelism, ease of use etc and since 2016 there's been a lot of new data products and tools written in Golang. So it makes sense to me that the book would use a popular language for the domain.


Databases really do push runtimes in such a way that I think it makes sense to urge folks to use a system level language, or something close to it. In particular it'd be hard to cover concurrency (and parallelism) properly using vanilla CPython or JS, and I think that would impinge on the lessons learned.

That said, it'd be an interesting read on how to make a DB in pure Python.


I don't normally think of Node and CPython as in the same performance bracket.

Regardless, you can do some crazy things in Node. See these notes about Node and MySQL:

https://github.com/tigerbeetledb/tigerbeetle/blob/main/docs/...


In this context I meant that the parallelism primitives are different than what you'll get in a systems level language, which might make teaching those parts unnecessarily awkward and probably the concepts less translatable to other runtimes.

For sure they've got different performance profiles.

Very impressive what your group was able to do with Node, and continuing on with Zig. It's got me interested in learning more.


you may be interested in this https://github.com/avinassh/py-caskdb


I could be wrong, but my perception is that Go is so opinionated that you'll either write idiomatic Go or use another language. So, from that perspective there's some goodness in using Go as a learner's systems language.


It's opinionated, but it's not _that_ opinionated IMO. You can write awkward Java, shiny C, or whatever idiomatic Go is. Most people I worked with were from .net/Java worlds, and learned just about enough Go to be able to subject others to their coffee bean ideologies.

There's somethings the compiler will fail on like unused variable and the likes, but for the most part you need added static analysis and style checking -- some of which ships with the Go compiler.




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

Search: