> In C and C++, there's no such thing as an array Yes there is. `int a[10]` allocates 10 consecutive `int`s on the stack, and it's the only language construct to express that (with `alloca` but it's a builtin function).
The "C is Efficient" Language Fallacy (2006)
11–20 of 133 posts
Re: The "C is Efficient" Language Fallacy (2006)
#12While a lot of Scientific computing is done in FORTRAN, much of the lower-level `plumbing' is written in assembly, C or C++. C isn't an efficient language, C is just thin layer on top of assembly. You can write shit code in C, I know that from experience, but you can also write really fast code in C.
This is a pretty common fallacy. These days a C compiler does so much magic that calling it sugared assembly doesn't describe it accurately.
With a 1970's single pass compiler your argument may have been more true.
Re: The "C is Efficient" Language Fallacy (2006)
#13I was actually under the impression that Fortran was used simply because the experts (in this case in fluid dynamics) was familiar with Fortran. It was the language they learned and used while back at the university. At least this is the impression I got from working in the field. I never heard of anyone suggesting we should use Fortfran for performance reasons, instead there was an ongoing movement to evolve the cod…
Re: The "C is Efficient" Language Fallacy (2006)
#14Umm, yes C/C++ will not parallelize your code for you, whereas Language XYZ will. Im not sure how this is an argument against C/C++ being effective. C/C++ will not parallelize your code by design. It's was never meant to. I'd never blame my stick-shift car for not changing gears by itself - thats the first reason I didnt buy an automatic in the first place! If your matrix manupuilation code performance becomes an iss…
The idea is: if you use a tool that lets you describe your problem at a high level and let the computer worry about how to do the calculation efficiently, you'll beat your hand-rolled C++ every time. And, there is now the possibility of hiring a "Real Programmer" to hack your math library (Octave, Mathematica, Python + numpy, whatever), allowing you to delegate work. If every calculation was a brand new C++ program, you'd only be able to improve your application's performance by hacking on your application. Separating the problem description and the solution description allows the solution-finding code to be optimized without knowledge of the specific problem.
I think this approach scales to the work that practicing programmers, too. We don't see it a lot because writing tools is time consuming and we all have deadlines; so we pic k the "worse is better" solution and hard-code our applications in what amounts to glorified machine code.
Just because a practice is common doesn't mean it's a good idea.
Re: The "C is Efficient" Language Fallacy (2006)
#15While a lot of Scientific computing is done in FORTRAN, much of the lower-level `plumbing' is written in assembly, C or C++. C isn't an efficient language, C is just thin layer on top of assembly. You can write shit code in C, I know that from experience, but you can also write really fast code in C.
> C isn't an efficient language, C is just thin layer on top of assembly. This is a pretty common fallacy. These days a C compiler does so much magic that calling it sugared assembly doesn't describe it accurately. With a 1970's single pass compiler your argument may have been more true.
In the end, C has branching and memory access, and that's basically what our computers have too. The rest is details.
Re: The "C is Efficient" Language Fallacy (2006)
#16> In C and C++, there's no such thing as an array Yes there is. `int a[10]` allocates 10 consecutive `int`s on the stack, and it's the only language construct to express that (with `alloca` but it's a builtin function).
The OP wants to point out that C hasn't got first class arrays the same way that Fortran does. The C kind of arrays get passed to and from functions using naked pointers and that makes lots of compiler optimizations more difficult because of aliasing issues while a Fortran compiler knows that two arrays cannot alias (use overlapping memory areas). By adding a "restricted" declaration to your pointer types in function…
void f(int len){
int array[len];
printf("sizeof len: %zu\n", sizeof(array));
}
Yes, I was weirded out when I saw this for the first time. But C does in fact have arrays; they're just not very good arrays.Re: The "C is Efficient" Language Fallacy (2006)
#17Umm, yes C/C++ will not parallelize your code for you, whereas Language XYZ will. Im not sure how this is an argument against C/C++ being effective. C/C++ will not parallelize your code by design. It's was never meant to. I'd never blame my stick-shift car for not changing gears by itself - thats the first reason I didnt buy an automatic in the first place! If your matrix manupuilation code performance becomes an iss…
Should I happen to wander into a problem space that needs this stuff, my choice will be how many minutes to spend Googling for a decent free library, or whether to license a commercial one.
On the shoulders of giants...
Re: The "C is Efficient" Language Fallacy (2006)
#18People otherwise rightfully challenge his conclusions.
There's a funny comment there about matlab: "MATLAB struck me as being the wrong tool for every problem."
Re: The "C is Efficient" Language Fallacy (2006)
#19Earlier quoted context omitted.
> C isn't an efficient language, C is just thin layer on top of assembly. This is a pretty common fallacy. These days a C compiler does so much magic that calling it sugared assembly doesn't describe it accurately. With a 1970's single pass compiler your argument may have been more true.
Yes, but it would be just as easy to write an "assembly compiler" that did the same optimizations on your program text. C provides a layer above the machine that acts as we imagine a machine to work; the compiler adjusts our expectation to reality. In the end, C has branching and memory access, and that's basically what our computers have too. The rest is details.
While there are ways to optimize machine code without extra debug information, no, what you've said is not true. It is not nearly as easy to optimize machine code as it is to optimize C.
Re: The "C is Efficient" Language Fallacy (2006)
#20This is old (2006), and seems to base its argument around the problems with unrestricted pointers in C, that cause aliasing. As of C99, of course, C has the "restrict" keyword which allows pointers to explicitly be declared to not alias, thus enabling all these optimizations in C, too.