PDA

View Full Version : most line of codes for programming language



ok_good
09-13-2007, 09:46 PM
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!

Wraithan
09-13-2007, 10:12 PM
Lines of code is a worthless measurement of a language.

swoopy
09-13-2007, 10:34 PM
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.

ok_good
09-13-2007, 10:49 PM
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.

how about between C and Java? Is it Java take less code than C?

swoopy
09-13-2007, 11:23 PM
how about between C and Java? Is it Java take less code than C?I would say C and Java would be about equal. Java might take less lines if you need something with a GUI, or are doing a lot of string processing. But my guess is the two languages would be about equal in lines of code.

VirtualAce
09-13-2007, 11:44 PM
No C specific questions in this post. Moved to GD.

matsp
09-14-2007, 02:17 AM
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

CornedBee
09-14-2007, 03:08 AM
Java comes with a far larger default library, which greatly contributes to concise code. Of course, you can use libraries with C too.

Rashakil Fol
09-14-2007, 07:56 PM
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!

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.

paulstovell
09-20-2007, 08:47 AM
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.

Rashakil Fol
09-20-2007, 09:53 AM
If you compare languages you'll find they're all about the same.

You must not be comparing the same languages I've been comparing.

ggs
09-22-2007, 01:50 AM
Try a forth or a lisp and see how small your programs can get