Hi:
I have a simple question that which programming language likely takes the most lines of code between Java, C and MIPS assembly language? Thanks!
Hi:
I have a simple question that which programming language likely takes the most lines of code between Java, C and MIPS assembly language? Thanks!
Lines of code is a worthless measurement of a language.
Well generally higher level languages take less lines of code than lower level languages. So the first step would be to order those three from higher level to lower level. Once this is done, the answer will be obvious.
On average, a line of C will generate around 4 instructions - this is of course not PRECISE, but it's a rough estimate that will be right for most C-code (assuming a reasonable compiler with some level of optimisation - if the compiler is really pessimal, then the result may be closer to 10 or 20 instructions).
Going by this, and if you don't count comments and other "empty" space, you'd expect the assembly code to be about 4x the number of lines compared to C.
As to Java vs. C, it depends very much on what you want to achieve, but a fair assumption would be that Java is slightly shorter than C - but not by a huge margin. There are almost certainly some cases where Java is longer, and other cases where Java is MUCH shorter - that's because the language has functions that are more suitable to do the same thing.
[Of course, C & Java can be written in very compact manner, compressing what most of us would use 3-5 lines to do into a single line - but this is not using "good style"]
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Java comes with a far larger default library, which greatly contributes to concise code. Of course, you can use libraries with C too.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
I'd guess MIPS would take the most, then C, then Java. At first I thought Java might take more than C, because it takes up space with all its class declaration business. But then if you consider that C has declarations too, it's not really that much longer. The main advantage Java has over C as far as SLOC goes is memory management. Either C code will take more lines for that purpose, or the design will be convoluted and restricted in ways due to the way manual memory management makes a real hassle of communicating information between different parts of a program. Neither C nor Java have real support for any other things that drastically reduce the lines of code or the complicatedness of code, since they're both nothing more than portable assembly languages (one having garbage collection), so Java ekes out a victory here. I'm assuming that all programs in this thought experiment have equal libraries.
I don't really know anything about MIPS assembly. You could make an assembly language with a macro system that gives you more powers of abstraction than Java gives, and you'd end up being able to write programs with fewer SLOC.
There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.
If you compare languages you'll find they're all about the same. The real comparison is in frameworks. For example, simply showing a Window in C using pure Win32 would take at least a hundred lines of code. The same thing in .NET or Java might be just a dozen lines of code. However, in C, you could make use of MFC, which might reduce it to a dozen lines as well.
First pick the problem space that you're working in, then the frameworks available. Languages are really an afterthought.
There are 10 types of people in this world, those who cringed when reading the beginning of this sentence and those who salivated to how superior they are for understanding something as simple as binary.
Try a forth or a lisp and see how small your programs can get
.sect signature