HNHacker News
TopNewBestAskShowJobs

bnegreve

2,040 karma · joined January 4, 2011

submissionscomments
bnegreve··on Facebook's std::vector optimization
If you need to realloc a fixed size array, souldn't you use a std::vector instead?
bnegreve··on Elvish – An experimental Unix shell in Go
Ah yes indeed [1], I didn't know.

[1] http://en.wikipedia.org/wiki/IEEE_floating_point#Exception_h...

bnegreve··on Elvish – An experimental Unix shell in Go
I really like in-shell floating point operations. But this:

    > / 1 0
   +Inf
Is not the correct answer - even as a limit - since the limit of 1 / x (when x -> 0) can be +Inf or -Inf.
bnegreve··on How recursion got into programming: a comedy of errors
> Stack overflows seems opaque to me, while preallocating memory (malloc) has mechanism to signal failures for proper handling.

On Linux (and probably on other OSs) it's not easy to detect that the system is out heap memory because of lazy memory allocation policies.

Physical memory is not allocated when you call malloc() but when you first read or write the corresponding memory page.

Because of this, malloc() does not necessarily return NULL even if there isn't enough memory available on the system at the time you called malloc(). But if the system is still out of memory when your first access the allocated memory, your program will crash with a segfault.

So in absence of extra precaution, using heap memory isn't any safer than using stack memory.

bnegreve··on I've never seen a language's style guide recommend avoiding comments before
I realize this, but the article doesn't provide any clear definition of what actually is a bad comment. It only gives trivial examples of bad comments such as "increment a by one".

Since I don't think anyone here would argue that "increment a by one" is a useful comment, the part about duplicate/obvious comments isn't adding much to the discussion about the usefulness of comments.

Nevertheless, it's true that comments cannot be checked by the compiler, and that's a more interesting point, I think.

bnegreve··on I've never seen a language's style guide recommend avoiding comments before
This is not convincing to me because the examples are trivial:

    -- swap the elements of a pair
    swap :: (a,b) -> (b,a)
Yes this is redundant.

    let b=a+1   -- add one to 'a'
Yes this is also redundant

Does it mean that every piece of code can be expressed as clearly as in a one-line comment in natural language? I don't think so.

bnegreve··on HTML Canvas in the terminal
With aalib, you can even render videos on the terminal. E.g. on Linux:

    mplayer -vo aa video.mpg
Will use aalib to render video.mpg inside the current terminal/console. The quality is not great though: http://www.youtube.com/watch?v=O5JLjfCi0mw (Here with Vlc.)
bnegreve··on The UN thinks we could hit peak births in 2014
Check again, the peak is clearly at 2014 (each tic is 5 years)
bnegreve··on Floppy Bird: A Flappy Bird clone in 16-bit x86 assembly
> I meant "hardware access ([when the particular thing is] not exposed by other languages ...

Ok, I agree.

>Like I said, you cannot quickly do better than a modern compiler, and a compiler does it very, very quick.

I'm not sure what you mean by "quickly" but this submission proves that it can be done in reasonable time. And if you look at the code (for example here:  https://github.com/icebreaker/floppybird/blob/master/src/gam...), it's obvious that you cannot produce anything nearly as compact and efficient with a compiler.

So, claiming that assembly is still a language of choice nowadays was maybe exaggerated, nevertheless it's nice to remember that no matter how good they are, compilers come with a cost. If you need some evidence simply compare the submitted code with any code produced with a compiler.

bnegreve··on Floppy Bird: A Flappy Bird clone in 16-bit x86 assembly
> Hardware access (not exposed by other languages), speed, and possibly executable size are the practical reasons one would write in assembly.

This is a bit misleading, accesses to physical memory, disks and to other devices are usually protected by the operating system, not by the language. So you don't have direct hardware access because you program in assembly, but because you run a program without the control of an operating system. This can be done in assembly, but also in C or in any other language that can generate native code.

The only thing that you can do with assembly and that you can't really do with higher level language like C is accessing processor specific registers/instruction sets (e.g. SSE). And this is typically done using inline assembly snippets, as there is no reason to write a whole program in assembly when you only need to optimize a single function.

So I would say that having better hardware access is not a good reason to write an entire program in assembly.

On the other hand, building small, standalone executable file that use very little (stack) memory is still relevant for programs that run on very small (usually embedded) hardware. Especially when they need to run fast or to have low energy consumption. So speed and memory usage are still pretty good reasons to use assembly :)

bnegreve··on No crankshaft, no problem: Toyota's free piston engine is brilliant
> Seems like needing the piston to change directions is a waste of momentum.

It's not, in a closed system momentum is conserved [1] so without friction, a free engine would rotate forever.

Also there is not conceptual difference between an engine and a ball sniping in a donut. In both case, the piston or the ball have to change direction (the piston has to change direction more abruptly though)

[1] http://en.wikipedia.org/wiki/Momentum#Conservation

bnegreve··on Why I can’t stop using Vim
I use a text editor because using a text editor that you've mastered is pleasant. (I'm an Emacs user fwiw.)

I think we should stop trying to rationalize this choice.

Or rather, we should realize that we like text editors because we went through a long training and acquired complex skills which are fun to put in practice. Being a power user of Emacs or Vim is is satisfying, the same way mastering a video game is satisfying.

bnegreve··on Lisp implementation in sed
> sed is provably Turing complete

This submission is in itself, an elegant proof that sed is Turing complete.

bnegreve··on Undefined behavior can result in time travel
> If you know that p is not NULL then why are you checking for it?

These dummy tests can happen if you have a lot of macros for example. It still valid C code as long as p is not NULL. A compiler generating an error on this particular example wouldn't be a correct C compiler.

The compiler can reject this code if it can prove that p can be NULL, but in many case that's impossible at compile time.

I agree that a warning would be nice though.

edit: clarity.

bnegreve··on Undefined behavior can result in time travel
> In the printf example, the compiler could trivially emit an error saying "NULL check on p after dereference of p"

If you know that p is not NULL, the code is just fine. The compiler has to compile it.

bnegreve··on African firm is selling pepper-spray bullet firing drones
> All solutions are technical.

What does this mean? When employees are on strike, one solution is to increase wages. How is this a technical solution?

bnegreve··on Astronomers may have identified what may be the smallest known star
> J0523 has the lowest possible mass for fusion, so it’s taking its sweet time using up its hydrogen fuel. [...] It could literally still be fusing merrily (though feebly) away even a trillion years from now!

The good thing about astronomy is that there's always something impressive.

bnegreve··on Lossless audio compression with libpng
Here's the answer (from AceJohnny2's comment): https://news.ycombinator.com/item?id=7893243
bnegreve··on Raptor robot runs at 28.58 mph, faster than any human [video]
> These are really impressive from a mechanical engineering point of view

It's not just a mechanical engineering problem, the dynamic of the system is way too complex to be modeled with a simple formula. There's a lot of AI/machine learning involved in robotics. That's hard with or without external power supply.

bnegreve··on Amazon Loses Bid For .Amazon Domain
It doesn't sound right, with this logic DNS would be useless. Even if I use search engine to reach most websites, the domain name remains an effective way to distinguish legitimate websites from illegitimate ones.
bnegreve··on Searching 20 GB/sec: Systems Engineering Before Algorithms
One can name thousands of examples (literally) where the simple code doesn't beat the fancy algorithm. What's your point?
bnegreve··on Did removing lead from petrol spark a decline in crime?
> I am terribly sorry for the ad-hominem,

That was a bit cheap but ok. Let me add more.

Here is the same data that I have reploted

http://imgur.com/fdtc0tH

This chart is less biased (y axis starts at 0) and the correlation is less obvious.

The correlation is actually -0.6557, which is significant but probably not as high as you would expect from the first chart. But ok the correlation between game software revenue and juvenile violence is probably here (we're talking about ~20 data points...). To go further and conclude anything about violent games, you would need at least the proportion of violent games among games, we don't have it here.

Here's the data that I've extracted from the pixel position. It's not 100% accurate, but it should be good enough.

    1990 412.999995
    1991 430.999995
    1992 448.999995
    1993 469.999995
    1994 495.49999995 
    1995 487.99999995 3.2		  
    1996 432.49999995 3.67407407407407
    1997 384.49999995 3.74179894179894
    1998 355.99999995 4.55449735449735
    1999 322.99999995 5.43492063492064
    2000 298.99999995 5.5026455026455 
    2001 291.49999995 5.90899470899471
    2002 276.49999995 6.92486772486772
    2003 285.49999995 7.06031746031746
    2004 270.49999995 7.33121693121693
    2005 279.49999995 6.92486772486772
    2006 297.49999995 7.26349206349206
    2007 286.99999995 9.43068783068783
    2008 288.49999995 11.6656084656085
    2009 261.49999995 16
bnegreve··on Did removing lead from petrol spark a decline in crime?
> We can conclude, from the fact that we did not find a positive correlation, that the hypothesis is false.

We could if it was a lab experiment where the only factor that varies would be the popularity of violent video games. But it's not.

It's entirely plausible the the increase of home entertainment has indeed reduced the rate of juvenile crimes. (kids don't stay in the street any more). Yet it doesn't say much about how violent games induce violent behaviours.

bnegreve··on Did removing lead from petrol spark a decline in crime?
> You offered a suggestion that was based on a false premise.

I haven't, I am not taf2. I was just saying that this inverse correlation that you see may be due to other factors or may not even be statistically significant. We're missing a lot of data here (e.g. how does the juvenile crimes rate fluctuates prior to 1990).

bnegreve··on Did removing lead from petrol spark a decline in crime?
> If there is a correlation there, it is negative

Yes that's my main point: this plot does not prove the correlation.

If you look at a bigger picture e.g. (maybe here [1], altough it's not technically the same metric) there was a peak around 94. The peak and the relative low value before the peak cannot be explained by video games.

And that my second point: no one ever claimed that violence is only caused by video games. Clearly the blue curve is under the influence of (many) other factors, so it's very hard to determine whether there is a correlation without knowing these other factors.

But let me say it once again, it's a possibility that video games reduce violence. I am simply saying that if think this is the case because of this plot, you're probably biased.

[1] http://www.eji.org/files/juv%20murder%20rate%20drop_0.jpg

bnegreve··on Did removing lead from petrol spark a decline in crime?
I genuinely don't know whether violent video games implies more violent behaviour, but I am 100% sure that this chart doesn't prove or disprove anything.
bnegreve··on Programming paradigms that change how you think about coding
Just to clarify, it wasn't obvious to me before I read the part of the article that I have quoted.

But I still think that functional programming goes beyond simply specifying "what you want". Take the problem of sorting an array for example. A declarative specification of the sorting problem would be: Given an array T, compute a permutation of T such that for all i, it's true that T[i] < T[i+1] (some languages support this type of specification e.g. [1]).

Clearly here, you don't describe "how to do it". In functional programming you can't do this, you have to explain "how", implementing quicksort, for example.

[1] http://www.minizinc.org/

bnegreve··on Programming paradigms that change how you think about coding
According to Wikipedia, functional programming is an example of declarative programming [1], which is mentioned in the article.

This is not immediately obvious to me, here's why (from the same wikipedia article [1]):

While functional languages typically do appear to specify "how", a compiler for a purely functional programming language is free to extensively rewrite the operational behavior of a function, so long as the same result is returned for the same inputs. This can be used to, for example, make a function compute its result in parallel, or to perform substantial optimizations (such as deforestation) that a compiler may not be able to safely apply to a language with side effects.

[1] http://en.wikipedia.org/wiki/Declarative_programming

bnegreve··on A talking multimeter
So you need the same number of samples whether you use 80+12 or 90+2.
bnegreve··on A talking multimeter
The fact that you can "factorize" 92 into 4 x 20 + 12, means you need less samples, not more. Of course it also requires more and specialized logic in your program, which is the real problem.
← PreviousPage 15 of 25Next →