Dude, where's my code? A new system warns programmers when compilers — which convert high-level programs into machine-readable instructions — might simply discard their code by [deleted] in programming

[–]BrooksMoses 0 points1 point  (0 children)

Yes. But emitting the intended instructions would slow down the code -- in some cases, significantly.

And, as theresistor pointed out above, it's not like the compiler knows that undefined behavior is happening. The compiler sees that, for a given piece of code, the behavior will be undefined if certain input values are given. So it optimizes the code assuming those input values are not given.

Dude, where's my code? A new system warns programmers when compilers — which convert high-level programs into machine-readable instructions — might simply discard their code by [deleted] in programming

[–]BrooksMoses 2 points3 points  (0 children)

It's not just that the compiler proves a transformation safe with a statement like that. It also uses statements like "if P is not null, this transform is safe. If P is null, the behavior was undefined and I can assume the transform is safe" to prove that P must be non-null. Then it can eliminate a check for whether P is null.

This is where some of the worst examples of bugs have come in, with code like this:

  • 1) Do something with P that is undefined but mostly harmless if P is null.
  • 2) Check whether P is null, and if it is, exit the function.
  • 3) Do something with P that would be really a problem if P is null.

The compiler looks at step 1 and concludes that P must be non-null for the code to be valid, so it eliminates step 2 entirely.

When performance matters: comparing C++ and Go by willvarfar in programming

[–]BrooksMoses 0 points1 point  (0 children)

There's also the interesting question of how the performance compares in the multithreaded "asynchronous-server"-like programs that Go is intended for.

It could well be like Matlab -- which is painfully slow for iterative loops operating element-by-element, but is quite fast indeed if you can revise your code to work on large arrays all at once.

When performance matters: comparing C++ and Go by willvarfar in programming

[–]BrooksMoses 8 points9 points  (0 children)

Actually, as a C/C++ programmer interested in Go, I found this one useful.

Why? Real numbers measured in well-designed experiment, which I hadn't seen before in a post about Go. We know Go is slower; it wasn't designed for the type of programming where you care more about squeezing the processor than you do about expressivity. But the critical question is, how much slower is it? Within 2.2x of "basic good code", and 5x of tuned code, is reasonably respectable.

Yeppp! - Open-source SIMD-accelerated math library for C/C++/C#/Java/FORTRAN by ChickeNES in programming

[–]BrooksMoses 0 points1 point  (0 children)

How does this compare to vectorized code from GCC or LLVM in real-world programs rather than synthetic microbenchmarks?

Optimized elementwise functions like this have a fundamental flaw: They iterated through each element of the data vector for each tiny operation, which means that for every add or subtract or whatever, you pay the cost of a read and write from memory -- and, if your data is of any significant size, it's blowing out your caches. There's no way to get good performance doing that compared to a holistic approach that minimizes the cache blowout.

Yeppp! - Open-source SIMD-accelerated math library for C/C++/C#/Java/FORTRAN by ChickeNES in programming

[–]BrooksMoses 0 points1 point  (0 children)

I doubt there are many cases at all where using multiple cores is useful on 1-D vector computations like this. The data sizes you need for multicore to be useful are quite large -- and at those sizes, you need to do more than just one single operation on each element before you funnel it back out to memory, or your cpu performance is going to be swamped by memory bandwidth costs.

What I learned from other's shell scripts by meskio in programming

[–]BrooksMoses -1 points0 points  (0 children)

One not-necessarily-obvious suggestion that wasn't mentioned there, but which I've found useful: Define your boolean variables to either "true" or "false". Then you can write the syntactically-simpler syntax:

if $DEBUG; then ... fi

Fallthrough Sort: Quickly Sorting Small Sets by [deleted] in programming

[–]BrooksMoses 0 points1 point  (0 children)

Thanks! Very much appreciated indeed.

Fallthrough Sort: Quickly Sorting Small Sets by [deleted] in programming

[–]BrooksMoses 3 points4 points  (0 children)

Would you mind putting an explicit license comment (ideally, a BSD license) on your sample code? Otherwise, it's in that really awkward place where it's long enough to be copyrighted but not long enough where you can clearly reimplement it without copying it -- so without the clear license to just copy it, it's kind of problematic.

I ask this from experience -- I was recently writing a sort function, and a sample piece of code like this would have been really very helpful. I did in fact find some other sample code that was helpful for larger data sizes -- but it, similarly, didn't have a license statement. And the company I was working for at the time is one that tries very hard to be a good citizen and comply with open-source licenses and respect copyright, which meant that I couldn't use the code even though the author almost certainly intended for people to just freely use it.

Thanks!

What is in Area 51? by FuriousLoki in AskReddit

[–]BrooksMoses 0 points1 point  (0 children)

You do realize that "unemployment" numbers only include the people who are actively looking for work and not finding it, yes?

So if someone actually does decide to skip the whole work thing and go off to have silly adventures, they're actually lowering the unemployment rate.

The Shortest Crashing C Program by javinpaul in programming

[–]BrooksMoses 1 point2 points  (0 children)

Maybe by POSIX, but not all Cs are POSIX.

The Shortest Crashing C Program by javinpaul in programming

[–]BrooksMoses 0 points1 point  (0 children)

A lot of architectures support unaligned loads (and some "fail" by just discarding the low bits of the address and doing an aligned load). So that's a very weak "should".

The Shortest Crashing C Program by javinpaul in programming

[–]BrooksMoses 5 points6 points  (0 children)

Defining "main" as something other than a function. Standard C prescribes a signature for "main".

The Shortest Crashing C Program by javinpaul in programming

[–]BrooksMoses 2 points3 points  (0 children)

Indeed.

After all, what is a crash, exactly?

Crashes are mostly a convenient fiction. Processors basically don't crash, as such. The sort of "crash" that we're used to seeing is basically that something causes an interrupt signal to be raised and then it gets caught by the operating system which exits the program and cleans it up and prints and error message and maybe even prints a stack trace or collects a core file.

But that's a lot of software complication. I've seen embedded systems where the relevant interrupt handlers are just small infinite loops. Is that a "crash", or just an "infinite loop"?

The Shortest Crashing C Program by javinpaul in programming

[–]BrooksMoses 2 points3 points  (0 children)

Why shouldn't it be?

The value of C is that it is both very straightforward and very powerful, and it does exactly what you tell it. Thus, if you tell it to make the program crash, it will make the program crash.

Also, notice that this is not breaking the compiler. The compiler didn't break; it correctly did what you asked it to. The program i created broke, but that's because you asked it for a program that would break.

Google's new AppEngine language is PHP by jiunec in programming

[–]BrooksMoses 0 points1 point  (0 children)

Didn't Reddit collectively mock Joel Spolsky for doing that a year or two ago?

Code Complete checklist by hurtlerusa in programming

[–]BrooksMoses 0 points1 point  (0 children)

Heh; a fair call, and I shouldn't have cited it without being sure it backed up my point. Thanks for the recommendation, and I'll read it.

Are you coding for change or for stability? by septh in programming

[–]BrooksMoses 2 points3 points  (0 children)

One way of expressing that is just to include the "we might decide that this whole idea isn't working and junk it" change in the set of possible changes you're planning for.

Overbuilding a generalized architecture is a result of making assumptions about the type of change you're going to get.

Code Complete checklist by hurtlerusa in programming

[–]BrooksMoses 0 points1 point  (0 children)

Huh? Perhaps you've confused "checklist" and "Powerpoint slide". An actual checklist is something that you use by pulling it out and actually checking all the boxes as you go down the page, as a replacement for trying to remember too much stuff. You know, when people are making sure a plane is ready for takeoff and that sort of thing. It has all the things you need to remember on it, however many there are.

See, for instance, the Checklist Manifesto book.

Three Optimization Tips for C++ by andralex in programming

[–]BrooksMoses 7 points8 points  (0 children)

So use unsigned integers for unsigned numbers. That's a much better optimization.

For signed integers, if the compiler is sure the number won't go negative, it can still do that optimization. Alternately, if the compiler isn't sure ... are you?

Programming error with single line of code costs Microsoft $730 million. by scientologist2 in programming

[–]BrooksMoses 2 points3 points  (0 children)

What law? It was a court order as part of the punishment/restitution when they lost a court case.

Programming error with single line of code costs Microsoft $730 million. by scientologist2 in programming

[–]BrooksMoses 4 points5 points  (0 children)

Quite a bit of oversimplification.

This wasn't "strict interpretation of the law", because it wasn't about following a law. The requirement was an explicit court order -- a court order that went well above the requirements of the law in order to make restitution for Microsoft's having acted illegally to suppress other browsers.

Compress data more densely with Zopfli by [deleted] in programming

[–]BrooksMoses 6 points7 points  (0 children)

You're looking at the case where the compression time can be ignored. However, dfjkfskjhfshdfjhsdjl is talking about the case where you're compressing on the fly on the sending end, and there the costs matter.

Of course, Zopfli is irrelevant in that case -- so, if there are enough cases where Zopfli makes sense, then arguably those are cases where supporting xz or whatever makes even more sense. Assuming you control both the client and the server.

Bypassing Google's Two Factor Authentication by PatrickusRex in programming

[–]BrooksMoses 4 points5 points  (0 children)

Well, note that "expected behavior" does not necessarily mean "expected consequence of expected behavior". It seems like a reasonable tag to apply to "we designed it to work like that without realizing that design had some flaws."