Better HN
topnewbestaskshowjobs
Log inSign up

codeflo

9,664 karma · joined Jun 14, 2010 (16y ago) · 1,504 submissions

Submissions

comment 4y ago · link · parent

I agree unwrap is tragically overused in example code, and any non-logic error should use a Result instead — even early in a project. This isn’t a huge overhead. Even in “prototypey” code, it’s not hard to make everything return an anyhow::Result and upgrade to more fine-grained error types later. The main function can return a Result as well (which will be unwrapped by the runtime), making this style almost as concise as the unwrap version.

I also agree that panic and crash is usually the correct response to a logic error.

However, I think library functions like Regex::new shouldn’t decide for me what I do or don’t consider a logic error — how should the library know where that string comes from? They also shouldn’t be effectively required to offer two overloads for every function just to enable both decisions: there’s already a very clean way to put that decisions into the hands of the library user, Result.unwrap() vs. Result?.

Now, about unwrap vs. expect: Since the author and I agree that panics should be reserved for logic errors, the expect() argument is effectively only a debugging aid. Should that be required? I’m torn. Often, which one I personally use reflects my confidence in getting the invariant correct and never hitting the panic in production. That can be risky. A particular team in a particular context might therefore adopt a convention to always use expect instead of unwrap, that’s fine. But I don’t think it’s unreasonable that the language offers a choice here, and in similar places, like the no-parameter variant of panic!().

comment 4y ago · link · parent

I have to wonder where this person’s school circumstances.

For example, why was the triangle area formula only memorized and not demonstrated to them? I thought this should be standard everywhere in the world? Maybe they just don’t remember, it happens early (age 11-12 for me IIRC).

Similarly, and this is from two decades ago at this point, some basics of gene expression and cell differentiation were covered in my later biology classes, including some of the evolutionary steps. Details are of course fuzzy now. But I clearly remember that learning we share so many genes and so much cell chemistry with even basic bacteria threw me into a bit of an existential crisis when I was 17 — making me question what if anything is so special about humans.

When they were students, some people were simply unwilling to follow any train of thought that was unlikely to be test-relevant. The author almost admits as much: “Someone probably told me that every cell in my body has the same DNA. But no one shook me by the shoulders, saying how crazy that was.” That’s a perfectly fine way to approach school, I’m not judging. But then maybe don’t complain that you didn’t learn anything?

comment 4y ago · link · parent

I hope this Imgur link works, here are two shots of what I assume is the same room. You can't possibly be serious: https://imgur.com/a/IGPhFtd

comment 4y ago · link · parent

Taste is certainly subjective, and I'm also not complaining that styles evolve. But can somebody explain to me what the art style is even trying to do? I mean this purely on an intellectual level, regardless of personal preferences.

Because I have a hard time recognizing the noses as anything but face wounds in some of the shots, and I wonder why the colors were chosen this way. Characters don't stand out from the background very much, which again, is an intentional choice of colors. And the animations seem to happen mostly via rotations and stretches in the 2D plane, which makes everything look flat. (I think that's also what gives the "flash game" vibes that another commenter described.)

Is this supposed to look like it's made out of paper cutouts (in the style of other games with a "hand-crafted" look, like Paper Mario or Kirby's Wooly World)? That's my best guess, but I'm grasping at straws.

comment 4y ago · link · parent

"Non-contrived" is a matter of definition; it's almost necessary to give toy examples, but I hope you can be convinced that the same structural pattern can appear in real code.

I hope Clang on x86_64 is common enough for you to make my point. In this example, Clang reasons (backwards in time) that the if couldn't have been taken and dereferences whatever was in p, instead of dereferencing null: https://gcc.godbolt.org/z/zjhY1W67Y

comment 4y ago · link · parent

It's dangerous to assume that you know better than someone like Raymond Chen, the author of the article the GP linked. This is not a Clang bug, it's just the nature of UB optimizations we're talking about. :)

I've found a simple example. Code order and compiler options are very finicky with this sort of thing, but as of posting this, clang optimizes away the null dereference here entirely: https://gcc.godbolt.org/z/zjhY1W67Y

(Edit: Simplified example even a bit more.)

comment 4y ago · link · parent

In addition to the spacebar issue, the fact that the rows aren’t shifted, which by row 3 means the Z is below the Q instead of below the W, will make your brain melt.

comment 4y ago · link · parent

I have a clarification: Dereferencing a null pointer in C++ doesn’t reliably crash anymore, unfortunately, and if you still believe it does, then I do not want to run your C++ code. I assume that the author understands this and is only trying to simplify. My problem is that this is already such a widespread and dangerous myth that I’m sad to see it perpetuated in an otherwise great article.

For anyone who’s wondering, I’m referencing “UB” here (which is short for Undefined Behavior, but don’t be confused by the English language meaning, it’s a precise technical term in the spec). Skipping the details, there’s a surprising (and growing) amount of situations where a null pointer access leads to silent incorrect code execution instead of a crash already, with standard compilers and CPUs. C++ programmers need to deal with that on any platform. As I’m sure the author is aware, what the WASM compilers do here is well within the spec.

comment 4y ago · link · parent

Context?

Edit: Thanks! This submission was incomprehensible on its own.

comment 4y ago · link · parent

I don’t know anything about particular political distortions in the US, though I wouldn’t be surprised if they exist, at least on a small scale. What I can tell you is that electric energy is traded on complicated spot markets that are designed to ensure that production and consumption are balanced at every point in time. Overproduction is as bad as underproduction, as the power grid can’t store excess energy. Fuses are tripped to prevent short-circuits, causing blackouts. This makes time-based arbitrage difficult.

Since power demand isn’t entirely predictable, flexibility is rewarded in these markets. For example, if there’s a downward spike in demand that causes an imbalance, you can earn extra money by either having a power plant that can ramp down very quickly, or by being a consumer that can ramp up very quickly.

I wouldn’t be surprised if mining rigs participated in these spot markets. In theory, they should be able to adjust their power consumption within seconds.

BTW, it’s been theorized that overnight charging of electric cars could do the same thing and dynamically adjust the charging speed based on spot prices.

comment 4y ago · link · parent

The text tries to introduce the idea of a “narrow waist” as an architecture pattern. But I don’t fully understand how the author distinguishes this concept from similar ones, and some of the examples even seem to contradict the principles.

It supposedly solves the N*M problem (so it’s an interface?), but it can’t be statically typed (so the interface has to be implicit?), and success stories are HTML5 and the x86 ABI (so it does require explicit specification after all, and huge amounts of it? Just look at the size of that Intel ABI book…), but also, it must be plaintext (so not like x86 at all?).

I’m not trying to be mean because maybe there’s something there that I miss, but frankly, I don’t get it, at least not yet.

comment 4y ago · link · parent

If the colonies were fed human cells, I’d agree.

comment 4y ago · link · parent

To be clear I understand you correctly, you think there was a chance that Intel would add a CPU instruction that is "more performant" than ADD? In fact, significantly so, to the extent that this would justify the overhead of a dynamically linked function call? Do I understand you correctly?

(BTW, this is exactly the kind of argument people made in defense of left-pad, which in my view completely validates my analogy.)

comment 4y ago · link · parent

Wow, that comment must have hit a nerve.

comment 4y ago · link · parent

Not sure why you mention Intel extending their instruction set, the addition of stuff like SIMD never changed the behavior of anything that existed before.

Very few programs ran on non-x86 back then anyway. Some people used to argue that writing assembly is more portable than using OS functions. I’m not saying I fully agree with that view, but it’s a discussion one can reasonably have.

comment 4y ago · link · parent

The function is dynamically linked from kernel32.dll, compiler inlining is irrelevant here.

comment 4y ago · link · parent

I love how this shows some of the problems with unnecessary dependencies even back in 1995.

Let’s say you really only cared about the sign of the result — freeing a resource when a refcount reaches 0 is a plausible use-case for that. But instead of using a single CPU instruction, you decide to link in a Windows function, because it’s easy, and why not pay for the overhead of a dynamically linked function call when CPUs are so fast?

And the joke is, when users upgraded to Windows 98, your program became a lot slower, because without asking you, the API was augmented to emulate a CPU feature you don’t need.

If this isn’t essentially 1995’s left-pad, I don’t know what would qualify.

comment 4y ago · link · parent

That’s only an implementation/optimization difference, I think it’s also relevant to understand why that’s the case. At the API level, the important distinction is that a Mutex an be shared between processes. This is great when you need it, but having the capability makes Mutexes have a somewhat expensive implementation. CriticalSections stay inside the process, so can be optimized for that (more common) use case.

comment 4y ago · link · parent

As the comment you reply to states: “INC/DEC don’t give you a copy of the value to examine. (…) If you want that, you need a second instruction.”

Here’s what you might be missing: Even on a single processor machine, if you have multiple threads and a preemptive (!) multitasking OS like Windows 95, any locking protocol can be interrupted mid-sequence. A second OS thread (yes, they existed) may be scheduled and observe an inconsistent state. Or it may perform an update on its own and leave the first state in an inconsistent state when it resumes.

And yes, this kind of stuff actually happened.

comment 4y ago · link · parent

I’m sure the thing you quoted is technically true, the existing features are still there somewhere. But it’s not a great experience if some of the most prominent buttons in the VS Code UI now open the GitKraken account page. YMMV; I personally found this very “in your face” and unusable.

comment 4y ago · link · parent

It’s a real problem. GitLens[0] comes to mind, which used to be a decent free extension, but now gives me flashbacks to the shareware nag screens of old.

I’m also not against selling software on principle. Downgrading a free piece of software into a demo with an auto-update feels shady, however.

[0] https://marketplace.visualstudio.com/items?itemName=eamodio....

comment 4y ago · link · parent

I’m fully with you. This greatly simplifies tooling by making transpilers entirely optional, meaning you don’t need a complicated setup just to get going. Developers get convenience, users aren’t affected, that’s a win all around.

People may not fully realize this, but the problem with the “just standardize TypeScript” suggestions is that TypeScript is a fast moving target. This is actually well argued in the proposal: lots of meaningful innovation is still happening in that space with more precise checks, which also means that small incompatibilities happen from version to version. That’s okay if we’re talking about dev tooling that a team can choose to upgrade at their own pace. It would be really bad to have browser upgrades affect the functionality of existing websites.

comment 4y ago · link · parent

True, but if you’re just listening and not for some reason updating your whole library, we’re talking about one block write every three minutes or so. That’s negligible compared to everything else the system is doing.

comment 4y ago · link · parent

To be technically correct, it’s called a finalizer in that case to distinguish it from deterministic destructors.

For resources like memory, where it’s merely a question of performance, I would agree. But some resources have correctness implications. Files, for example, you often want to close deterministically. It’s simply a terrible experience if a user can’t save because a file handle from a previous operation still lingers in a GC queue somewhere.

That’s also the reason why language features like try-with-resources were added in the first place.

comment 4y ago · link · parent

I wish this also contained an alternative suggestion. Where else should I hide the link to the privacy statement and the button for opting out of data collection?

comment 4y ago · link · parent

BTW, a lot of people in this thread compare destructors to Java's try-with-resource (similarly, C#'s using), or Go's defer.

Here's one important difference: Destructors work in standard data structures. If for whatever reason you want to build a map<string, list<fstream>>, and the map goes out of scope, all files are correctly closed. (Rust's drop semantics work the same way.) That's a lot more work in Java or C#.

comment 4y ago · link · parent

Rust doesn’t have initializers in the C++ sense. And I mean, even in C++ many classes like shared_ptr or even lock_guard have constructors that don’t acquire the resources yet. When the resource is acquired is an API design concern; the important part is where it’s released.

comment 4y ago · link · parent

I think the points you mention are easily noticed by people who lived in that era as anachronisms. At least that's true for me. And yet, Minecraft does all of those things and more, and I liked its style. I think it really depends on how well it's done.

comment 4y ago · link · parent

1. It’s a bit of a straw man to claim that’s the only reason or measurement of success for sanctions.

2. The violence on the vulnerable is inflicted by the sanctioned regime, not the sanctioners. As another commenter noted, these regimes effectively hold their population hostage. They could feed their population, they just prefer to pour everything into the military.

3. In your example, are the residents following the orders of those burglars?

comment 4y ago · link · parent

But again, who is it that makes that call?
1
242526
51