Improving code

This is a discussion on Improving code within the C++ Programming forums, part of the General Programming Boards category; >No, it's redundant. So is return 0; But people still use it for clarity. It's a stylistic issue and if ...

  1. #16
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >No, it's redundant.
    So is

    return 0;

    But people still use it for clarity. It's a stylistic issue and if you wish to use it then that's fine. If you don't want to use it that's fine too.

    -Prelude
    My best code is written with the delete key.

  2. #17
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    Acually this is part of a science project and I am explaining the code line by line in my paper. Now when I got my mom to look over my explination (she doesnt know much about computers) she found a few things that she didn't understand so I fixed those and now she understands them enough to understand my code. But the part I am having a hard time explaining is the seeding part. Could anyone give me a little lamens terms explination on srand?

  3. #18
    Registered User
    Join Date
    Sep 2002
    Posts
    272
    But people still use it for clarity. It's a stylistic issue and if you wish to use it then that's fine. If you don't want to use it that's fine too.
    This does not make it necessary. People can use it if they like; but by not using it, it doesn't mean it has been 'forgotten'. Which was the main point.

    Also, how many lines of redundant code does 'return 0' justify?1, 2 or 100 maybe? Waldo2k2 has already given the impression that redundant code has lead to his confusion (that it was necessary).

    Could anyone give me a little lamens terms explination on srand?
    It will initialise a value used by rand to generate another value. As long as the value initialised by srand is different each time, rand will generate a different sequence of numbers.
    Joe

  4. #19
    _ Munkey01's Avatar
    Join Date
    Dec 2002
    Posts
    280
    Thanks Joe.

  5. #20
    Registered User
    Join Date
    Jan 2003
    Posts
    38
    IMO Im spontanious when I program It comes in 2000 or so line blasts I really have no time to comment or I loose my thought theres a half way ok reason....

  6. #21
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    well, what about after you finish coding, add some comments in to make code easier to read...

  7. #22
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    First you don't provide any error checking on "fstream fout("rand.txt");". I think from a stylistic point of view the program gets much cleaner if you explicitly open the file, write to it and close it in the end. Anyone who has seen the open will think it's naturall to close it.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Improving Code Interface
    By helloamuro in forum C Programming
    Replies: 20
    Last Post: 05-02-2008, 05:34 AM
  2. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 08:23 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 11:20 AM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

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