Thread: most line of codes for programming language

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    20

    most line of codes for programming language

    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!

  2. #2
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Lines of code is a worthless measurement of a language.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    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.

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    20
    Quote Originally Posted by swoopy View Post
    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?

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Quote Originally Posted by ok_good View Post
    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.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    No C specific questions in this post. Moved to GD.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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

  9. #9
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Quote Originally Posted by ok_good View Post
    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.
    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.

  10. #10
    Registered User
    Join Date
    Sep 2007
    Location
    Adelaide, Australia
    Posts
    9
    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.

  11. #11
    aoeuhtns
    Join Date
    Jul 2005
    Posts
    581
    Quote Originally Posted by paulstovell View Post
    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.
    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.

  12. #12
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    Try a forth or a lisp and see how small your programs can get
    .sect signature

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 04:13 PM
  2. adding line numbers and concatenating a filename
    By durrty in forum C Programming
    Replies: 25
    Last Post: 06-28-2008, 03:36 AM
  3. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM