Forcing code conventions

This is a discussion on Forcing code conventions within the Tech Board forums, part of the Community Boards category; I need to know, is there any way to *force* the code conventions to our students? Yeah, at least the ...

  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    Unhappy Forcing code conventions

    I need to know, is there any way to *force* the code conventions to our students?

    Yeah, at least the indentation.

    I'm teaching Java...
    You know that! There is a LOT of conventions in Java.



    I just don't get it. I told them by applying code conventions leads to a more readable code that will be useful to debugging.

    Since they are totally noob in programming, I think...

    Code:
    double result = price - ( price * ( discount / 100 ) );
    System.out.println( "Discount: " + result );
    Will be more readable than...
    Code:
    System.out.println("Discount: "+price-price*discount/100);
    And MOST of them wrote:
    Code:
    System.out.println("Discount:+nPrice-nPrice*nDiscount/100);
    ... which is leads to an error.
    Just GET it OFF out my mind!!

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    for students? simple - drop the final score - several points (out of 100) for each violation of the established coding-style. And tell them about this in advance - at the first class. And then only remind.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by vart View Post
    for students? simple - drop the final score - several points (out of 100) for each violation of the established coding-style. And tell them about this in advance - at the first class. And then only remind.
    That's what I'd do, but it would probably be good to check how your school feels about this. If they don't want you taking points off for that, maybe you could give bonus points for good style?
    Maybe also have a Wall of Shame for absolutely horrible code.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    An important part of being a programmer is being able to write readable code, so I don't see why it would be unfair to punish those who can't or refuse to follow simple instructions.

    In the professional world, I feel that people should be able to use text editors that are advanced enough to display code according to a certain convention, while writing it to file using another that is agreed upon. For example, the tabs vs spaces debate is easily settled this way.

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Of course if they don't follow your coding style, but another that is well-established they shouldn't be penalised.

  6. #6
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489
    Quote Originally Posted by cpjust View Post
    That's what I'd do, but it would probably be good to check how your school feels about this. If they don't want you taking points off for that, maybe you could give bonus points for good style?
    Maybe also have a Wall of Shame for absolutely horrible code.
    Thank you, this is a great idea.

    Since I would prefer positive motivations instead of negative one...
    Just GET it OFF out my mind!!

  7. #7
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    You know what I'd do? I'd kick all the students out the window and tell them to go learn C++
    Currently research OpenGL

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    >> I need to know, is there any way to *force* the code conventions to our students?

    My opinion? Let people code however they please. You can always format the code with software.
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    My opinion is that they should be penalized for not writing readable code.
    It doesn't matter HOW they do it, as long as the code they turn in is readable, whether that is by hand or by some software.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,602
    If you do it Sebastiani's way, they would merely be penalising themselves for not formatting code such that it is readable.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by Sebastiani View Post
    >> I need to know, is there any way to *force* the code conventions to our students?

    My opinion? Let people code however they please. You can always format the code with software.
    Whyyouareabsolutelyrightweshouldalsowriteusingnosp acesbecauseanartificiallyintelligentprogramcanalwa ysfigureoutwherethewordbreaksareandreinsertthespac es

    [Spaces inserted by the forum, not me]
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  12. #12
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Quote Originally Posted by brewbuck View Post
    Whyyouareabsolutelyrightweshouldalsowriteusingnosp acesbecauseanartificiallyintelligentprogramcanalwa ysfigureoutwherethewordbreaksareandreinsertthespac es

    [Spaces inserted by the forum, not me]
    I guess that means that the forum is not all that intelligent then.

  13. #13
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    >> It doesn't matter HOW they do it, as long as the code they turn in is readable, whether that is by hand or by some software.

    That seems fair. But it's just such a non-issue in my mind. Enforcing one particular style is just saying "I don't like looking at this, and I would rather force everyone else to type exactly as I would than to deal with it or else find a way to make it more pleasant for me to read.". Writing correct software should be the task - not formatting code to suit someones arbitrary tastes...

    >> Whyyouareabsolutelyrightweshouldalsowriteusingnosp ...

    Very cute. But you don't, of course, need artificial intellligence to format code.
    Last edited by Sebastiani; 03-26-2009 at 11:14 AM. Reason: Wording
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  14. #14
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by Sebastiani View Post
    That seems fair. But it's just such a non-issue in my mind. Enforcing one particular style is just saying "I don't like looking at this, and I would rather force everyone else to type exactly as I would than to deal with it or else find a way to make it more pleasant for me to read.". Writing correct software should be the task - not formatting code to suit someones arbitrary tastes...
    It's one thing to get up in arms about whether you put a spaces around an expression inside parentheses, or whether to align the '=' operator on ten consecutive lines of assignment... This is visual sugar.

    But then there are standards like "Always enclose conditionals inside curly braces even if they aren't necessary" or "Only write one statement per line" that I think go a long way to increasing readibility and maintainability without pandering to any one person's whimsical preferences.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  15. #15
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    But then where do you draw the line? I mean, look at audinue's example again. It's precisely that "whether you put a spaces around an expression inside parentheses" sort of thing. In fact, if you look at most coding guidelines, they're typically just as strict. My contention is that by enforcing such things, the author is either forced to convert all of their work after the fact, or else adopt the standard outright to save time. Neither make sense to me. I would prefer to give people full artistic license so that they can concentrate on more important things rather than to be so concerned with such trifling details.
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

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

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 04:39 PM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

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