Like Tree1Likes
  • 1 Post By phantomotap

Could you guys rate my code?

This is a discussion on Could you guys rate my code? within the C Programming forums, part of the General Programming Boards category; I have been trying to do some programming projects lately and am wondering if there is any critiquing that can ...

  1. #1
    C lover
    Join Date
    Oct 2007
    Location
    Virginia
    Posts
    265

    Could you guys rate my code?

    I have been trying to do some programming projects lately and am wondering if there is any critiquing that can be done on my code. While this was an extremely easy one, here is a WOL implementation by me. Could you guys tell me if there is stuff that I am doing wrong or could improve on?

    https://sourceforge.net/projects/wakemypc/

    Here is another (ARP spoofer)

    https://sourceforge.net/projects/ticklemyarp/

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,282
    O_o

    I've got to ding you for the weird, inconsistent vertical space. I'm not really talking about the style; I'm talking about how the style is seemingly applied without rhyme or reason.

    I realize these are simple applications not intended to be library code, but you should get into a habit of not deciding on total failure points on behalf of library code. In the real world, library code deciding on total failure points tends to be pointlessly brittle and unforgiving. Sure, maybe a write to a socket failing is a total failure point in this case, but for a different facility a socket write failure may be business as usual.

    You have a lot of comments that are entirely pointless due to being obvious or don't give any extra information.

    Consider these comments:

    Code:
    // Here, we begin building our ethernet header after obtaining the hardware address of our interface
    // Here, we begin building our ARP header
    // Here, we begine building the entire PDU by appending all headers
    You have used some good variables names, at least here, so to me, being aware of the API, the comments are extraneous; they are only fluff that breaks the code. From the other side, assuming I knew nothing of the API, the comments are insufficient to explain the "doings" of the code.

    If we toss the entirely toss the comments, we don't really lose anything of value, but we may do better by naming the process in any event.

    Code:
    if(buildARPHeader(&arp_header))
    {
        // ...
    }
    We could conditionally document `buildARPHeader' if we are doing something flaky, but the name alone offers some guidance to anyone trying to reason about the code. (What's an ARP header? I summon thee GOOGLE!)

    In other cases, you are using comments and notes to do versioning despite the fact you are using version control software; you don't need to keep those comments related to old problems, faulty code, or removed features around; you can just delete them, and your version control software will remember the code just in case you need it later.

    Soma
    Sebastiani likes this.

  3. #3
    C lover
    Join Date
    Oct 2007
    Location
    Virginia
    Posts
    265
    Thanks! The feedback is much appreciated. I'll keep this info in mind in future projects.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please rate at my code
    By Richardcavell in forum C Programming
    Replies: 16
    Last Post: 02-23-2013, 01:34 PM
  2. Rate this code? what could i have done better?
    By SuperMiguel in forum C Programming
    Replies: 23
    Last Post: 07-08-2012, 05:51 PM
  3. Rate my code
    By Baard in forum C++ Programming
    Replies: 2
    Last Post: 01-04-2004, 08:19 AM
  4. rate my code
    By kashifk in forum C Programming
    Replies: 1
    Last Post: 06-07-2003, 12:18 PM
  5. Tic Tac Toe -- Can you guys rate this please?
    By Estauns in forum Game Programming
    Replies: 2
    Last Post: 09-15-2001, 10:22 AM

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