init
This commit is contained in:
commit
6109bae0a5
25 changed files with 2294 additions and 0 deletions
13
content/_index.md
Normal file
13
content/_index.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
+++
|
||||
title = "Home"
|
||||
+++
|
||||
|
||||
heya, i'm sam! this is my attempt at a blog which i will _definitely_ update often, trust me.
|
||||
|
||||
i deliberately don't really have a public online presence, but you can find me here:
|
||||
|
||||
- codeberg: https://codeberg.org/u1f320/ (git)
|
||||
- forgejo: https://code.vulpine.solutions/sam (self-hosted git)
|
||||
- pronouns.cc: https://pronouns.cc/@sam (i made this site!)
|
||||
|
||||
###### _vulpine problems require vulpine solutions_
|
3
content/blog/_index.md
Normal file
3
content/blog/_index.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
+++
|
||||
title = "Blog"
|
||||
+++
|
39
content/blog/go-panics-are-fundamentally-flawed.md
Normal file
39
content/blog/go-panics-are-fundamentally-flawed.md
Normal file
|
@ -0,0 +1,39 @@
|
|||
+++
|
||||
title = "go's panics are fundamentally flawed"
|
||||
date = "2024-11-05"
|
||||
+++
|
||||
|
||||
_(alternative title: `panic()` considered harmful)_
|
||||
|
||||
## errors, how do they work anyway?
|
||||
|
||||
errors in Go programs are represented by values. when calling a function that may return an error, it'll return `(T, error)`, and you can handle the error the same way you would any other value.
|
||||
|
||||
(note: the `(T, error)` syntax doesn't imply Go has tuples, because it doesn't. functions can just return multiple values.)
|
||||
|
||||
now, this approach does have some problems. Go lets you ignore the error very easily, by using the discard operator `_` rather than assigning it to a variable. it's also extremely verbose--anyone who has used Go a substantial amount has written `if err != nil { return err }` a thousand times. both of these issues are fixable, though: the compiler could emit a warning or an error (heh) when discarding an error value, and new syntax could be introduced to bubble errors up more easily.
|
||||
|
||||
## panic! at the goroutine
|
||||
|
||||
what _isn't_ fixable, though, is the panic system. any function, no matter its signature, can call `panic()` at any point, with any value. as soon as it's called, the call stack unwinds all the way to `main()` and the program crashes. a function doesn't have to indicate that it can do this. in fact, it _can't_, except in a documentation comment.
|
||||
|
||||
you can catch panics with a call to `recover()`. you _can't_ put this below a function that might panic, though, you have to use `defer` _before_ the panic happens. `recover()` will return the value passed to `panic()`, or no value if no function panicked. (ironically, `recover()` _also_ doesn't return an error, or even a boolean, when nothing panicked. you check if the return value is `nil` instead.)
|
||||
|
||||
this is basically a worse version of `try { } catch { }` in other languages. you can't guarantee that the value returned by `recover()` is an error, it can be _any_ type. it moves error recovery away from the source of the error. and, of course, it's inconsistent: the `(T, error)` pattern lulls you into a false sense of security, making you think that you handled all possible errors in your application, when surprise! it can always panic.
|
||||
|
||||
## how this could be fixed
|
||||
|
||||
simple: remove `panic()` entirely. all functions that panic now must instead return an error, and the caller must _handle_ that error. now when a function doesn't return an error type, you _know_ it can't ever crash your program! problem solv--
|
||||
|
||||
oh. the language itself panics quite a bit as well. trying to access a slice index that doesn't exist, trying to assign to a `nil` map, dereferencing a `nil` pointer, trying to write to a map from multiple goroutines simultaneously, and more can all cause panics. that requires a little more thought.
|
||||
|
||||
well, here we go:
|
||||
|
||||
- slice indexing could simply _also_ return a `(T, error)`, or at least `(T, bool)`, at all times, unless the index is known to exist at compile time. this would be extremely annoying in the current version of the language, but would be fine if a more streamlined way of bubbling errors up was added, such as borrowing Rust's `?` operator.
|
||||
- `nil` maps should be removed entirely. every map is strongly typed to begin with, and there is no practical difference between a `nil` map and an empty one. in my mind, the current behaviour is the language exposing an implementation detail (distinguishing between `nil` and empty maps) for no real reason.
|
||||
- similarly to slices, accessing a pointer could also return `(T, error)`. borrowing C#'s `?` operator to streamline accessing deeply nested values would help here. alternatively, do away with pointers entirely and replace it with a system similar to Rust's `Option<T>` type.
|
||||
- i'm not entirely sure how to handle maps in multiple goroutines. the easy solution would be to wrap every single map in a `sync.RWMutex`, but this would massively slow down single-threaded programs, which is why [the developers decided against doing this in the first place](https://go.dev/doc/faq#atomic_maps). maybe assigning to a map could return a boolean, with `false` meaning the write failed because another goroutine wrote to it at the same time. that's not a perfect solution, though.
|
||||
|
||||
but really, the biggest problem with panics is that all of the decisions surrounding them are set in stone, forever. Go intends to never release 2.0, which is understandable: they don't want a repeat of the Python 2 to 3 transition. but it also means the language can never truly grow past some of its faults.
|
||||
|
||||
luckily, this is all just a thought experiment. if i want a more reasonable error handling system, there are so many other languages to choose from. such as c#--`System.NullReferenceException` ...oh, never mind.
|
11
content/blog/hello-world.md
Normal file
11
content/blog/hello-world.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
+++
|
||||
title = "hello world!"
|
||||
date = "2024-11-04"
|
||||
+++
|
||||
|
||||
oh hey, it's the stereotypical "hello world" post. look at me! i copy pasted a hugo tutorial!
|
||||
|
||||
turns out making a blog is really difficult, and not for technical reasons. it's just really hard to actually write things consistently.
|
||||
i can't promise anything in that regard--expect this site to get about one post a year, and that's _if_ i actually remember it exists.
|
||||
|
||||
until then though, have fun reading the one rant i've already written. hope you like go because if not, it probably isn't for you!
|
44
content/blog/rust-is-good-just-not-for-me.md
Normal file
44
content/blog/rust-is-good-just-not-for-me.md
Normal file
|
@ -0,0 +1,44 @@
|
|||
+++
|
||||
title = "rust is good, just not for me"
|
||||
date = "2024-12-02"
|
||||
+++
|
||||
|
||||
Rust is the big new[^1] thing in just about every programming niche. web frameworks? of course there's a Rust one! in fact, there's dozens of them. command line tools? good luck finding one that _isn't_ written in Rust these days. databases? oops, all Rust!
|
||||
|
||||
all of this carcinisation[^2] has me feeling kind of left out, though. you see, i've never really vibed with Rust: i have tried it multiple times, even building a handful of (unfinished, naturally) projects with it, but i always bounce off of it eventually. for a long time, i attributed this to Rust just not being what it's hyped up to be, that it's actually a lot worse than everyone says it is, but... it really isn't. it _is_ a good programming language. a great one, in fact! i want to dig a little deeper into _why_ i, personally, don't vibe with it. (not very deep, mind you, because self-reflection is difficult as _hell_)
|
||||
|
||||
## it's too low-level
|
||||
|
||||
starting off with the big one: **Rust is a systems language.** while it _also_ works very well for web development, command line tools, and other software, it's not what it was designed for. it was designed for scenarios where you can (and often need to!) squeeze as much performance as possible out of a system, where a garbage collector on its own would already not fit into the device's memory, and where a string taking up any more space than its literal bytes is unacceptable.
|
||||
|
||||
meanwhile, when _i_ used Rust, i just wrapped everything in an `Arc<RwMutex<T>>`[^3] and called it a day, because i _don't_ care about performance all that much. HTTP and database latency already destroy any optimization i could do to the business logic, so why even bother?
|
||||
|
||||
## i was constantly fighting the compiler
|
||||
|
||||
i'll admit it: i didn't really go out of my way to learn Rust. like every other language i've used, i just jumped in headfirst and started trying to rewrite my silly little programs into the silly little crab language. **this was a mistake.**
|
||||
|
||||
Rust's compiler is its strongest suit: it catches bugs that no C or C++ compilers can even _imagine_ exist, and its borrow checker seems like dark magic at times. but what makes the compiler great for experienced Rust users makes it an absolute _pain_ for people learning the language. other languages let you throw code at the wall and see what sticks; Rust won't even let your code compile unless it works perfectly. this makes my learning process a lot more difficult, and as such, i never really learned more advanced Rust.
|
||||
|
||||
## macros are magic, but not the good kind
|
||||
|
||||
macros are _extremely_ powerful. many of the libraries i was using heavily relied on them--some, like `sqlx` (no relation to `sqlx`, the Go library[^4]) are entirely built around them. they're also a nightmare to reason with as an inexperienced rustacean.
|
||||
|
||||
i'm used to being able to ctrl-click on a function invocation to go directly to its implementation in other languages--Go, C#, and even Python all do this (well, as long as the Python package has type annotations, and you're not relying on external ones). this just doesn't work with macros, because the code is generated at compile time. it felt like i was feeding input into a black box and praying that whatever came out on the other side worked[^5].
|
||||
|
||||
### types for days
|
||||
|
||||
somewhat related to macros: some libraries like [axum](https://github.com/tokio-rs/axum) generate _ridiculously_ long type names, which, while funny, are impossible to actually parse. this didn't make debugging my code any easier.
|
||||
|
||||
## conclusion, i guess
|
||||
|
||||
i don't really have any conclusion to draw from writing this. i guess my learning process just doesn't mesh with how Rust works, and that's why i bounced off of it.
|
||||
|
||||
i definitely think it's worth thinking about this for _any_ language--or any other _tool_ in general, even--that you dislike. it's honestly kind of depressing to be extremely negative about things without being able to articulate _why_. i'm sure i've annoyed plenty of friends by complaining about Rust or any other tool they like.
|
||||
|
||||
in fact, i should write a post like this for every language i dislike! Go, Elixir, maybe even PHP--well, maybe not that last one. it's been so long since i last used it that i'm sure all my problems with it have been fixed at this point.
|
||||
|
||||
[^1]: please ignore that it's been stable for over 9 years.
|
||||
[^2]: [everything seems to evolve into crabs these days.](https://en.wikipedia.org/wiki/Carcinisation)
|
||||
[^3]: wait a second, does that mean i just used a reference-counting garbage collector?
|
||||
[^4]: `sqlx`, the Rust library that converts database rows to strongly typed structs using reflection magic (macros), not to be confused with `sqlx`, the Go library that converts database rows to strongly typed structs using reflection magic (the reflection package). they are somehow completely unrelated.
|
||||
[^5]: this is, coincidentally, why i don't use LLMs.
|
Loading…
Add table
Add a link
Reference in a new issue