Thread: Need someone to criticize my codes.

  1. #1
    Registered User
    Join Date
    Nov 2012
    Location
    Brunei
    Posts
    77

    Need someone to criticize my codes.

    Please find any fault in my codes. No errors, everything works like how I wanted it to be, but I don't have real teachers to scold me for not doing what real programmer supposed to do so please look up for any programming mistakes I've made.

    Thanks.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    good luck getting anyone to download that zip file and look at it. it just reeks of danger. you should post your code inline using code tags.

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    On the naive approach, which is the one of me, I feel that downloading and open it is extra work which I wouldn't like to have.

    In case you don't know how to, do it like this : [code]/*your program*/[/code].
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    1. Why is int totalCandidates; public?

    2. Most of the stuff in Global.h should be read from a data file, or failing that, a std::string array in main.cpp. #defines are ugly in C++.
    All the other #defines should be like const int ScreenWidth = 1024;

    3. main is nearly 1000 lines long - awful.

    4. Indentation != scope
    Code:
                if(voteKeyFont.loadFromFile("monospa1.ttf"))
                        voteKey.setFont(voteKeyFont);
                        voteKey.setColor(sf::Color::Red);
                        voteKey.setPosition(67,574);
    
                        InstructText.setFont(voteKeyFont);
                        InstructText.setColor(sf::Color::White);
                        InstructText.setPosition(70,556);
    Despite the indentation, it's only the first line which is controlled by the if statement.

    5. Use arrays or vectors.
    bool b4(false) ; bool b5(false) ; bool b6(false) ; bool b7(false) ; bool b8(false) ;
    ...
    int voteCounts_boyPrez_nameA = 0;
    int voteCounts_boyPrez_nameB = 0;
    When you start adding suffixes to variables like foo1, foo2, foo3 or barA, barB, barC, then it's a sure sign
    you should be using an indexed container of some sort.

    It would also significantly reduce the following code to use a loop, rather than copy/pasting your way to nearly 1000 lines.

    6. More on arrays
    > else if (Event.type == Event.MouseButtonReleased && buttonSwitch == 4
    This gets copy/pasted all the way up to
    else if (Event.type == Event.MouseButtonReleased && buttonSwitch == 23
    which spans nearly 400 lines of code.

    If you can figure out how to factor this properly, you'll have much shorter code.

    7. bool Security::checkPassword(std::string password)
    What is the point of this?
    You need a better way of comparing with 1500 strings!

    Gave up.
    I think the only thing which needs to be said is lay off the copy/paste!

    As soon as you've pressed ctrl-C, you should be thinking "How to I make this a function?"
    Not immediately press ctrl-V and start hacking the difference over and over again.
    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.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    That's many the points I was considering making before I also decided that there was just too much to cover on my own.

    Don't add empty constructors, and don't provide a virtual destructor if you don't need to use the class polymorphically.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    Registered User
    Join Date
    Nov 2012
    Location
    Brunei
    Posts
    77
    Thanks guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pythagorean Theorem Program Comment, criticize, or whatever
    By Sshakey6791 in forum C++ Programming
    Replies: 7
    Last Post: 02-13-2009, 02:48 AM
  2. i want you to criticize my code, so i can improve it
    By joker_tony in forum C Programming
    Replies: 1
    Last Post: 03-29-2008, 02:25 PM
  3. Replies: 17
    Last Post: 03-27-2008, 09:40 PM
  4. Need the codes for the following.
    By nouneim in forum C++ Programming
    Replies: 8
    Last Post: 06-27-2004, 02:36 PM
  5. converting scan codes to ascii codes
    By stupid_mutt in forum C Programming
    Replies: 11
    Last Post: 01-25-2002, 04:06 PM