Follow Slashdot stories on Twitter


Forgot your password?
Compare cell phone plans using Wirefly's innovative plan comparison tool ×

Comment Re:Readability wins every time (Score 1) 239

Speaking of readability, here's an entertaining one I've been seeing more of in C:

if (result == SUCCESS) versus if (SUCCESS == result)

The rationale behind the second is that you don't end up accidentally assigning SUCCESS to result (eg, if (result = SUCCESS)). But I know that I find it weird to look at it the other way around. I want to know if the result was successful, not if successful was the result. Maybe it's an english thing.

I know that Xcode has been putting up warnings/errors for code that does assignments in if-statements and saying that if you really want to do that, wrap it in an extra layer of parentheses (eg, if ((booleanResult = Do_Something()))). I'm not sure this is somehow more clear that you're doing the assignment...

In proper C++ this would be

if (bool booleanResult = Do_Something()) {

or more usefully

if (AClass foo = PrepareFoo()) { DoSomethingWith(foo); }

This does not generate those assignment warnings, is in the right order for readability and does not need obscure extra parens.

Comment Readability wins every time (Score 1) 239

In professional software development, the general idea is clear: if any non-functional change in a source code file makes it more readable and more maintainable, then it's good, and vice versa. You write the thing once and it has to be maintained for years. This is actually called code refactoring, which is part of several methodologies.

Code refactoring may mean either adding or deleting code. There ought to be a golden middle point somewhere where the code is neither too verbose nor too condensed.

There is a slight complication in that not every person agrees what is the most readable form for a program, but in general it's best to imagine that you may have a total autobiographical amnesia in the next day and still need to understand what the program does.

Comment Re:Missing features (Score 1) 286

So, memcpy() does not work in C++? Did not know that.

Or strcpy() for that matter? Ah: you want to imply that one should use std::string?

Sorry, regarding buffer overruns C++ is as vulnerable as C.

memcpy() and strcpy() are not found in proper C++ programs (there is no need for them).

Anyway, memcpy is not the cause for buffer overruns. Buffer overruns appear when two pieces of code get confused about what is the actual size of the buffer. In C++, the actual size is stored right there inside the buffer object (e.g. std::vector or std::string), so the probability of confusion is greatly reduced.

strcpy() is vulnerable because it relies on the buffer size stored somewhere else in addition to the buffer management (i.e. malloc()), and these two locations may get inconsistent and cause confusion and bugs. Luckily, there is about zero reason to use strcpy() in C++.

Of course one can compile what is basically C code by a C++ compiler, but this does not mean one could not do better in C++, or that C++ is somehow tainted by allowing C code. One can write buggy code in any language, writing buggy C code in C++ is just one easy way to do that.

Comment Re:Missing features (Score 1) 286

Nevermind managed execution to avoid buffer overruns and other "memtrashing" failures that have been a huge security clusterfuck over the last few decades...

I believe you have mixed up C++ with some other language. C++ does not have any such buffer overrun issues (unless you treat it as "C with classes", of course).

Submission + - Even Einstein doubted his gravitational waves (

Flash Modin writes: In 1936, twenty years after Albert Einstein introduced the concept, the great physicist took another look at his math and came to a surprising conclusion. “Together with a young collaborator, I arrived at the interesting result that gravitational waves do not exist, though they had been assumed a certainty to the first approximation,” he wrote in a letter to friend Max Born. Interestingly, his research denouncing gravitational waves was rejected by Physical Review Letters, the journal that just published proof of their existence. The story shows that even when Einstein's wrong, it's because he was already right the first time.

Comment Re:This is the least of the problems with SO. (Score 1) 303

I was having a debate with several high ranking programmers on SO about needing to mark an INT volatile or having to use Interlocked atomic writes to make sure the class variable gets flushed to memory after the method call finishes.

Indeed, there is no need for that. You need to sync only if something must get visible to another thread.

My argument is that unless the method discards the data or inlines the method call, the method has to eventually flush the data from registers back to memory before returning control.

As written, this statement seems indeed either insane or tautological. I am not surprised SO people were baffled.

Now that .Net code is on GitHub, it turns out Microsoft's own code for stuff like semaphores are written exactly the way I proposed.

A semaphore is a totally different thing than an ordinary user-defined class object.

Comment Re:Bring More Solutions than just One (Score 2) 74

Perhaps you could give an example of Open Source software you think needs a special class of user called "tinkerer"?

Try compiling three year old scientific software written in academia without either a programmer or a sysadmin (either should fulfill the role of "tinkering" with software).

I know the sentiment. The only thing worse than open-source software from academia is closed-source software from academia. We ended up putting it in a separate background process so when it crashes we can try to run it again a couple of times.

Making some program open-source does not magically increase its quality, and being in academia does not magically turn professional scholars into professional programmers. Nothing new here.

Comment Doctors are no different (Score 2) 397

In the article there are a lot of comparisons to doctors. Like, how you can become a doctor by spending 7 years in a medical school, etc, whereas in programming you do not have a clear path.

To my mind, this only proves that nobody really questions the qualification of the doctor. The patients are (or considered to be) not qualified to do that, so unless you are very bad, you can carry out a successful doctor career without really mastering the skills. I am sure in no way can all people become good doctors if they spend 7 years in medical schools, and the same applies to programmers. The only difference is that for a computer program it is much easier to see if it works and who is responsible when it doesn't.

Comment Re:Need more mature languages (Score 1) 232

C/C++ is not suitable for anything which should never crash or return random results due to memory corruption.

Yes, it's 2015 and so it would be appropriate to realize that C and C++ are two totally different languages (where one of those is just capable to seamlessly compile most of the code written for the other).

Submission + - NATO STRATCOM: Fearmongering on refugees spread by 'third parties' (

paavo512 writes: Upon examining the information flow about the refugees' way to Europe, the NATO Strategic Communications Center of Excellence (StratCom) has noticed that the information shows signs of having a coordinated strategy, leading to thoughts about third parties trying to divide European society.

"We have a hypothesis that there is a noticeable, coordinated strategy [of influencing the information flow] — we have started comparing the situation in Lithuania, Latvia and Finland, and there are many parallels," said Janis Sarts, head of the StratCom.

He added that he currently has no information about the possible perpetrators of these disruptions. "But it is obvious that this information is splitting society, and it is splitting Europe," he said.

Slashdot Top Deals

"Life begins when you can spend your spare time programming instead of watching television." -- Cal Keegan