HNHacker News
TopNewBestAskShowJobs

bstamour

303 karma · joined July 19, 2013

submissionscomments
bstamour··on You never did math in high school
And this is why I hate the term "mathematical induction". It's actually a form of deductive reasoning, not inductive reasoning.
bstamour··on C++ – From goto to std::transform
You can, but not with vector. Use valarray if you need to perform those kinds of computations.
bstamour··on Google Reader announced its shutdown exactly a year ago
Make sure to check out the android app too. It's cool to be able to read your self-hosted RSS feeds from your phone with zero hassle.
bstamour··on Guide to Advanced Programming in C
Is the phrase "locator value" defined by the C standard? I've never heard of it before. I always knew the 'l' in "lvalue" as meaning "this expression can appear on the left-hand side of an assignment operation."

EDIT: Found the answer (thanks, draft C11 standard.)

Section 6.3.2.1 contains the definition of lvalue, and it does not use the phrase "locator value" at all. However if you want to use it as a reminder that modifiable lvalues can be assigned to, then more power to ya :-)

I can't help it - I'm a sucker for standardese.

bstamour··on Hand Coding A Personal Website
Which goes right back to the original piece of advice: if you have access to the main apache config, put your changes there for performance reasons. Otherwise use .htaccess.
bstamour··on JavaScript: The Right Way
It was mentioned in a section about frameworks: http://jstherightway.org/#frameworks
bstamour··on Go by Example
I omitted the return type (which is allowed for lambdas in C++11, and now arbitrary functions (with some conditions) in C++14) because it was a 1-liner. The bool return type can be deduced by the compiler automatically (or else it would fail to compile) and by the human by the operator < in use, the fact that it's being passed to sort, etc.
bstamour··on Go by Example
More than that, actually. Because of argument dependent lookup, this will work for any container that has begin and end functions in the same namespace.
bstamour··on Go by Example
With C++14 this becomes

    sort(begin(vs), end(vs),
         [](auto const& l, auto const& r) { 
             return l.size() < r.size(); 
         });
Even simpler.
bstamour··on Taking PHP Seriously
After years of long build times, we C++ programmers basically have to become mental compilers in order to keep our productivity high.
bstamour··on Another go at Go failed
It allows you write code that works for multiple types. For example, consider the following function in C++:

    template <typename T>
    T min(T a, T b)
    {
        if (a < b)
            return a;
        else
            return b;
    }
This code works for any type T (ints, strings, floating point numbers) that can be compared with less-than. In a language like Go that does not support generics, you would have to write a min function for ints, a different min function for strings, etc.
bstamour··on Equational reasoning
Typically with monadic code, a function with an underscore at the end of its name discards it's effect. For example, the function mapM maps a function over a list, i.e.

    mapM :: Monad m => (a -> m b) -> [a] -> m [b]
it returns the result of the computation. But sometimes you want to iterate over a list but discard the result (say you're printing elements.) mapM_ discards the result:

    mapM_ :: Monad m => (a -> m b) -> [a] -> m ()
where () denotes a kind of "null type".

So if you want to store the results in a new list, you use mapM, but if you don't, and just want the "effects", you use mapM_.

Here's an example of each, using the IO monad. If I have a list of numbers, and I want to iterate through each one and prompt the user for a multiplier, I would write the code like this:

    main = do
        let numbers = [1.. 10]
        numbers' <- forM numbers $ \n -> do
            putStrLn "Enter a multiplier"
            a <- getLine
            return $ n * (read a :: Int)
where forM is just mapM with the arguments reversed to look more like a for-loop. Here I want the results of the computation, so I use forM. If, however I want to just print the numbers out, I'd use forM_

    main = do
        let numbers = [1.. 10]
        forM_ numbers $ \n -> do
            putStrLn (show n)
bstamour··on Obscure C++ Features
unique_ptr, the default smart pointer in C++ is no slower than direct pointer access. If you require data sharing, then shared_ptr offers you that feature at the cost of reference counting.
bstamour··on 25 years ago I hoped we would extend Emacs to do WYSIWG word processing
It closes for me fine. Just tested it to be sure.
bstamour··on Ask HN: Is C++ still worth learning?
I tend to write a lot of systems-level code, and the reason I choose C++ over C is because C++ gives me more power to build useful abstractions, while still letting me drop down to the bit-twiddling level if I need to. I do enjoy high level languages (in particular Haskell) but C++ is still the king on my servers.
bstamour··on Ask HN: Is C++ still worth learning?
Yes.

C++ is one of the few (maybe the only) languages that gives you enough high-level features to be productive, but doesn't do so at the expensive of ruthless runtime efficiency. If you need to squeeze every ounce of juice out of a machine, but still require the ability to create good abstractions, C++ is for you.

bstamour··on Bjarne Stroustrup Discusses C++
Correct. Even if you simply changed all of your dynamic arrays to std::vectors, the code you write is now simpler, easier to reason about, and pretty much memory leak-free.
bstamour··on Bjarne Stroustrup Discusses C++
It's not an optimization: it's move semantics. And it's default behaviour for any standards-conforming compiler. Moves can be optimized away still, but by default, returning a std::vector from a function is a constant-time operation.
bstamour··on C++ has become a scripting language
I wouldn't say it's gone into scripting language territory yet, but C++ is becoming a much simpler language for everyday programming. It's still a large complicated beast with sharp corners, but that only really occurs when you delve into library-writing territory. Everyday C++ code, when written in a modern style, is just cleaner, and C++14 is going to make it even better.
bstamour··on Go vs C++: Ray tracer (part 3)
Passing by value in C++ can offer speed increases when the function will be copying the object anyways, due to move semantics, constructor eliding, etc.
bstamour··on Apache Kills Off Its C++ Standard Library
Technically C doesn't have a standard ABI either. Compilers just tend to use similar symbol names.
← PreviousPage 5 of 5