130 reputation
5
bio website
location Sweden
age 29
visits member for 3 years, 7 months
seen Nov 12 at 21:22

Software Engineer from Lund


Sep
24
awarded  Autobiographer
Jul
21
comment When I test out the difference in time between shifting and multiplying in C, there is no difference. Why?
@NicholasFolk Depends on what you're doing. As always, you should profile before doing optimizations, but one area where these types of optimizations can have huge effects is in image processing. Doing a couple of multiplications for each pixel in a large image can take a lot of time even on fast computers. Converting the multiplications to shifts and additions is a pretty standard way of speeding up image processing.
May
7
comment Writing in C for Performance?
This should really be the accepted answer. It explains why statements like "C is faster than C++" exist. C can be faster or slower than C++, but it is usually a lot easier to figure out why a specific piece of C code is fast/slow, which usually also makes it easier to optimize.
Feb
13
comment What is the benefit of having the assignment operator return a value?
+1 for bringing up a = b = c which the other answers do not really bring up.
Feb
5
comment Why does automated testing keep failing in my company?
I have also never worked in a company where full blown automated testing has worked for long. Just recently read "How Google Tests Software" though which seems to suggest that it is possible to get it to work even in a very large company. It requires a lot of work though, and may require continuous integration to get it to stick.
Jan
25
comment How do we make unit tests run fast?
+1: A further improvement would be to modularize the tests. If a specific module/file has not changed since the last run, there is no reason to re-run the tests that are responsible for testing it. Sort of like a makefile not recompiling everything just because one file has changed. This may require some work but will probably give you cleaner tests as well.
Jan
25
comment Why does it matter that HTML and CSS are not programming languages?
+1: Joel Spolsky has an interesting blog post that takes up the problem with function vs flashy GUI. Especially the hazards of showing a 100% finished and very flashy GUI when the functionality is not in place. A good read if you havent read it. joelonsoftware.com/articles/fog0000000356.html
Jan
25
comment I've been told that Exceptions should only be used in exceptional cases. How do I know if my case is exceptional?
+1: Exactly what I was going to answer. Use it when it simplifies the code. Exceptions can give much clearer code where you do not have to bother checking return values on every level in the call-stack. (Like everything else though, if used the wrong way it can make your code a horrible mess.)
Dec
20
comment Maintenance wise, is `else while` without intervening braces considered safe?
Good example. What a horrible way to write it.
Dec
11
comment Why do operating systems do low level stuff in C and C++? Why not just C++?
+1: I can usually beat the compiler in performance when it comes to writing assembly and it is a LOT easier to predict how the compiler will translate C into assembly compared to C++.
Oct
25
comment Is this a decent use-case for goto in C?
@KevinCathcart: Thanks!
Oct
24
comment What did programmers do before variable scope, where everything is global?
+1: When writing assembly I usually face some of the same problems in that if I name the registers, the names are global (I face the added problem that even if I create more names, I don't get more registers, but that's not relevant here). Having a few registers dedicated for temporary values really helps keeping down the number of variables created which makes it easier to keep everything in your head. Documenting which variables each function will use (most important is which it will modify) helps getting the global picture right.
Oct
22
comment Is this a decent use-case for goto in C?
The link seems to be dead (which is a shame since I would like to read the full discussion). Good answer nonetheless.
Oct
3
comment Why don't computers store decimal numbers as a second whole number?
@han: Depends on the size of the number you want to store. Floats will (roughly) give you the same precision no matter how large or small the number is while fixed point will only give you full precision if the number you wish to store fits perfectly into its range.
Aug
28
comment Why do we have to use break in switch
Google Go does the same thing IIRC (allowing fallthrough if explicitly specified).
Aug
17
comment Should I take care of race conditions which almost certainly has no chance of occuring?
+1: I would say that the consequences are probably what you should be analyzing and not the probability of it occuring. If the consequences don't matter, you might not have to handle the race condition EVEN if it is very common.
Aug
3
comment What backs up the claim that C++ can be faster than a JVM or CLR with JIT?
Good answer but one minor point: "C++ templates give you both (at the cost of longer compile times.)" I would also add at the cost of larger program size. Might not always be a problem, but if developing for mobile devices, it definitely can be.
Jul
14
comment How does learning assembly aid in programming?
I don't agree. If you have extensive knowledge about a certain algorithm and a good grasp of the hardware, it is usually possible to create assembly code that is better optimized than what the compiler can create since it has to play it safe. Knowing roughly how your code is translated into assembly also helps when doing optimizations.
Jul
14
awarded  Critic
Jun
14
awarded  Commentator