HNHacker News
TopNewBestAskShowJobs

detrino

482 karma · joined July 15, 2013

chris@detrino.org
submissionscomments
detrino··on Ask HN: Inspiring female programming blogs?
This isn't a compile-a-list-for-me site, it's fair game to question whether restricting yourself to female only blogs is the best course of action here.
detrino··on What if anything have we learned from C++? [video]
You cannot implement cache efficient data structures using void pointers.
detrino··on Code Golf at Google
There was a proposal[1][2] for C++17 to allow:

    for (e : c)
which would be equivalent to:

    for (auto &&e : c)
Gcc implements this when compiling with -std=c++1z. My understanding is that it was rejected by the committee.

[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n385...

[2] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n399...

detrino··on Ask HN: Does such a programming language exist?
C# is gonna be your best bet.
detrino··on How Google Sparsehash achieves two bits of overhead per entry using sparsetable
Sorry, it's early, I was thinking about cuckoo hashing.
detrino··on How Google Sparsehash achieves two bits of overhead per entry using sparsetable
My understanding is that Robin Hood hashing has worse performance than linear probing due to greater cache misses.

If you are looking for low memory overhead ordered sets/maps, then B-Trees can provide that.

detrino··on Nearly All Binary Searches and Mergesorts are Broken (2006)
Are you overloading "expense" here to mean something other than runtime performance?
detrino··on When ‘int’ is the new ‘short’
size_t's raison d'etre is portability, you should be using it for things that are indexes/sizes into memory. FWIW, I don't have the karma to downvote.
detrino··on When ‘int’ is the new ‘short’
People downvote incorrect information all the time.
detrino··on When ‘int’ is the new ‘short’
Your rant against size_t and portability is misplaced as size_t increases portability when used appropriately.
detrino··on When ‘int’ is the new ‘short’
I am addressing the specific example given by the Google style guide. The code for counting down using a signed integer as they do has more corner cases than the while loop I have shown. Using their way, you have to remember to subtract 1 from the size at the start and then use >= in the loop conditional. My way is just the inverse of what you do while counting up.

It's also worth pointing out the style of loop they give can't be used at all if you are counting down iterators or pointers instead of numbers.

detrino··on When ‘int’ is the new ‘short’
I disagree that a signed type is the correct solution to that, rather you need a while loop:

  std::size_t i = foo.size();
  while (i != 0) {
    --i;
    ...
  }
detrino··on Object Theft Etiquette in C++: methods with a side of &&
This kind of interface has precedent: http://en.cppreference.com/w/cpp/experimental/optional/opera...
detrino··on Object Theft Etiquette in C++: methods with a side of &&
You misunderstand the point of reference-to-const in C++. It is just a const view of an object, it makes no promises about the object itself. For functions returning a reference-to-const, the value of the contract is for the function, not the caller. For functions accepting reference-to-const parameters, the value of the contract is for the caller, not the function.
detrino··on Object Theft Etiquette in C++: methods with a side of &&
The standard defines preconditions when talking about what operations on valid on its containers. std::string::clear() has no preconditions so it is valid to call on a moved from object and then you can be sure of its state.
detrino··on Things Rust shipped without
I wonder if this is really faster than just writing it as a loop.
detrino··on Things Rust shipped without
I don't see how this helps here, unless you intend to call the closure several times per case.
detrino··on Plex: a parser and lexer generator as a Rust syntax extension
Unless you are Greg Ewing, you should probably choose a new name.
detrino··on The Ubiquitous B-Tree (1979) [pdf]
Because when you split the root, it can only have 2 children.
detrino··on The Ubiquitous B-Tree (1979) [pdf]
Cache coherency is something else.

But ya, B-Trees will (sometimes significantly) outperform BSTs for small keys because they will have fewer cache misses. Also interesting is that the idea that RB-Trees are faster than AVL trees for insert/delete may be outdated as well. I've seen benchmarks of AVL trees beating std::set in both libstdc++ and libc++ for both of those operations. Again this is probably due to less cache misses.

My B-Tree story is actually a B+Tree story. B-Trees (and B+Trees) can can actually be used for more than just ordered sets/maps, I've implemented a C++ sequence container[1] that allows O(log n) random access insertion and deletion. It is _much_ faster than a similar container[2] implemented using AVL trees, but at the cost of iterator stability.

[1] https://github.com/det/segmented_tree_seq

[2] http://avl-array.sourceforge.net

detrino··on How Rust Achieves Thread Safety
Relaxed access of atomics performs no synchronization.
detrino··on How Rust Achieves Thread Safety
From tsan documentation: "A data race occurs when two threads access the same variable concurrently and at least one of the accesses is write"
detrino··on How Rust Achieves Thread Safety
From wikipedia:

    A race condition or race hazard is the behavior of an
    electronic, software or other system where the output is
    dependent on the sequence or timing of other
    uncontrollable events.
Example: https://gist.github.com/anonymous/eb72f1091bd1592df552

Output:

    $ for i in {0..10000}; do ./race; done | sort | uniq
    0
    1
detrino··on How Rust Achieves Thread Safety
Rust doesn't get to redefine "data race".
detrino··on How Rust Achieves Thread Safety
That's not true, Rust permits opt-in data races in safe code.
detrino··on Exceptional results: error handling in C# and Rust
Both Rust and C# provide throwing/failing interfaces for parsing, it's just that Rust's is written:

    let foo: u32 = "3".parse().unwrap();
and C#'s is written:

    var foo = uint.Parse("3");
Both require familiarity with the stdlib (Parse throws, TryParse doesn't, unwrap fails).

I agree that TryParse is worse than Rust's ADT approach, but that's a different issue, much like nullable references. The author is asserting that results are superior to exceptions and I am asserting that no, that is just a bad application of exceptions. Additionally, I am asserting that without exceptions, you limit what programmers are willing to propagate through their interfaces because errors become viral.

detrino··on Exceptional results: error handling in C# and Rust
Overcommit is just one configuration on Linux, it is a good default, but there are domains where you would disable it.

How is Parse any less explicit than unwrap ?

detrino··on Exceptional results: error handling in C# and Rust
I'm not glossing over it, I said that this is better written using results.

Complaining about the existence of Parse is like complaining about the existence of unwrap in Rust.

C++ (another systems language) is probably a better comparison for out of memory.

detrino··on Exceptional results: error handling in C# and Rust
Both exceptions and results are important for software architecture. The lack of the former leads to an oversimplification of interfaces in languages with only the latter. The author hit upon an example that is probably better written using results. But guess what? A C# programmer would write it that way too. See the TryParse methods found all over the C# standard library. On the other hand, what would a Rust programmer do to handle an out of memory situation? That would be too pervasive with the result approach so it has been culled from all interfaces. Also, nullable reference types are a separate issue.
detrino··on Inverting Binary Trees Considered Harmful
I don't think its clear at this point.
← PreviousPage 3 of 9Next →