Most active commenters
  • arwalk(4)
  • rmunn(3)

←back to thread

517 points bkolobara | 15 comments | | HN request time: 0.202s | source | bottom
Show context
aeve890 ◴[] No.45042188[source]
>The code will compile just fine. The Zig compiler will generate a new number for each unique 'error.*'

This is wild. I assume there's at least the tooling to catch this kind of errors right?

replies(3): >>45042403 #>>45042586 #>>45050319 #
1. arwalk ◴[] No.45042586[source]
The example is a bit dubious. Sure, it compiles just fine, because the author is not using errors properly in zig. Here, he uses the global error set with `error. AccessDenid`, and as stated, it compiles just fine because when you reach the global error set, it's integers all the way down.

If the author had written `FileError.AccessDenid`, this would not have compiled, as it would be comparing with the `FileError` error set.

The global error set is pretty much never used, except when you want to allow a user to provide his own errors, so you allow the method to return `anyerror`.

replies(3): >>45042666 #>>45043035 #>>45043562 #
2. veber-alex ◴[] No.45042666[source]
Why does the compiler decay the FileError and the global error set to an integer? If they were unique types, the if statement would not have compiled.
replies(1): >>45043279 #
3. empath75 ◴[] No.45043035[source]
All examples of this type come down to "the user made a mistake", but that is kind of the the entire point. It is not possible to make that mistake in rust.
replies(1): >>45043177 #
4. arwalk ◴[] No.45043177[source]
I'm not saying that zig has the same level of safety than rust, i'm just saying that grabbing a knife by the blade is not an argument for using a spoon.

The error presented in this example would not be written by any zig developer. Heck, before this example i didn't even knew that you could compare directly to the global error set, and i maintain a small library.

zig and rust do not have the same scope. I honestly do not think they should be compared. Zig is better compared to C, and rust is better compared to C++.

replies(3): >>45043283 #>>45043441 #>>45044284 #
5. arwalk ◴[] No.45043279[source]
`FileError.AccessDenied` is a unique value in a unique error set. `error.AccessDenid` has not been defined anywhere and hence is just given an integer value at some point by the compiler.

As I stated before, this error wouldn't even exist in the first place in no codebase ever: look how the method that fails returns a `FileError` and not an `anyerror`

It could be rightly argued that it still shouldn't compile though.

6. love2read ◴[] No.45043283{3}[source]
comparing these examples to “grabbing a knife by the blade” equates writing code that looks right to picking up a sharp and jagged object with your hands that would obviously hurt and will hurt once you hold it.

It’s more like picking up a fork and being surprised to find out that it’s burning hot without any visible difference.

7. NobodyNada ◴[] No.45043441{3}[source]
Rust and Zig are the two most prominent new systems programming languages. It's only natural for people to compare them, from perspectives such as "I'm starting a project and need to choose what language to use".

The languages are very different in scope, scale, and design goals; yes. That means there's tradeoffs that might make one language or the other more suitable for a particular person or project, and that means it can be interesting and worthwhile to talk about those tradeoffs.

In particular, Rust's top priority is program correctness -- the language tries hard not to let you write "you're holding it wrong" bugs, whereas Zig tends to choose simplicity and explicitness instead. That difference in design goals is the whole point of the article, not a reason to dismiss it.

replies(1): >>45043583 #
8. dminik ◴[] No.45043562[source]
You say never, but even the Zig stdlib does this occasionally.

Like here in `std/tar.zig`: https://github.com/ziglang/zig/blob/50edad37ba745502174e49af...

Or here in `main.zig`: https://github.com/ziglang/zig/blob/50edad37ba745502174e49af...

And in a bunch of other places: https://github.com/search?q=repo%3Aziglang%2Fzig+%22%3D%3D+e...

9. arwalk ◴[] No.45043583{4}[source]
Sure. Did i dismiss the article? Or was I only saying that the example was bad?
replies(1): >>45043706 #
10. NobodyNada ◴[] No.45043706{5}[source]
I was specifically responding to the statement "Zig and rust do not have the same scope. I honestly do not think they should be compared".

I don't know enough Zig to have a qualified opinion on the particular example (besides being very surprised it compiled). However, I thought this post from the front page the other day had more practical and thoughtful examples of this kind of thing: https://www.openmymind.net/Im-Too-Dumb-For-Zigs-New-IO-Inter...

11. jibal ◴[] No.45044284{3}[source]
> The error presented in this example would not be written by any zig developer.

No True Scotsman fallacy. It was written by the Zig developer who wrote it.

replies(1): >>45046957 #
12. rmunn ◴[] No.45046957{4}[source]
No True Scotsman is only a fallacy when it involves changing your definitions after counterexamples are presented. But it can also be insisting on a non-standard definition.

E.g., "No true Scotsman would hate haggis!" "You're wrong, my friend Angus hates haggis, and he's a Scotsman through and through." "Well, if he hates haggis, then he isn't a true Scotsman!"

The first speaker isn't changing his definitions, so he's not actually engaging in the fallacy. Rather, he's insisting on his own idiosyncratic definition of what standards you must meet to be considered a "true" Scotsman, and insisting that Angus doesn't meet his standard.

But that's enough digression on "No True Scotsman". We now return you to your regularly-scheduled arguing over code. :-)

replies(1): >>45048298 #
13. jibal ◴[] No.45048298{5}[source]
> is only a fallacy when it involves changing your definitions after counterexamples are presented

That is false.

Edit: The fact is that we have the counterexample: the piece of code written by a zig developer who somehow isn't actually a zig developer. Where the counterexample comes from, who presents it, and when isn't relevant to whether this is a fallacy. The Wikipedia article overstresses the order of things, but that is never an issue with a fallacy. There are thousands upon thousands of examples where, e.g., someone claims that people aren't Christians because they don't follow Christ's teachings and that claim is called out as a No True Scotsman fallacy--it implicitly redefines what "Christian" is for the sake of denying that a Christian actually is a Christian, in order to preserve some claim of some virtue of Christianity in the face of clear evidence to the contrary.

replies(2): >>45048443 #>>45048666 #
14. rmunn ◴[] No.45048443{6}[source]
Then you might want to update the Wikipedia article which claims that it's a fallacy "in which one modifies a prior claim in response to a counterexample by asserting the counterexample is excluded by definition", citing three links to support that: https://iep.utm.edu/fallacy/, http://www.fallacyfiles.org/scotsman.html, and https://archive.org/details/godphilosophy0000flew/page/104/m....

To say "No true Scotsman would dislike haggis" is to assert "If A, then B": If you are a true Scotsman, then you will like haggis. The response "Angus doesn't like haggis" is asserting "not B". To which the response "therefore he's not a true Scotsman" is asserting "not A". But "if A, then B" logically implies "if not B, then not A". Therefore when the person's definitions don't change, *it is not a fallacy*. It might be wrong — his definition of a "true" Scotsman might be a false premise — but the conclusion logically follows from the premise, so it is not a fallacy.

15. rmunn ◴[] No.45048666{6}[source]
To reply to your edit: the fact that he wrote this in an example does not mean that he would write this in actual code. Examples are often contrived. The guy you're replying to clearly meant "no Zig developer would write this in actual code", which may have been wrong but this counterexample isn't a case of writing it in actual code.

As for the second part of your edit, arguing about definitions of who fits into the group is commonly mistaken as "no true Scotsman". For example, just because you call yourself a Scotsman doesn't necessarily make you one: if you have no Scottish ancestry, do not live in Scotland, and do not hold a Scottish passport, few people would agree with you that you are a Scotsman just because you assert that you are. They would insist on some standard for calling you a Scotsman that goes beyond "I say that I am one, therefore I clearly am one". Or, to use the example of Christians: millions of people around the world would say "no true Christian would deny the divinity of Christ: it's a fundamental teaching of Christianity". That is not a "no true Scotsman" argument, despite the presence of people who call themselves Christians who do deny the divinity of Christ. It is, rather, saying "You call yourself a Scotsman but you do not measure up to the commonly-accepted standard of being a Scotsman".

OTOH, your example of people saying "He's not really a Christian because he doesn't live up to Christ's teaching" is a "no true Scotsman" fallacy, attempting to redefine the commonly-accepted standard. Because nearly every Christian knows that we (I'm a Christian myself) never fully live up to Christ's teaching, and can always do better. So trying to say "He's not a true Christian because he doesn't measure up" is to redefine the standard in a way that would exclude pretty much everybody, and that's not at all what it means.

Short version: membership in certain groups can have standards (you're not a Zig developer if you've never written a single line of Zig code), and asserting those standards is not necessarily this fallacy, even if those standards are disputed by some people. (E.g., the case of groups that call themselves Christian while denying the divinity of Christ, which everyone NOT part of those groups would say is a fundamental part of the standard for being a true Christian).

*EDIT:* In my last sentence I wrote "everyone NOT part of those groups"; I should say "every Christian NOT part of those groups" if I wanted to be fully accurate. Because many non-Christians would deny that accepting the divinity of Christ is part of the definition, but pretty much all Christians who do accept that Christ was indeed God in human form will agree that that doctrine is one of the fundamental requirements, and that if you deny it you can't truthfully call yourself a Christian. (Hopefully I phrased that in a way that's both accurate and comprehensible.)