Better HN
topnewbestaskshowjobs
Log inSign up

codeflo

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

Submissions

comment 6y ago · link · parent

Can you explain why you have to pay for the Sun's gravitational well on the way to Mercury? From the famous XKCD illustration[1] I get the impression that it might be hard to "stop at" Mercury since the pull of the Sun is relatively strong. Is there no clever trajectory that comes close enough to Mercury to get caught in its orbit?

[1] https://xkcd.com/681/

comment 6y ago · link · parent

I didn't want to suggest it's undefined, I said weird. In C++, it's reverse declaration order, and that's important because destruction exactly mirrors construction. Arguably, Rust is completely wrong here, but my experience is that this problem doesn't come up in idiomatic Rust all that often because fields can't depend on each other anyway. And I'm wildly speculating of course, but something like that might be more of an issue if a lot of unsafe C++ objects are instantiated from within Rust.

comment 6y ago · link · parent

The usual understanding is that an unsafe function is any function that can, if passed the wrong arguments, cause Undefined Behavior. A lot of Rust’s std and library ecosystem provides safe wrappers around underlying unsafe C APIs, by cleverly using borrow semantics and performing additional runtime checks. The bar for safety is lower than you might expect, for example, crashing with a “panic” in case of an error is completely fine, that’s not considered unsafe.

Presumably, the C++ wrappers suggested here would not even be safe in that sense. They would use a lot of pointers, and cause UB if passed the wrong one. The article argues that using unsafe correctly is impractical for Chromium because basically every Rust function would have to be marked unsafe to call into these raw C++ APIs.

Whether that’s the right call, I don’t know. I see the practical argument, but I also think that a lot of common Rust idioms, especially around memory management, depend on these safety guarantees. For example, field destruction order in Rust is weird and you often don’t control it as carefully as you would in C++. That’s usually fine in normal Rust code, but might not be if lots of marked-as-safe-but-actually-unsafe code is flying around.

comment 6y ago · link · parent

Virus scanner false positives are slowly becoming my personal hell. From my experience, they aren’t even remotely anything as sophisticated as you suggest, but the fact that people believe that antivirus software can actually do this kind of analysis helps the vendors sell their snake oil. If they would be triggered by any actual behavior, changing random compiler flags wouldn’t usually remove the false positive. But you have to do that kind of tinkering, or users will be scared.

comment 6y ago · link · parent

Pascal is a neat little language, but are you really trying to claim that its features are on par with Rust? The grandparent poster might not have picked the best examples (I’d have chosen traits, zero-cost lambdas and syntax macros), but the point is, Rust’s abstractions are inspired by decades of PL theory research that haven’t made their way into any Pascal dialect that I know of.

comment 6y ago · link · parent

In Europe, and I can only assume that it’s similar to the US, the energy market is actually running a surprisingly complicated auction system. For example, since power generation and consumption have to be balanced at all times, power generation capability that can ramp up and down quickly is more valuable than one with the same nominal power that can only be controlled slowly. As far as I understand, all of this is priced in, with separate auctions for different timescales.

What batteries allow you to do is to perform time arbitrage in this market. As with many other forms of arbitrage, this should lower average prices, though some specific current uses could suffer. For example, if this is deployed at scale, electricity might no longer be all that much cheaper at night.

comment 6y ago · link · parent

The perspective that there are “thousands of things that are illegal” but not prosecuted always fascinates me, that’s not at all a common perception e.g. here in Germany. Is that a difference between common law and civil law systems? Maybe in places where code law is mostly binding, there’s a lot more pressure on the legislature to keep the law books up to date with the current norms of society.

comment 6y ago · link · parent

The researchers discuss the question whether “huh” is a word or just a grunt in the linked paper. (https://journals.plos.org/plosone/article/file?id=10.1371/jo...):

> Huh? exhibits linguistic conventions that speakers need to learn in order to use the form properly. A learner of Spanish has to know that repair is initiated with the mid front unrounded vowel ‘‘e8’’, a learner of Cha’palaa has to know that the form is more like ‘‘aQ’’ with falling intonation, and a learner of Dutch has to know that a glottal fricative at onset is common: ‘‘h38’’. Its acquisition follows a normal trajectory, at least in American English-speaking children [37]. Second language learners’ reports confirm that the precise form of this interjection has to be learnt, and that intuitions are not necessarily a reliable guide in this process [38].

> Perhaps there is a continuum from non-linguistic vocalisations like sneezing and crying to prototypical conventional lexical items like bless you and pain [39]. Our evidence suggests that huh? is more on the word side of that continuum. Based on the fact that huh? is integrated in multiple linguistic subsystems and conventionalised in language-specific ways we conclude that huh? a lexical word.

comment 6y ago · link · parent

I have never heard such a thing. Are you talking about font rendering differences? There are different anti-aliasing algorithms, but they don’t have anything to do with this convention.

comment 6y ago · link · parent

Pixel centers at (0.5, 0.5) is the convention adopted by all major graphics APIs (OpenGL, DirectX, Vulkan, Metal). That’s because it makes the math, especially around image scaling, becomes a lot simpler. What exactly the alignment problem you say isn’t solvable?

One common mistake is to not think in floating point coordinates all the way through. E.g. a rectangle that covers a single pixel should have coordinates like (100.0,100.0)-(101.0,101.0), NOT involving a 0.5 offset. You almost never offset anything by 0.5 in this convention. 1 pixel wide lines are an exception, but only because then the edges of the line are exactly at pixel boundaries.

comment 6y ago · link · parent

For the most part, the Rust community seems to value safety and correctness above extracting the last bit of performance. Using “unsafe” code is seen as a necessary evil, only allowed when its use is hard to avoid, local and easy to understand. Mostly, you’re supposed to use unsafe code as the foundation which safer abstractions are built on top of.

It’s a bit if an oversimplification to say that the Rust community complained about the amount of “unsafe” code in Actix. It was more about the how and why.

From what I gather, the author didn’t accept patches that fixed safety/soundness bugs when they had even a small impact on performance. That’s a trade-off that one is allowed to make in my opinion (if clearly communicated, so that people can make informed decisions on whether to use a piece of code).

I think this difference in values (or rather, engineering goals) explains in part why this escalated so badly. But a healthy software ecosystem should have room for libraries that make different trade-offs. Zealotry (in the form of “There’s one right way”) doesn’t encourage experimentation, and shrinks communities instead of growing them.

comment 6y ago · link · parent

I’ve read that some vector instruction sets use masking instructions to avoid branching. You execute both arms of the conditional and discard the unwanted computation, which can be cheaper than an X% chance of a branch misprediction.

Should CPUs include more masking instructions for regular, non-vectorized code as well?

comment 6y ago · link · parent

Thanks for the correction, Microsoft calls it the C Runtime/CRT. It‘s unfortunately complicated, and I’ll completely ignore static linking, which is possible, but not supported in many scenarios involving DLLs.

It used to be the case that the CRT shipped with Windows (msvcrt.dll). That file is now considered legacy/deprecated and is no longer supported by current compilers. For several years after that, you always had to redistribute the CRT (msvcrtXXX.dll), even for pure C support.

The current state of affairs is that the CRT is split into several files, some of which come with Windows update (the so-called UCRT) and some of which are compiler-specific and have to be redistributed. C++ std support requires yet more files.

This document gives an overview: https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-l...

comment 6y ago · link · parent

That’s exactly my point: The problem is that Rust doesn’t use the stable kernel32/user32 functions (VirtualAlloc etc.), but the libc ones, which don’t have a stable location on Windows. Without looking it up: Which DLL do you have to redistribute this week to get “malloc”?

comment 6y ago · link · parent

Yeah, I saw your username too late or I would have known that you know that. ;) But it’s a common misunderstanding among many Unix programmers, so I feel it was good to clarify.

comment 6y ago · link · parent

There are lots of tiny practical annoyances you notice, starting with having to vet dependencies and transitive dependency upgrades extremely carefully. A major one is that dev-dependencies are very broken in a no_std environment. It’s obviously useful to have the std in your build.rs script, but unfortunately, Cargo merges dependencies and devDependencies in a way that’s simply incorrect.

The good news is that every problem I found had an actively discussed GitHub issue and the community is active, so there will be progress.

comment 6y ago · link · parent

Basically yes. ntdll is an implementation detail that shouldn’t be relied upon. kernel32/user32 and friends are considered the “proper” interface to the system and have been stable for decades.

comment 6y ago · link · parent

That’s partly true, but the stable interface on Windows is not the libc, but the kernel32/user32 functions like VirtualAlloc, CreateFileW etc. Those are stable since the NT days. The libc functions like malloc and fopen are a compatibility layer above that and unfortunately switch places every few years. Currently they are delivered by a combination of a Windows update and a redistributable package, which makes it a nightmare to ship (on pre-Windows 10 even more so).

comment 6y ago · link · parent

The only stable interface on Windows are the documented functions from kernel32.dll, user32.dll etc. Libc is a compatibility layer above that, that Microsoft invents a new incompatible distribution mechanism for every 3-5 years. It’s pure DLL hell unfortunately.

Edit: Not even the DLL name of Microsoft’s libc is stable (msvcrt140.dll etc.), leading to all kinds of wild goose chases when trying to run old binaries.

comment 6y ago · link · parent

That’s true. But going the no_std route is very hard (the ecosystem isn’t big, and relying cargo and crates.io you’re almost guaranteed to link in the std or liballoc by accident at some point). Even when using the std intentionally, I really wouldn’t have expected that basic std functions like println require the libc.

comment 6y ago · link · parent

I recently did some experiments with creating small static Rust binaries, custom linking, no_std et cetera. A lot of stuff around that kind of thing is unstable or unfinished, which might be somewhat expected. But I’ve also come to the conclusion that Rust relies on libc way too much. That might be fine on Linux, where GNU’s libc is well-maintained, is a bit questionable on MacOS (as seen in this article) and is a a complete distribution nightmare on Windows (in no small part due to a series of very questionable decisions by Microsoft).

My understanding is that Go doesn’t use the libc at all and makes system calls directly, which IMO is the correct decision in a modern systems programming language that doesn’t want to be limited by 40 years of cruft.

comment 6y ago · link · parent

Yes. Judging from the HN discussion of a very similar list a week ago, a loud minority confuses “not Turing complete” with “sandboxed”. Hence lots of discussions about security that seem to miss the point.

comment 6y ago · link · parent

I’m unsure of how you mean that in a technical sense. It’s straightforward to make those guarantees in your interpreter.

And just to be clear, Dhall, the configuration language we’re talking about, is not TC, but powerful enough to compute the Ackermann function: https://gist.github.com/Gabriel439/77f715350ecc0443eed5fa613...

Add “ackermann 10 10” to your configuration file and you have something that’s technically proven to terminate, but won’t do so before the sun burns out. No security properties are gained here.

comment 6y ago · link · parent

I find your first link particularly ironic. It claims that certain words are used beyond their literal meaning as a "signaling mechanism" for "like-minded people" that you're doing the right thing. And "non-Turing completeness" is one such "shibboleth" that signals to security-minded people that your configuration language is very secure and awesome.

Now I could claim on the contrary that whenever you're using "security" and "non-Turing completeness" in that way together, the only thing you're actually signaling is that you don't know WTF you're talking about.

comment 6y ago · link · parent

I simply don't think Turing completeness is the deciding factor in determining that difficulty. Hopefully someone can define this more clearly, but in my opinion, the issue is not abstract "state space", but implementation complexity and attack surface.

For example, it's a lot easier to write a secure Brainfuck interpreter (a very simple Turing complete language that can only access STDIN and STDOUT) than a program that securely extracts a ZIP file to disk.

comment 6y ago · link · parent

I’m not sure why that’s explicitly mentioned, I believe that for analyzing security, TC is a bit of an academic red herring. (Warning: not an expert.) There are two kinds of security implication to consider here I think.

One, can certain input data cause a large usage of computing resources (processing time or memory)? Non-TC mechanisms have repeatedly failed this test: ZIP bombs and XML entity bombs are notorious examples. On the other hand, you can easily put a resource cap on an interpreter of a theoretically TC language and be safe.

Two, can the untrusted code access resources that it shouldn’t (memory, files, sockets)? That’s mostly a quality of implementation issue, not one of Turing completeness. JavaScript interpreters have certainly been vulnerable to various exploits, but so have JPEG decoders. I don’t think TC is the issue here. (However, this is complicated a bit by side-channel attacks à la Spectre. I’m not sure how TC factors into those.)

In summary, I’m not convinced that Turing completeness is all that relevant for security. Am I wrong here?

comment 6y ago · link · parent

The problem is basically a variant of Goodhart's law: "When a measure becomes a target, it ceases to be a good measure."

Publications want to use these benchmarks as a convenient proxy for real-world performance. Phones have "benchmark detection" and run their power management with different settings when they detect that a benchmark is running, defeating the purpose of running the benchmark.

BTW, I don't think this is about gaming vs. non-gaming workloads (there are different benchmarks for those), or even running plugged-in vs. on battery. My understanding is that some of these "benchmark modes" are so aggressive that the phones would become too hot to hold in your hands. No sane phone manufacturer could use settings like these for real-world usage.

comment 6y ago · link · parent

I don't think this would work, the size of the network would likely dominate the size of the compressed image.

comment 6y ago · link · parent

Also, shouldn’t true Pauli chess allow an arbitrary number of pieces in the same square, but no two of the same kind and color?

comment 6y ago · link · parent

You don’t capture kings in chess, and I don’t think that changes in this variant (at least the article doesn’t suggest that). If you attack the square with the king on it, the king is in check. If there’s no legal move that puts the king out of check, that’s checkmate.

Perhaps interestingly, you can create a discovered check with two pieces on the same square, say two rooks. Like a double check in regular chess, you can’t remove the check by capturing, because you would only capture one of the rooks.

1
404142
51