Better HN
topnewbestaskshowjobs
Log inSign up

codebje

1,356 karma · joined Jun 19, 2017 (9y ago) · 591 submissions

Submissions

comment 8y ago · link · parent

The simplest way to think about memory is as a place where one executed instruction might write a value into a slot, and the next be able to read it.

In practice, things are more complicated. The next instruction might be from a different process, executing on a different (hyper)core. Or the next instruction executed might not be the next instruction in the program, because the CPU may be performing out-of-order execution. The CPU will have several layers of cache as well, and cache coherency protocols aren't always engaged.

In a language like C, you can declare a variable to be volatile. When the program is compiled, this causes the compiler to emit memory barrier instructions - these barriers force the CPU to do the work to ensure some semblance of sequential memory access is restored across the two sides of the barrier. These may be implicit, in the memory semantics of the language itself, or explicit operations in the language.

However, it's not easy to be sure that the barriers that end up in compiled and executed code actually provide the memory semantics that the language specified. This is exacerbated by the different semantics of different hardware architectures, and the overall complexity of the problem space.

The paper provides a way to address this problem by introducing an intermediate memory model, which is amenable to formal verification of compiler outcomes. They map this model to a handful of popular architectures, showing that the mappings are correct (more or less, that for all possible execution flows, the observable behaviour is the same). They also map from RC++ (repaired C++11, fixing an unsound semantics in concurrent memory access) and Promise ("the promising model") to the IMM.

Assuming the proofs are correct (a non-trivial assumption in this field, unfortunately) this offers a step forward in the process of formally verifying that the output of compilers actually behaves in the way that the program should, according to the programming language's semantics. There aren't many formally verified compilers around, and those that do exist are for subsets of languages we might use, limiting their applicability.

comment 8y ago · link · parent

You certainly cannot determine that two programs do or do not have the same behaviour in the general case.

In specific cases, the proofs can be pretty trivial:

https://tinyurl.com/ycx2245q - proof your two programs are different

https://tinyurl.com/y7lcv3re - proof 'y + x' is the same as Version 1.

These proofs weren't automatically discovered, though for such simple programs I'd expect an SMT solver to be able to find the proof or a counterexample easily enough.

But even proving they're the same value for all inputs isn't all that helpful, because of lazy Haskell code like:

    version 1:
    fib :: Int -> Int
    fib n = if n < 3 then 1 else fib (n - 2) + fib (n - 1)

    version 2:
    fib :: Int -> Int
    fib n = let fs = 1:1:zipWith (+) fs (tail fs) in fs !! n
They're (provably) the same for all (positive) input values, but if you call version 1 with n greater than, say, 35, you'll be waiting quite a while for an answer, while version 2 will be very snappy for the first few hundred thousand values of n, at least, after which the size of the answer will be a bottleneck.

If a library switched from the latter to the former, it'd have a good chance of breaking code.

While obviously exponential code is obviously exponential, this sort of behavioural change can show up in less obvious ways - a change in memory usage might blow your heap after a supposedly minor version change, eg.

In the end I don't think the value judgement of 'breaking' or even 'significant' is computable, and you'd need to rely on a human doing something that approximates to 'right' for your world view with their version numbering.

comment 8y ago · link · parent

I'd be horrified to discover an architecture that could be simplified by adding a blockchain to it.

comment 8y ago · link · parent

All monitoring has that problem :-) But if your rate of rate of change has been positive for some suitable amount of time for the context, it's worth waking a human up over it, because the amount of resource remaining is dwindling exponentially.

comment 8y ago · link · parent

Not offhand, sorry - I first encountered the notion at a conference some years back, but I've long since gotten out of operations so it's all a bit dusty for me now.

comment 8y ago · link · parent

Netflix carries a decent selection of kid's entertainment, where having a 10-minute show followed by the next episode automatically is useful.

On the Apple TV app, at least, the "Are you still watching" message is still there.

comment 8y ago · link · parent

Don't forget to alert when the double derivative of capacity growth is above a (very low!) threshold, that can catch an explosive problem far earlier than the 70% mark, by which time it might be growing at 5% per second.

comment 8y ago · link · parent

Climate change is a global problem, so you cannot move countries to escape it. The best you can plan for is to move to minimise its impact on you personally for as long as possible, which is fine if you only expect to live another 30-50 years and don't give a crap about the next generations.

comment 8y ago · link · parent

My brother-in-law prefers a mind-numbing job. He was a cashier for many years, until they promoted him to management and he had to have his mind "in the job" even outside of work hours, then switched to being a delivery driver, which is working out as his dream job - he can listen to sports broadcasts while driving, and when the deliveries are done, so is the job. No part of it comes home.

He has a degree in sports journalism, so he can be creative, and learn, and develop skills, it's that he doesn't want to do that for a job.

comment 8y ago · link · parent

Why do you have 100kloc operating directly on a single shared mutable structure in the first place? That sounds like an architectural choice that's going to make any sort of change far more difficult than it needs to be.

Avoiding abstraction is another form of premature optimisation.

comment 8y ago · link · parent

"A parser for a thing is a function from a string to a list of pairs of strings and things."

> Traditional parser combinators are just a recursive descent parser DSL, with a 1:1 translation between both representations.

Yes, exactly - a recursive descent _parser_ recognises a grammar and produces the parse result for the grammar. Parser combinators take little parsers and make bigger parsers.

combine-regexp doesn't make parsers, it makes regular expression grammars, that you then feed to some _other_ parser that actually does the parsing based on that grammar.

comment 8y ago · link · parent

I'll talk about this declaration only:

    data PreOrder : (a : Type) -> (a -> a -> Type) -> Type where
      PrO : {lte : a -> a -> Type} -- <=
          -> ((x : a) -> (y : a) -> (z : a) -> lte x y -> lte y z -> lte x z) 
             -- transitivity
          -> PreOrder a lte
This declares a function `PreOrder`, which when given some type called `a`, and some function from two `a`s to some other type, produces a type itself. The reason why we see `(a : Type)` to give a name to `a` is that the name is re-used in the second argument.

To produce a value, a constructor is defined `PrO`, with one _implicit_ argument `lte` of type `a -> a -> Type` (note that this `a` is not the same `a` in the type for `PreOrder`!) that can be inferred from the other arguments, and one other argument of a complex type we'll dig into in a moment. If you supply `PrO` with these two things, you will get back an inhabitant of type `PreOrder a lte` - the type that `PreOrder` promises to return when given two things. This is the same as `Maybe` in Haskell being a type-level function, and `Maybe Int` being a type, where `Just` is a constructor that can produce a `Maybe Int` given an `Int`, and `Nothing` is a constructor that can also produce a `Maybe Int` out of nowhere.

    ((x : a) -> (y : a) -> (z : a) -> lte x y -> lte y z -> lte x z)
This type is interesting because of the Curry-Howard correspondence, which basically says that types and propositions are the same thing, and expressions and proofs are the same thing. If you can show there exists some value of some type, you have proven the proposition the type represents. If you think about what `foo :: Int -> String` means in Haskell, you could turn it around to say "If there is an Int, then there is a String." Given some "proof" that `Int` is a non-empty type, that is, a value of type `Int`, can you prove that there exists some value of type `String`? Well, of course you can: `foo _ = "const"` is one such proof, as is `foo = show` or `foo x = if x < 10 then "less" else "greater"`.

In Idris, we can express much more interesting types, such that the existence of some expression of that type is non-trivial. The above type signature is best viewed IMO as a predicate:

    ∀x, y, z ∈ a. x ≤ y ∧ y ≤ z ⇒ x ≤ z
Remember that `a ⇒ b ⇒ c` is the same as `a ∧ b ⇒ c`, just curried, the type signature above is saying that given any x, y, z of type a, and some value indicating that `lte x y` is "true", and some value indicating that `lte y z` is "true", it can be shown that `lte x z` is "true" too. That is, a value of that type is a proof that `lte` is transitive.

Given some _user supplied_ proof of transitivity, and the implicit transitive operator, we have an inhabitant of the type `PreOrder a lte`.

This is dependently typed, because the _type_ of `lte x y` depends on the _value_ of `x` and `y`. When we say `lte : a -> a -> Type` we mean that `lte` is a function from two values of type `a` to some other type.

As an example, we could write `badlte : Int -> Int -> Type; badlte _ _ = Int`. This comparison operator simply ignores its arguments and says the Type of all such comparisons is always `Int`, which is the same as saying that all `Int`s are equivalent, because the binary relation is inhabited for every possible pair of `Int`s. We can prove transitivity with the lambda expression `\x,y,z,ltexy,lteyz => 42`, that is, given three values and two proofs that x <= y and y <= z, we can "prove" x <= z because we can show there's an inhabitant for the type of `Int`. We can make a preorder, and a totalorder, and sort using this order (the result is that any permutation of the input list is fine, because everything's equivalent for comparison).

As a more _interesting_ example, consider the definition of `LTE` for the type `Nat`:

    data LTE  : (n, m : Nat) -> Type where
      LTEZero : LTE Z    right
      LTESucc : LTE left right -> LTE (S left) (S right)
This is an inductive type definition that depends on the values given. `Z`, or zero, the base case of a `Nat`, is less than or equal to every other value, so we can use `right` as a placeholder variable. Given the proof that `left <= right`, we can also say that the successor of `left` (`S left`) is less than the successor of `right`. This is a bog standard inductive proof form, transposed to code. `LTE` becomes a function from two `Nat`s to a `Type` - but it's a partial function, or relation, because not every `Nat` pair produces a `Type`. If we want to prove that 2 is less than or equal to 3, that is, `LTE 2 3`, we can construct it inductively: `LTESucc (LTESucc LTEZero)`, that is, given `0 <= 1` we can show `1 <= 2` and from that `2 <= 3`. But there's no way to chain `LTESucc` and `LTEZero` together to wind up with `LTE 3 2`.

comment 8y ago · link · parent

I don't think I'd call that a parser combinator, it's a regex DSL - it's just a more verbose way of writing out a regular expression, with a 1:1 translation between the DSL and a regex.

comment 8y ago · link · parent

You're placing a heck of a lot of trust in a digital system if you're putting a significant (as in "I would hate to lose this") sum of money into it in the expectation it'll still be there in the future.

Even if we put aside the problem of unstable valuation, forks, and potential total collapse of cryptocurrencies, you're going to face the challenge of keeping a private key secure for however many years you plan to escrow the money.

Compared to creating a trust account, this is insanely risky - you'd have to be convinced that the legal and banking systems were facing imminent catastrophic collapse to think that's better than what we've got.

comment 8y ago · link · parent

Smartphones: "I want to search for something on the Internet when I'm not at home." It's a very simple problem statement, it's well solved by a smartphone, and it's a far superior solution than the pre-existing one, which was to find an Internet cafe or free wifi hotspot. This is borne out by smart phone adoption worldwide.

Meanwhile, bitcoin was never better than the existing alternatives of barter and foreign currency for dealing with a failing central currency. It's not got substantial traction as an electronic currency.

Bitcoin does solve one problem: "how can I rake money in from suckers when I'm providing them with nothing in return". It does this well. Tremendous amounts of money are going from "investors" to miners and people at the top of the pyramid. This can only continue so long as there's a growing base of new money coming in - but nothing of value is coming out, just the promise of more coming in later.

My opinion is that Bitcoin was originally a political statement or thought experiment in crypto-anarchy, with a poorly thought out economic model that actively discourages its use as a coin, and history continues to reinforce that opinion.

comment 8y ago · link · parent

The purpose of a type system is to allow the programmer to more fully express their intent in a way that allows static analysis to reject code which runs counter to that intent. Not to alter the compiled code.

That there's no difference between a const ptr and a ref at runtime is irrelevant, because there's a significant difference at compile time.

comment 8y ago · link · parent

> Matthew Iles, the chief executive of Civil, said that by selling crypto tokens masquerading as ownership stakes they could raise a large amount of capital without setting any expectation of returns.

It's just another coin capital scam. Launch a crypto coin, get suckers to buy it, go yacht shopping.

comment 8y ago · link · parent

> How do you synchronize multiple events? How do you handle partial system outages? What is the retry strategy for failed events and how do we handle inconsistent data?

Make an event sourcing system single threaded, and the problems of synchronisation don't exist. Make a "traditional" RDBM system distributed, and the problems of synchronisation exist.

If you weren't building a distributed (or parallelised) system to start with, why introduce it with event sourcing? If you were, how were you going to solve all those problems with a traditional RDBMS approach?

The solutions are more or less the same.

Perhaps "retry strategy for failed events" is new - how would you have handled a replicant failing in a distributed RDBMS application?

The data size issue in my experience pales in comparison to the problem of having the business ask questions you can't answer because you threw away data. How high is your transactional rate, anyway? Views shouldn't be a data size concern, as they should only contain the pertinent data. In many cases you should be able to hold views completely transiently in memory. It's relatively rare that a view is expensive to compute from an ordered history.

> I agree with Fowler - CQRS/ES is probably too complicated and you should avoid it unless you have a well described bounded domain that fits the model.

Given the model fits any domain in which things happen, this might not be the best way to determine if ES is appropriate - it's probably more along the lines of how important history is, how important flexibility for future use of data is, and how important time to market is. If we give up security to get a product out sooner, we would pretty quickly also give up a total history of the system, too.

There's also more than one way to skin this cat - you can use transaction scripting and log transactions; you can use database table level auditing; you can have a high level business intent audit log. Probably others. They all have complexities and drawbacks.

I don't personally find CQRS/ES particularly complicated, having worked with it a few times. I don't apply to every project, the same way I don't apply any of the other history mechanisms to every project, but I'll reach for it over those other mechanisms, because I prefer the costs of ES over the costs of those mechanisms.

comment 8y ago · link · parent

Side effects and non-determinism can break the relationship between action ("command") and event. You'd need to take care with things such as random number generation, to use a PRNG whose call sequence is determined only by the actions, and whose seeding is an action itself.

Side effects caused by action handlers are also something to beware - don't launch the missiles when you're replaying the past.

comment 8y ago · link · parent

If you just want to know a unique identifier for an entity holding INR, look at the extended delegated statistics data, published daily by each RIR recording an opaque, but stable, identifier for the holder of a resource block.

http://ftp.lacnic.net/pub/stats/lacnic/

https://ftp.arin.net/pub/stats/arin/

https://ftp.ripe.net/pub/stats/ripencc/

https://ftp.apnic.net/stats/apnic/

https://ftp.afrinic.net/pub/stats/afrinic/

comment 9y ago · link · parent

A maybe<T> in a language with halfway decent support for sum types is most likely a tagged pointer to a T, if it is reified at all.

A clever compiler is likely to do the same thing for a pair of (bool, T): represent the bool as a tag in the pointer, store the T. If the value is reified at all.

What new run-time failure modes do you get with optional? Is it just what happens when you blithely ignore the "nothing" possibility and attempt to extract the contained value "on faith" ?

1
1617181920