5,075 reputation
22437
bio website
location Munich, Germany
age 36
visits member for 4 years, 2 months
seen Apr 14 at 18:59

I work at a small mechanical engineering company, where I develop software and image processing algorithms for camera-based inspection machines.


Apr
14
comment Is it okay to have code smells if it admits an easier solution to another problem?
Sounds like you need an adapter class that provides a non-OO interface to your procedural code, so you can keep the rest of your code clean(er).
Apr
10
awarded  Good Question
Feb
21
awarded  Good Answer
Jan
24
awarded  Yearling
Dec
23
revised Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
added 2 characters in body
Dec
23
comment Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
@user31782: Depends, IIRC. float values can live in an FPU register - then there would be no instruction at all. The compiler just keeps track which value is stored in which register during compilation, and emits stuff like "add constant 1 to FP register X". Or it could live on the stack, if there are no free registers. Then there would be "increase stack pointer by 4" instruction, and the value would be "referenced" as something like "stack pointer - 4". But all these things only work if the sizes of all variables (before and after) on the stack are known at compile-time.
Dec
23
comment Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
@user31782: Machine instructions, as a rule, are very simple: Add two 32-bit integer registers. Load a memory address to a 16-bit integer register. Jump to an address. Also, there are no types: You can happily load a memory location that represents a 32bit float number into a 32bit integer register and do some arithmetic with it. (It just rarely makes sense.) So no, you can't emit machine code like that directly. You could write a compiler that does all those things with runtime checks and extra type data on the stack. But it wouldn't be a C compiler.
Dec
23
comment Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
@user31782: Like I said, might be possible for special cases. But take Func_i()+1: A typical CPU has several different "add" instructions, one for 32bit-integers, one for 16-bit integers, one for 32bit floats, and so on. The compiler has to know which one to emit, so it either has to know the types of both all subexpressions, or it has to decide which one to call at runtime (which is expensive).
Dec
23
comment Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
@user31782: If you write a compiler for a VM, like the java compiler, you can do all those things. But C (and C compilers) were designed to emit actual machine code, and there simply is no machine code instruction for "reserve memory for whatever type some function returns". There are instructions like "increment the stack pointer by [insert constant here]". You could emit code that explicitly handles different types (in C++, you can actually do stuff like that), but that would mean type checks at runtime, which costs performance - no real C programmer would want this.
Dec
23
comment Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
(Cont.) Also: What if you wrote printf(..., Func_i()+1); - the compiler has to know the type of Func_i, so it can decide if it should emit an add integer or an add float instruction. You might find some special cases where the compiler could go on without the type information, but the compiler has to work for all cases.
Dec
23
revised Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
Correction; Thanks Bart
Dec
23
comment Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
@user31782: No, because the emitted code doesn't contain any types; There are no real types in assembly code, that's why it's so fast. And also because not all types are treated the same: For example, an x86 CPU has a separate stack for floating point numbers and "ordinary" data. And pass-by-value structures are another beast entirely.
Dec
23
answered Why is *declaration* of data and functions necessary in C language, when the definition is written at the end of the source code?
Dec
22
comment Using single characters for variable names in loops/exceptions
@im_a_noob: Then you probably never had to debug somebody else's code that was littered with expressions like myArray[i][j] and myArray[j][i] (which one's the right one? i was the employee index and j the project index, right? Or was that the loop above?), or my favorite: myArray[l][I][1] (no, they're not all three the same character). Code like that probably started its life as a 1d-array with one loop variable, but it didn't stay that way...
Oct
28
comment Is it permissible to use explicit interface implementation to hide members in C#?
@Telastyn: If the contract included mutability, then why would the interface contain a IsReadOnly property?
Sep
24
awarded  Autobiographer
Sep
15
comment Why do some languages round to the nearest EVEN integer?
@Gusdor: That's exactly what I've read. I was hoping Ian might have found said evidence ;-)
Sep
15
comment Why do some languages round to the nearest EVEN integer?
@Ian: Do you have a source that clerks used banker's rounding before computers? AFAIK banks never used banker's rounding.
Jul
9
comment Why do some functional programming languages use a space for function application?
A few non-FP languages that allow function calls without parenthesis: Ruby, Visual Basic, Powershell
Jun
24
comment Is there a benefit in compiling your code as you go along?
On the other hand, compiling breaks my flow. It's often more important to get the high-level structure of the code right than catching every little syntax error.