Hacker Newsnew | past | comments | ask | show | jobs | submit | appellations's commentslogin

Thanks for all your hard work!


Founding engineer is the worst role in tech


Which role do you prefer and why?


Meh. I like it. The key is to not get emotionally invested and help make that transition to a bigger operation if things go well.


    Add(x,y):
       Assert( x >= 0 && y>= 0 )
        z = x + y
        Assert( z >= x && z >= y )
        return z

There’s definitely smarter ways to do this, but in practice there is always some way to encode the properties you care about in ways that your assertions will be violated. If you can’t observe a violation, it’s not a violation https://en.wikipedia.org/wiki/Identity_of_indiscernibles


In some languages overflow is asserted as a can't happen and so the optimizer will remove your checks


Best I can tell is that overflow is undefined behavior for signed ints in C/C++ so -O3 with gcc might remove a check that could only be true if UB occurred.

The compound predicate in my example above coupled with the fact that the compiler doesn’t reason about the precondition in the prior assert (y is non-negative) means this specific example wouldn’t be optimized away, but bluGill does have a point.

An example of an assert that might be optimized away:

    int addFive(int x) {
        int y = x + 5;
        assert(y >= x);
        return y;
    }


Yes, you can not meaningfully assert anything after UB in C/C++. But you can let the compiler add the trap for overflow -fsanitize=signed-integer-overflow -sanitize-trap=all, or you could also write your assertion in a way where it does not rely on the result (e.g. ckd_add), or you use "volatile" to write in a way the compiler is not allowed to assume anything.


Clang is a bit smarter than GCC here (for some definition of 'smart') and does optimize the original version:

https://gcc.godbolt.org/z/3Y4aheG6x


Care to share a language where the compiler infers the semantic meaning of asserts and optimizes them away? I’ve never heard of this optimization.


Signed overflow is UB in C/C++ and several compilers will skip explicit overflow checks as a result. See: https://godbolt.org/z/WehcWj3G5


C. This is a great thread: https://mastodon.social/@regehr/113821964763012870

(That was one of my texts at uni)


C and C++


I forget there are people who don’t configure softwrap in their text editor.

Some languages (java) really need the extra horizontal space if you can afford it and aren’t too hard to read when softwrapped.


Apple has a history of adding sensors, security chips, etc. a few revisions before the feature they support launches. It’s a really good idea because it helps them sort out the supply chain, reliability, drivers, etc. without any customer impact. It decouples the risks of the hardware project from the risks of the software project.

If things go particularly well you get to launch the feature on multiple hardware revisions at once because the first deployment of the component worked great, which is a neat trick.


Yeah, my iPhone 11 Pro came with the ultra-wideband chip in late 2019, and before the AirTags were released in early 2021, I believe the only thing it was used was for ordering AirDrop targets by proximity. It was clearly intended for the AirTags from the beginning, but it took about 1.5 years before it actually mattered.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: