quick question about int main()

This is a discussion on quick question about int main() within the C Programming forums, part of the General Programming Boards category; hello guys, i have very quick question, i dont no might be very silly. is that true that if main ...

  1. #1
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682

    quick question about int main()

    hello guys,
    i have very quick question, i dont no might be very silly. is that true that if main fucntion too long it is a worst programming pratice. i havn't heard about this or read an any book. is that true if the main is too long is it worst programming practice. can any one direct me in right direction. for the proof

    thanks in adavance

    ssharish2005

  2. #2
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    If something is "too <adjective>" then it's bad by definition. How you judge it is quite subjective and depends on many things. I'd say that in general no function should be made very long, and main is no exception. If it makes sense to break it up into smaller functions, then do so.

  3. #3
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    thanks CWR for your reply, the reason why i asked this was my teacher argues with me saying that u'r is worst programme for just being my main a bit longer. she dont even bother about the other fucntion being longer. she just says that u'r main is long. no credits for that. even though program compiles fine with error or warnings and gives the output which was expected and moe user freindly.

    ssharish2005

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    In school, or in a company, you have to learn to play by their rules. If they want a short main, then give them one:
    Code:
    int main( void )
    {
        everything( );
        return 0;
    }
    Now just treat the function 'everything', like you'd normally treat main.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    it seems that i dont have any way to get the marks back. i dont have proof to argu with them.

    ssharish2005

  6. #6
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    No point in arguing. Your instructor is the boss and her opinion, unfortunately, is what counts. Function size is a style issue and totally open to opinion.

    Now if she claims
    Code:
    void main()
    gets()
    fflush(stdin)
    are good things, then you have a potential argument. There is a lot of 'proof' that these are wrong and/or bad.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    > is that true that if main fucntion too long it is a worst programming pratice.
    Only in the sense that it's bad for any function to be too long.

    Fair enough, a function which is just a big switch/case of many possible choices, where each choice results in a function call could be hundreds of lines long, but it would be totally obvious what was going on.

    But a single function playGameOfTicTacToeReadingUserInputAndChoosingComp uterMoves() would just be awfully bloated.

    If you think splitting a function would improve the clarity of the program, then you should probably do it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I need help with variables, please
    By JOCAAN in forum C++ Programming
    Replies: 39
    Last Post: 12-08-2007, 03:16 PM
  2. Debug Error Really Quick Question
    By GCNDoug in forum C Programming
    Replies: 1
    Last Post: 04-23-2007, 12:05 PM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. Converted from Dev-C++ 4 to Dev-C++ 5
    By Wraithan in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2005, 06:45 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21