1,205 karma · joined Jan 2, 2022 (4y ago) · 235 submissions
comment 4y ago · link · parent
Compare:
> If B and C are subtypes of A, then List<T> must be invariant over T since List<B> should not be a subtype of List<A>, which can contain both B and C.
with:
> List<Cat> can't become List<Animal>, because you might add Dogs to that list!
comment 4y ago · link · parent
comment 4y ago · link · parent
comment 4y ago · link · parent
comment 4y ago · link · parent
comment 4y ago · link · parent
comment 4y ago · link · parent
> The point is, this [Result type] makes it impossible for us to access an invalid/uninitialized/null Metadata. With a Go function, if you ignore the returned error, you still get the result - most probably a null pointer.
It's all about framing. You can just as equally say it is "impossible" to access an invalid Go FileInfo, because you'll get a panic for derefencing a null pointer. Or you can just as equally say it is "possible" to access an invalid Rust Metadata, just by doing .unwrap(). Everyone knows an unchecked .unwrap() is just bad Rust code, but then again dereferencing a pointer without checking the returned error is just bad Go code.
Anyways the rest of the article seems like just a criticism of Go's file system API, which seems fair but also seems a little niche given how difficult it is to create a good cross-platform file system API. This particular point irks me though:
> stat "$(printf "\xbd\xb2\x3d\xbc\x20\xe2\x8c\x98")"
> fmt.Printf(" %s\n", e.Name())
> It... silently prints a wrong version of the path.What did you want it to do? The author even admits go strings are just byte slices, not UTF8, and then passes a non-UTF8 string to a function that expects UTF8. If there's a chance the file path your program works with might not be UTF8, then you should validate it. I think moving the complexity UTF8-ness out of the type system was a necessary evil.
comment 4y ago · link · parent
comment 4y ago · link · parent
> What's the point of making "Republican" so prominent in the article? Is it just to use the negative connotation most WP readers have about the Republican party to malign Facebook a little more?
comment 4y ago · link · parent
comment 4y ago · link · parent
unsafe { transmute::<u32, Error>(error_code) }
than it is to verify that the weird macro code in the article is correct. There is no data races, use-after-free, etc. in that block, it does exactly what the article needs. To me, Rust programmers seem to have a weird notion that just the word "unsafe" is enough to conjure demons and monsters into otherwise totally normal code.comment 4y ago · link · parent
Also I disagree with the idea that teams should use the same editor. I, for example, hate vscode, so if I join your team, I'm stuck either using a less productive editor, or re-creating the launch configs and save actions in my editor. To me it seems like a failure on the editor's part to separate concerns---a code editor should edit code. If it compiles or launches the code, it should do so using an external program, e.g. make, where all the launch configs can go in the Makefile, and not in some editor specific file.
comment 4y ago · link · parent
comment 4y ago · link · parent
But here the name actually matters. They're called "panic"s, not exceptions. When you panic, you signal a fatal error that should ideally terminate the program. You shouldn't care about closing files or freeing memory, because well-written Go does not panic, and if it does, execution will end very soon. A panic in a String() method is just bad code, don't do it. Meanwhile in C++ you can reasonable expect an exception anywhere. Bad arguments, invalid states, IO failures, and other errors that should be expected in the execution of a program all throw exceptions in idiomatic C++.