Better HN
topnewbestaskshowjobs
Log inSign up

randomdata

8,634 karma · joined Jun 23, 2011 (15y ago) · 7,679 submissions

Submissions

comment 3y ago · link · parent

> The sophistry trying to paint a nil pointer as "useful" is just trying to defend a position you've dug yourself into in the process of this argument

You are right. I concede nil is not useful. Therefore, we agree that (T, error) cannot exist. As we see in the style guide: "Returning a nil error is the idiomatic way to signal a successful operation that could otherwise fail." This means there is no way to check the error condition. One might be tempted to write `if err != nil`, but because nil is not useful that obviously won't work. That would make nil a useful value, just as I once thought – incorrectly, as you helpfully made me realize – a nil T would be.

And as the Go style guide indicates that you cannot use the T value without first touching the error value, which is, for all practical purposes, impossible since the error value may not be useful, there is just no way this pattern can be used in any actual program.

> But it does match how (T, error) is actually used the majority of the time.

Right. As you have pointed out – of which I was reluctant to admit to, but you said it enough times that it must be true! – (T, error) cannot be used. Period. Its values do not convey the useful information required to be useable. Either does, then, indeed, match how (T, error) is used most of the time... which is to say not at all!

You mentioned something about MarshalText in the slog package showing how an idiomatic function with errors might actually be written, but then we realized that there are multiple implementations with the same name. Which one were you referring to?

comment 3y ago · link · parent

> You are now claiming that they are useful when you must discard them as useless when the error is non-nil.

Is it that you've confused implementation with interfaces? I would have to reject the values if received through the TextUnmarshaler interface, which defines MarshalText, as the implementation being called then becomes unknown, and therefore may not be idiomatic. If I was knowingly working with the three concrete types mentioned above then their function is documented.

> That's odd, because you've contorted yourself into defending absurd positions based on personal definitions no one else shares, including the Go authors, just to avoid admitting you were wrong

I mean, all you have to do is show some code which is reasonably considered idiomatic that does not return a useful value when in an error state and I'll be convinced; something you agreed was pertinent and useful when you brought up MarshalText.

The slog package is definitely reasonably considered idiomatic, so you are on the right track. Now you just need to be more specific at to which MarshalText method you are actually referring to. You called attention to it for good reason, no doubt. All we need, as there is more than one, is to know which one you meant specifically. It is a little odd you didn't do that in the first place, but I'm sure it was an accidental omission.

comment 3y ago · link · parent

> The slog package, brand new in 1.21, contains a MarshalText method

At quick glance, I found three MarshalText implementations in the slog package. Which implementation are you referring to specifically?

And, for what it is worth, none of them return useless values on error, so where do I find the fourth which does?

> This, too, is simply a lie.

Let's hope. I love nothing more than being wrong. That means I get to learn something new! But I haven't found it yet, which is sorrily disappointing. Looking forward to you clarifying the above so we can put this to rest.

comment 3y ago · link · parent

> It is idiomatic Go to never return useful values if error is non-nil unless explicitly documented.

No, it is very much written from a consumer perspective. There is known, non-idiomatic, code where relying on T in its error state is problematic, so the guidance is reasonable and logical.

But we're talking about this from the producer perspective. These do not challenge each other and can exist in harmony.

> believe most of the stdlib is idiomatic Go, especially the newer stuff.

I wholeheartedly agree, at least with respect to the newer stuff, and have already said as such. Now this is where, in that newer work which is idiomatic, you point to a good example of where you can find meaningless return values when there is an error.

Clearly the vast majority of the standard library, especially in the newer stuff, does return meaningful values upon error, so we need to identify those which buck the trend if we want to hold it as a counterexample of this being an idiomatic practice.

comment 3y ago · link · parent

> if err is non-nil, you shouldn't even check the other return values.

Yes, it says you cannot trust functions, unless documented, to be idiomatic. Which is reasonable as not all code is idiomatic. The language goes to no lengths to enforce how the code is written in this regard (obviously). But we are talking about code that is known to be idiomatic.

> Most of the stdlib, including the newest additions, is idiomatic as judged by other people but evidently not by you.

1. I don't see how it could be. What is idiomatic emerges from writing code and seeing what works and what doesn't. Most of the stdlib was written in the early days before anyone understood what works best. And, thanks to the go1 guarantee, modifying it now is out of the question.

2. If you believe that the stdlib is idiomatic, then you have to accept that returning an int (-1) to represent an error is idiomatic. The standard library is full of that. Which violates the premise of FP-Go that (T, error) is idiomatic. That is not my claim, that is theirs.

comment 3y ago · link · parent

That may be technically true, but is really just an implementation detail. If HN quietly replaced all the accounts with suitably capable LLM bots, it wouldn't make any difference. What this type of service really has on offer is solitary activity: Writing for one's own enjoyment, differing from a private journal only in that the software here provides some colour back to spark additional thoughts in order avoid writer's block.

I'm not sure the same is true in 'real' communities.

comment 3y ago · link · parent

> means T is a meaningless default value

Go Proverb #5: Make the zero value useful.

> that should be ignored or a null pointer

nil is the zero value of a pointer, so it should be made useful per the above, but it is also inherently useful even if you put no thought into it. It allows you to know that there is an absence of a value out of the box.

And this is actually why the vast majority of (T, error) cases in idiomatic code sees T be a pointer, despite the computational and programatic downsides of using a pointer, so that nil can be returned when the value is not otherwise useful – exactly to ensure the value is as useful as possible, denoting the absence of a usable value.

If you read through idiomatic code, you'll notice that only when the underlying type is more meaningful is a pointer not used. Returning a slice is one such example. An empty set upon error is more meaningful than nil, usually. Another common instance is when 0 is meaningful, like in the aforementioned io.Reader interface. Idiomatically, one will always strive to return the most meaningful value they can.

> Either and Option at least would be nice to have in the stdlib

And if it were, then this Either wrapper in question would become useful as an overlay to it, as they would then share the same intent and meaning. But it does not match the current semantics of idiomatic Go code using the (T, error) pattern.

You can probably make it work, but code is about communicating ideas to other programmers. Either implies a dependence between variables. (T, error) has no such dependence. There is an impedance mismatch here which fails to properly communicate what is happening.

comment 3y ago · link · parent

I don't think it is about the speed. My combine tops out at 18MPH, but there is something about the sound its engine makes when it is revved up – and when you throw the hydro level forward, oh boy.

I also enjoy concerts, though. Understandably music isn't for everyone.

comment 3y ago · link · parent

> It is absolutely not idiomatic to give any meaning to non-error values under error conditions in the usual case.

Based on what? We have come to see that it is beneficial to make zero values useful. In fact, Go Proverbs even says so. Likewise, we have learned it is useful to return the zero value when you have an error. Most commonly, this means returning nil, which is packed full of all kinds of useful information. Therefore, the T value can be expected to useful if the code is idiomatic.

I'd love to see some real-world code you think is idiomatic, but doesn't return a useful T value when there is an error.

> If a function returns an error, callers must treat all non-error return values as unspecified unless explicitly documented otherwise

This is not at odds with that. This merely warns that not all code you may call will be idiomatic. In fact, if I recall correctly, doesn't os.Open (maybe os.Create) return an invalid file handle in some error cases? The standard library is old and what helped us eventually see what is idiomatic. It is decidedly not idiomatic for the most part. If you rely on a function being written idiomatically, then you are going to run into trouble, as that is not a guarantee (unless the documentation provides such a guarantee).

But in the case of this Either wrapper, it explicitly states it is for use with idiomatic code, not any old code you can throw at it.

comment 3y ago · link · parent

> I don't agree with your personalized definition of idiomatic Go in the first place.

"That's the point. They are not equivalent, they represent different things" – Oh snap. Well, so much for that silly tangent.

If you want to actually have a discussion, you are going to have to go and understand the discussion that was taking place before you tried to take it in some weird and nonsensical direction. The non-sequitors may be entertaining, maybe even true, but off in la-la land with respect to the conversation taking place.

If your intent is simply to be my personal jester, then by all means, run with it. I'll continue to enjoy the laughs. Most people would pay good money to see an entertainer of this caliber, and you are offering it to me for free! I feel privileged.

comment 3y ago · link · parent

> Well, if the Go stdlib is haphazardly written and unidiomatic

Yeah, the older parts of the standard library are definitely not idiomatic. Lots of functions in the stdlib which return errors don't even return an error type. But, of course they aren't idiomatic. Idiomatacy is emergent. They couldn't possibly have been written idiomatically.

> I'll boil it down to one sentence: Go forces programmers to use (T, error) when it is not appropriate, and Go would be better if it did not.

That may be true, but of no relevance. I can see why I didn't bother reading it. Thanks for clarifying that it would have been a waste of my time.

comment 3y ago · link · parent

> Your claim of "in Go values must always be useful"

I said no such thing. I said idiomatic Go indicates that you must always make values useful. This is an onus placed on the programmer, not something guaranteed by the language. However, since the Either monad here was said to be introduced to wrap idiomatic Go code, not whatever haphazardly written Go code you happened to find in a SourceForge repository, that is of relevance.

> was rebutted multiple times

Cool. I must not have read it. There was a lot of weird shit in there that had nothing to do with anything. I'm not sure how that would even find relevance to the discussion taking place. I get that first year computer science programs are starting up and you're excited to share what you learned in your first week, but I really don't care. You are not going to tell me anything I haven't heard many times before.

comment 3y ago · link · parent

> That's the point. They are not equivalent, they represent different things

Good. I'm glad you came back to the first comment in the thread. I am not sure why it took you so long, but I respect that you got there eventually.

> I'll take your implicit admission that you have no rebuttals.

Naturally. You finally realized what I said is true, and we've talked about nothing else. What could there possibly be to rebut? You have clearly not thought this through.

comment 3y ago · link · parent

> I have to carefully check that it's non-null even if error is null.

Yes, that is true; at very least you need to read to documentation to understand if there is a relationship or not. Whereas Either defines an explicit dependence between two values, freeing you from that. With that, clearly they cannot be equivalent representations. I am surprised this is not obvious to you.

Honestly, I don't know what the rest of that gobbledygook is all about. It reads like one of those weird posts by Rust users we keep seeing where one is wallowing in the sorrow of not being able to grasp Haskell.

comment 3y ago · link · parent

> you have to return a useless nil pointer

nil is useful. Notably, you can derive meaning from its nil-ness. If you try to open a file and it doesn't exist, returning a nil handle is quite reasonable, and one can check for the existence of that handle without needing consider the error.

If, say, you returned an invalid file descriptor when the file could not be opened, conceivably that could make the handle useless, but that would not be idiomatic. That would just be a terrible API design and unkind to the users of your API.

> Funnily enough, your philosophy is far more true in a language with proper sum types.

Of course. But not the Either monad specifically, as its intent is to communicate a dependence between two variables. That can be useful in some languages where variable dependence is a convention, but that is not applicable to idiomatic Go.

Frankly, the only thing funny here is the idea that it is useful to reply to a thread before reading it. Let me reiterate: Either is not a suitable representation of (T, error). They have very different semantics. There are data structures which can serve as a suitable representation of (T, error), but Either is not it.

comment 3y ago · link · parent

That is incorrect. Idiomatic Go is abundantly clear that values must always be useful, even if all you have is the default value. Thus T must be useful regardless of the state of error, and vice versa. As such, they are free to be observed independently. That does not mean T and error cannot be in a relationship, but they are not dependents.

There being a relationship between T and error is common, but observance of error is only significant when the error is relevant. Quite often it is, but not always, and in the latter case you can, assuming the code is idiomatic, safely use T and ignore error. T must be useful, after all.

It may be possible to create a scenario where T is not useful when error is not nil if you really want to screw with people, but that code would decidedly not be idiomatic. Indeed, there is always some way to screw with people if you try hard enough, but that's really beyond this discussion.

The use of the Either monad here is trying to cover a dependency which doesn't exist.

comment 3y ago · link · parent

> If your pure function can return an error, then it will have a (T, error) return value in idiomatic go. In functional style the return value is Either[error, T] because function composition is easier with such a return type.

This seems flawed. In idiomatic Go, T and error are always independently observable. The Either monad implies that they are dependent, which is not true.

comment 3y ago · link · parent

> how do you exterminate a group of people without a state?

Communism, and thus the state being left behind, cannot happen until post-scarcity is achieved. Once post-scarcity is realized, why would you care if some still hold that mentality? They are only considered to be a hinderance in the days leading up to post-scarcity becoming a reality and during that time there is still a state.

comment 3y ago · link · parent

What are you adding, exactly? Communism is just a thought experiment that imagines what the world will be like when post-scarcity is achieved. Star Trek is a more modern adaptation of the same thought experiment.

Perhaps you are referring to actionable ideas we have come up with over the years to try and push us towards post-scarcity?

comment 3y ago · link · parent

> I'm generally not aware of how to make it work without significant centralized power.

You get rid of the need for power entirely. Communism, by definition, is free of state. That hinges on achieving post-scarcity.

The Communist Party’s primary tenant is achieving post-scarcity to one day usher in communism. The Soviet model failed, really, because they never got there. Probably not because of a poor power dynamic, but because post-scarcity was, and still is, beyond our grasp. It may not even be possible.

When you think about it, the Soviet model is fundamentally designed to fail! If everything went according to plan, it would have fallen to communism. It was never meant to be sustainable.

comment 3y ago · link · parent

Sounds like a trap. The first structure that came to mind was an r-tree. While I have a superficial understanding of when to use one, I have never needed to and would need to look up the details for the next question that is no doubt to talk about it in detail.

It came to mind first because I don’t know the intimate details and would need to look them up should I ever need that structure. That leaves reason to keep the name in active memory, unlike the structures you use daily, which never have reason to communicate outside of artificial situations.

comment 3y ago · link · parent

> And is a basic understanding of common data structures not allowed to be in that set?

It may not be unreasonable, but the question didn't ask that. Granted, it is unlikely the interviewer was skilled in interviewing and the ill-conceived question was born out of their own lack of ability in the the job they were thrown into doing. The reality is that very little effort goes into researching the science of hiring in the first place, and it is even less likely to find people who are both experts in technical matters and experts in what little we do know about interviewing. For how critical businesses claim the hiring process is, it is amazing how they will so often happily throw the first bumbling idiot they can find willing to accept the interviewer role into it like it doesn't matter.

comment 3y ago · link · parent

> Communicating about work is a core part of work.

Absolutely, and the work I do is solving problems to further business objectives. As such, we talk about business things. Lists, sets, and maps are not normally business-related terms. Indeed, programming is the tool we most often use to implement the solutions to the particular problems we face, but it is not the work any more than a hammer is the work.

> Respectfully, my assumption is that you also don't work in technology, or always work alone.

I do not work alone, but I use the tools alone, yes. I expect most do. I don't see much evidence that pair/mob programming has ever caught on in a significant way.

> Data structures are unrelated to brackets, so I assume this is hyperbole.

They are indeed related as some programming languages use [] syntax to denote use of the data structure mentioned. If the people involved in the conversation are familiar with those languages, they can infer what is meant through the process of communication.

> Someone claiming to have 10+ years of developer experience should know the word "list". Full stop.

You're going off the rails here. A developer of 10+ years will know the word "list". That is not in question. The topic of conversation is how they will not necessarily have it at the tip of their tongue, because why would they? Unless you are caught in the 10 years of experience doing the same thing over and over trap, leaving you forever a beginner, it is not something people normally talk about.

Again, what would seasoned developers need to talk about lists, sets, and maps for? They should know them inside and out, backwards and forwards. "Hey colleague, I need a list here, but I forgot how to do it. Can you help?" never comes up. "Good news everyone, I discovered this great new thing... It is called a list!" – not going to happen. If we were talking about esoteric data structures, that's a little more conceivable, but we are talking about the ones you use essentially every time you write some code.

comment 3y ago · link · parent

> This feels like either hyperbole or extremely rare/almost impossible

Why's that? Aren't these basic knowledge items almost always able to be left unspoken? "Here is what we are trying to accomplish, and you must use a map in your implementation" never seems pertinent. There is faith in the people I work with that they will understand how to best implement something.

Furthermore, if there were some reason to bring up, say, a list then I could fumble around with some other ideas to get the group there. "I'm blanking on the term, but you know, the thing you can build with square brackets.", "Oh, you mean a list?", "Yeah, that!" But that doesn't satisfy the question posed here which specifically asked for the structure by name. In normal situations you don't need that kind of thing at your beck and call like you do when you are playing with a trivia master.

> I believe it to be a core competency.

And, to be fair, if I were knowingly about to enter a developer interview I'd probably brush up on the language ahead of time knowing that it is likely that an interview very well might want to talk about the trivial basic building blocks to weed out those who have never programmed before. But I personally haven't interviewed for a job in 20-some-odd years, so again, not something in the forefront of my mind before this discussion happened.

However, of note, the interview in question was for a people-based job, not a technical role. Who is going to think to study the technical language ahead of time in that situation? It wasn't pertinent to the job. The interviewer just went there because it was noticed the person once was a developer in a past life.

comment 3y ago · link · parent

> If there would be real shortage, they would increase the salary.

Technically, a shortage occurs when an external mechanism prevents price from rising. Think price gouging laws as once such mechanism.

Where I am from, doctors are prevented from raising their prices in an effort to give equal access to all, rich and poor alike, which would allow for a doctor shortage to transpire. But a real labour shortage outside of such unique situations would be unheard of.

comment 3y ago · link · parent

> Why would you need to _communicate about programming_? Because it's a core part of your job...

Honestly, I am not sure I have personally ever had to communicate low level details like that with anyone else. The people I have talked pogromming with in my life have all be capable technologists, which allow us to discuss in high level detail. If a list is the right data structure for whatever high level problem we are trying to solve, it is assumed we know that and understand how to use it.

> Every interview question can be characterized as trivia if you squint hard enough.

Well, I suppose. And there isn't anything wrong with trivia per se. But at the same time it should not be surprising when someone doesn't have an answer. A lot of this stuff just isn't worth having in immediate memory – unless you enjoy trivia, in which case, cool!

comment 3y ago · link · parent

Yes, the down syndrome kids may find a job, but for same reason they struggled to go far in school, they will also struggle to go far in the workplace. This isn't surprising.

But it is faulty to think that going to college will cure what ails them. Statistically, most people who are capable of graduating from college do. Everyone capable of graduating from high school does. Those who fall short, so to speak, were held back due to limitations of themselves. The same limitations that hold them back throughout life.

As before, incomes have held stagnant. There is no premium. If you're born a top performer, it doesn't really matter what exactly you do – the numbers show that you have always been a top earner. College didn't change that. If you're born with down syndrome, it again doesn't matter what you do – the numbers show that you have always been a bottom earner.

comment 3y ago · link · parent

While that may be true, you are not comparing like people. I'm sure anyone here, even if they dropped out of high school, can make $1M+ more in their career than someone with a crippling mental disability. The latter of which being much less likely to be college gradates, making any comparisons meaningless.

If what you are trying to say is that college filters out those who are not well suited to high level careers, there is no doubt truth to that, but that is not the same as a premium. It is not like college can cure someone's disability. The same person sees no change, statistically.

comment 3y ago · link · parent

> If you can't even remember what list/set/map whatever is called, how are you going to use them?

Certainly not by dictating their names to my coworker. Why would I need to know their names? I suppose some languages require you to know their names in order to use built-in implementations, but lots of languages use other syntax – often void of natural language (e.g. [], {}, etc.) – to do the same.

I eventually got there, but it took awhile to remember. That's great if you have prioritized trivia to occupy your mind's space, but I have found no reason to.

comment 3y ago · link · parent

> which is easily negated by the college wage premium

We once thought there would be such premium. Wages held stagnant as people started going to college, though, and have continued to.

1
103104105
256