Better HN
topnewbestaskshowjobs
Log inSign up

devit

4,235 karma · joined Sep 10, 2015 (11y ago) · 1,525 submissions

Submissions

comment 8y ago · link · parent

Because unlike most other programming languages, Rust is well-engineered and seeks to both provide the most general abstractions possible and to make the code generated by them as efficient as possible.

In particular, for this task, this requires to:

1. Return references to subranges of the original string, rather than copying them, so that no copy happens if you only need to examine the component instead of storing it

2. Not use reference counting to do so, but rather statically checked references with lifetimes, to avoid unnecessary instructions to update the reference count and lack of a static finalization point

3. Provide a way to get components one by one, so that if you only need e.g. the first two, time is not wasted to split the whole string

4. Provide that through a generic Iterator trait, so that it may be passed to generic methods (like one that collects the result into a vector)

5. Dispatch that generic trait statically rather than using an indirect call as that would destroy performance

6. Make the state manipulated by such an interface into a first-class object, and allow to put them in a data structure (like an array) while still doing static dispatch, so that you can, for instance, split multiple strings into components and interleave them without ever making an indirect call.

The combination of these essential requirements results in the creation of the SplitWhitespace<'a> data type, which represents the state of a parser splitting a string into 'a-lifetime references to whitespace-separated its components one by one, implementing the Iterator trait, and usable in a data structure.

comment 8y ago · link · parent

The simple solution is to always require a certificate by Let's Encrypt, and allow the website to optionally present a second OV/EV certificate in addition to the Let's Encrypt DV certificate.

Although it's unlikely that's of any use, since unsophisticated users aren't going to differentiate, and sophisticated ones can use other means to verify identity.

comment 8y ago · link · parent

Security requires that ALL CAs be secure, since any compromised CA can compromise all websites (barring fragile schemes like pinning or certificate transparency checks), so the less CAs there are, the more secure the system is.

It's like a building that needs secure doors: it's better to invest in a single, massive, bulletproof, guarded door rather than inviting anyone who meets some standards to add a door to the building, since what matters is the weakest door.

comment 8y ago · link · parent

Browsers need to remove all CAs except Let's Encrypt.

CAs have proven again and again to be ridiculously insecure, and the problem is that there is no penalty for their mistakes.

So just remove them all, after a warning period: Let's Encrypt is enough.

Or if they want to stay in business and be trusted by browsers, then require them to put up at least $100k in cash in escrow for each certificate they sign, which is forfeit if there's evidence that any compromise of that specific certificate, due to their fault, has or may have happened, with at least half of the money being distributed to whoever provides the evidence first.

comment 8y ago · link · parent

Is there an estimate on the magnitude of the maximum total bandwidth achievable with a LEO satellite, both for a smartphone client and for a fixed home antenna?

How far would it be to 4G and gigabit fiber respectively?

comment 8y ago · link · parent

Smartphones are commoditized and there are non-Google Android smartphones on the market, so they should be able to get some made. Also, they can just buy any unlocked phone at retail, replace the OS, rebrand and resell (obviously this limits the market due to high price, but also requires no upfront investment).

As for Play Services, they could just have a team whose job is to make MicroG work exactly like Play Services so that all apps work including the Google apps.

The only Google app that you need to replicate is the Play Store client (or really, the downloader, since you can just use the Play Store website for the UI) and then the user can install all the Google apps from the Play Store.

As for getting developers to put apps in their store, it's certainly much easier than getting them to write another app.

comment 8y ago · link · parent

Because writing a whole OS from scratch competing with giant companies and having to somehow magically go from 0 to a million apps (while being unpopular due to the few apps) is a good place to be in?

Instead, they could have gotten all the Android apps and the popularity of Android essentially for free.

It's even possible they could have overtaken Google and became the effective steward of the Android platform, since Google doesn't offer a version that can be installed by users and also doesn't offer their version to OEMs with no strings attached.

Again, they still can do that now, since there still isn't a version of Android that runs on any phone other than LineageOS, which is relatively underfunded.

[obviously what Mozilla would gain from this is market share for Firefox for Android]

comment 8y ago · link · parent

What they lacked is support for Android apps, since obviously expecting everyone to rewrite all apps for a new platform is a non-starter.

If Mozilla had simply acquired LineageOS, worked on MicroG to reach feature parity with Play Services, added Firefox for Android and their own app store in addition to Google Play via MicroG, and resold flagship Android phones with that as well as offering it to OEMs, they would have had significant success at very little cost.

In fact, they still could do that.

comment 8y ago · link · parent

The main advantage is that you can combine them with public transportation: you take a dockless bike to an underground/bus station, then once you get off you take another dockless bike to the destination, which effectively gives you very cheap and very fast transportation from anywhere to anywhere.

The other advantages are not having to worry about theft, being able to get a bike wherever you are even if you didn't anticipate it, and being able to get somewhere by bike and go back in a car with someone else or vice versa.

comment 8y ago · link · parent

Why use a straw at all instead of just drinking directly from a drinking glass, thus avoiding the need to wash and manage the straws?

Also, glass is a better material than steel for food applications, and glass straws exist, so they are probably a better choice (unless there's a significant chance of breakage like giving them to small children).

comment 8y ago · link · parent

Basically the traditional way to do I/O is to just call I/O functions (like printing to the terminal and reading keyboard input) in the middle of the program.

There is another way, which consists of having the program only consist of a pure function that returns the kind of an I/O function to call, its parameters, plus a closure that takes the result of the I/O function, and returns again a pair of I/O function kind, parameters and closure.

Then, an external "executor" can just perform the I/O, call the closure with the result, perform the I/O again, etc.

The result of this is the program can be executed to do I/O, but all functions are side effect free (they just compute a result based on the arguments).

The tuple of I/O function kind to call plus parameters plus closure is called an "I/O monad" (or equivalently it can be just the closure).

Now in this model if you want to have subroutines you need them to return an I/O monad, and need to be able to "chain" the rest of the computation to it, which is done by adding a method to the I/O monad called "bind".

These subroutines might not do any I/O, but it's still convenient to return an I/O monad, so an operation called "return" is added, which returns an I/O monad whose I/O function simply returns the parameter to return.

This interface with those "bind" and "return" functions is called a "monad", of which the I/O monad is an instance (along with some obvious properties, like that calling bind twice is the same as calling it once with the composition of the two functions, and that return and bind also commute in the same obvious way).

Another example is the "state monad", which is like the I/O monad except the operations are "read variable #i" and "write variable #i" (Haskell uses STRef objects instead of variable indices, but it's essentially the same).

While the I/O monad can only be executed "externally" to the program, the state monad can be executed internally: a pure function can be written that takes an array of initial values of the variables, a state monad instance and executes the state monad instance and gives back the final variable values.

So this gives a more complicated way of expressing imperative programming that has the advantage of only involving pure functions and thus being usable in pure languages like Haskell.

Now, why isn't this the best thing since sliced bread?

The obvious problem is that a naive implementation is massively inefficient, since every time you want to perform a memory write you need to stuff the stack of the program into the heap and return it as a closure.

Furthermore, monads for normal I/O and state are just not very useful: isolating the computation can be done with Rust's model of lifetimes and linear types, the ability to execute it in different ways can be achieved by providing a dynamically-dispatched set of I/O functions, and stopping the computation can be performed with unwinding.

The only practical advantage of monads is that you can pause the computation and have the state on the heap instead of the stack. This is why efficiently implemented languages like Rust (and in this case Java/C#/JavaScript) only use monads to implement futures/promises, where this ability is exactly what is wanted, and don't use state monads or I/O monads for synchronous I/O.

As an aside, the reason futures/promises are the best way to do I/O is that when the computation is paused, the state is stored on a heap in a compact layout (as a future/promise monad instance), while with either threads or coroutines it consists of an inefficiently laid out machine stack in userspace (that also takes a lot of virtual address space since it must be able to grow arbitrarily) and in case of native threads a machine stack and thread structure in kernel space as well.

The async/await and future/promise support in Java, C# and JavaScript is essentially a direct implementation of the Haskell monad model, with the downside of requiring an allocation for each await.

However, there's also way to have a monad-like style while preserving near-optimal performance, which is used in Rust's async/await generators.

The idea is that instead of having monads be closures that return closures, they instead become generic "objects" with a method that, upon being called, updates the state of the object and returns a description of the I/O operation to perform (or even just performs it with parameters provided by the caller), and is called again and again until it signals that the computation is done (this of course involves mutable state, but the mutation can be restricted with ownership).

"bind" can then be performed by simply defining a larger object that embeds the inner "monad" and the whole thing can be monomorphized, thus removing any dynamic dispatch and having a program that behaves as normal, except that instead of storing variables in the stack, it stores them in a single variable that needs to be immovable, either by heap allocating or ensure it's not moved on the stack. Note however that you need further allocations for recursion and in general for any dynamic calls whose state does not have a bounded size.

TLDR: monads primarily exists because Haskell must be pure and doesn't care about performance, but also because they are the only way to do memory-efficient async I/O

comment 8y ago · link · parent

Yeah but in Rust and Haskell it's isolated to clearly marked code (except for some minor bugs in Rust that will be fixed - see https://github.com/rust-lang/rust/issues?utf8=%E2%9C%93&q=is... ).

Instead TypeScript has a bunch of serious unfixed design flaws that make the problem pervasive, plus they refuse to fix them (see https://github.com/Microsoft/TypeScript/issues/9825 ).

comment 8y ago · link · parent

It's not: the TypeScript type system is unsound (accepts code that violates it), and there are no runtime checks, so it doesn't actually guarantee anything: a TypeScript variable may in fact contain any value regardless of its declared type.

I'd say the best type systems are found in Rust (naturally models zero-cost abstractions but doesn't have dependent types) and Idris and Coq (have dependent types but don't naturally model zero-cost abstractions).

comment 8y ago · link · parent

It's not "nasty" at all, it's an irrelevant bug, since local account security is easily bypassable in a lot of ways.

It's also trivial to fix: just create a directory in Temp and put the executable there instead of directly in the Temp directory.

comment 8y ago · link · parent

The big issue is that the companies have absolute power over facilities that should be mankind's possession and thus managed with explicit laws and a justice-like system offering due process.

Google is managing mankind's search engine with a secret algorithm and they can arbitrarily decide your site's presence or position in search queries with no recourse (granted, it's hard to define a fair way to do this, but still).

Facebook is managing mankind's person-to-person communication system and you have no recourse if you are banned, if your content is removed, or if you are trying to publicize some content and the newsfeed algorithms are unfavorable to you.

Amazon is managing mankind's delivery system and you have no recourse if they refuse to carry your products.

[Apple is less of a problem because they are merely monopolizing iOS devices, and there's an easy fix in terms of forcing them to open source iOS and license any related patents, so that iOS apps can be made to run on Android devices]

Reddit is another huge problem as they manage (and especially allow random moderators to manage) mankind's discussion forums with no regard to free speech, with arbitrary bans and no enforced transparency.

One option is to enforce competition: this could be done for Google by only allowing them to operate their search engine for up to a few consecutive hours per day, can be done for Amazon by allowing them to operate only a few days per month, for Facebook by forcing them to federate their social graph, so that people can host their accounts on any service and still have the same interaction and for Reddit to also federate their forums like Usenet is federated.

The other option is to be force them to manage all these facilities in the public interest, with explicit and published rules of operation (e.g. Google and Facebook must publish their ranking algorithms) and with all protections like free speech applying, according to well-defined rules and providing due process for any decisions that are adverse to anyone.

Obviously these should be as much as possible be general laws, like extending free speech to apply private spaces as well, forcing to put any software that can generate lock-in (e.g. because it implements a proprietary widely used API or manages a proprietary widely used file format) in the public domain and forcing to federate any service that benefits from network effects.

comment 8y ago · link · parent

Yeah, it seems like it should be possible to send a packet using a "firewall rule protocol" to the DoSing IP address, and have any non-malicious routers in between enact a rule that blocks traffic in the opposite direction (obviously there needs to be either spoofing prevention, or the packet must be signed with a certificate provided by the RIR to prove ownership of the source IP address).

Why not do this? Is it impossible to design it in a non-abusable way, or is there too much overhead to store and apply a possibly long list of arbitrary blocking rules?

comment 8y ago · link · parent

> C and C++ could literally become the downfall of Western civilization.

Rust coming to the rescue!

Seriously, I think peak insecure C/C++ has already passed, so if civilization hasn't fallen yet, it's not likely to fall for this reason.

comment 8y ago · link · parent

C++ templates are bad because they are untyped generics (e.g. C++ doesn't check that the key type for an hashmap is hashable, and instead you get a bunch of errors that there is no "hash" overload accepting certain arguments when you try to call a method on the hashmap).

C++ tried to add a type system for templates with "concepts" but it was scrapped.

Rust instead has properly typed generics instead using the trait system, resulting in proper static checking and proper error messages (although without higher kinded types and const generics currently, that C++ instead supports).

Rust also has a powerful macro system, which is unrelated to templates, although you can use them to have kinds of abstractions that the language doesn't support directly (like higher kinded types, const generic or abstracting over mutability), at the cost of having to explicitly perform instantiation, not having inference and having a higher cognitive burder.

comment 8y ago · link · parent

An analog connector doesn't necessarily seem perfect since sound can degrade undetectably.

I think what would be perfect would be something carrying both power and a lossless digital signal.

comment 8y ago · link · parent

Seems an interesting idea, but it's implemented in Python, which means it will never replace bash and probably not achieve any significant adoption unless they rewrite it in Rust first (which they should have written it in to begin with since they started in 2016).

The reasons for that are that shells must start very quickly (due to subshells, local ssh, etc.), be fast, have no complex dependencies since they are used to recover broken systems, be portable but also with full support for OS semantics and be written in a language that allows rapid development of robust software, none of which Python does well.

comment 8y ago · link · parent

Ofo and Mobike bikes use locks that block the wheel's rotation and can thus be parked anywhere.

Seems like forcing to use an existing bike rack would be a non-starter, since the whole point of dockless bike sharing is that you can just leave the bike in front of your destination regardless of what is there.

The "eyesore" factor is a trivial downside compared to the massive convenience of just being able to park the bike anywhere.

comment 8y ago · link · parent

But how does that work in practice?

Does their system determine those signals or are they fed to it as input?

How can it possibly provide a generic solution to "personalizing a message" that works across all apps and is not just something trivial like the example in the interview?

On the web the kinds of "personalization" I can think of are public account profiles, targeted advertisements, recommendation engines ("you may also like...", "products like this...", etc.), algorithmic newsfeeds and history-sensitive search. If their software does any of those, maybe they should just say what it does.

comment 8y ago · link · parent

After reading the article, I can't figure out what their product does at all in practice.

Apparently it turns "hello user" into "Hello Bob, it’s great to meet you on a wonderful December day" but it's not at all clear how that's packaged into something that's useful and non-trivial.

That seems like it could have been one of the main problems.

comment 8y ago · link · parent

Using multiple separate emitters and detectors it should be possible to determine how every point reflects light (i.e. sample its BRDF for a limited angular range and set of wavelengths), which should allow to distinguish at least between a limited set of materials such as snow, solid ice, liquid water and asphalt.

Cameras alone seems unsuitable, since it doesn't seem possible to make a camera-based system that works correctly all the time, ideally provably so, as required for a life-critical system.

comment 8y ago · link · parent

Why not just have a system that produces a full 3D model of the surroundings and their velocity (using something like doppler radar) and then just do a geometric computation in 4D spacetime to find out a path that doesn't intersect with the trajectory of anything? (assuming their speed is unchanged)

That should prevent all such trivial accidents and allows to actually mathematically prove that the software works, as it should be required for such a critical system.

Machine learning can be added for object detection to allow more sophisticated trajectory prediction.

comment 8y ago · link · parent

Aren't Reddit and in general forums much better at that?

With Facebook, you are using your true identity resulting in the pressure of having to post perfect content, you often have to post photos which are extremely time consuming to get right, the number of people who can "upvote" is very limited and the lack of a "downvote" button makes trolling for downvotes impossible.

On the other hand, a short but effective text post on Reddit or a forum can be done in a minute and potentially generate a huge flamewar and thousands of people upvoting or downvoting, and it doesn't matter if it turns out to be dumb or ineffective or otherwise bad.

And all you need is to just express the most controversial and hyperbolic take possible on a given existing subject, while on Facebook you'd need to come up with original content.

Finally, while Reddit might be accused of doing it intentionally for traffic, the web forums and newsgroups where this behavior started most definitely did not, so it's more of an intrinsic property of public one-to-many communication systems than something evil that Facebook came up with.

comment 8y ago · link · parent

Container and iterator code is not safe at all since there is no bounds checking by default and no protection against iterator invalidation, which can both cause writes to memory outside the intended object and thus a catastrophic outcome.

There is no safe subset of C/C++ unless you just don't use pointers or references at all (and refrain from using any library that is not safe which includes large parts of the standard library like all the containers), or you write it in Rust or an equivalent language with lifetimes and linear types and automatically translate it to C/C++ somehow.

comment 8y ago · link · parent

I think both "as" and using "transmute" for non-exceptional circumstances are mistakes in Rust.

There should instead be a bunch of type-specific cast operators that can check things like alignment and that what you intended to be a zero-extending integer cast is not in fact truncating to a smaller integer type, and so on.

It's not too late to deprecate "as" and discourage using "transmute" in favor of those.

1
394041
51