Like Tree1Likes
  • 1 Post By MK27

Old habits die hard

This is a discussion on Old habits die hard within the General Discussions forums, part of the Community Boards category; Even after writing ks of lines of Python over the course of 1+ ys, I still catch myself putting freaking ...

  1. #1
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,610

    Old habits die hard

    Even after writing ks of lines of Python over the course of 1+ ys, I still catch myself putting freaking semicolons on the end of lines, and the interpreter always has kittens over it.
    Anyone else get frustrated by cross-language habit bleeding - even when you are well aware of the right thing to (not) do?
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  2. #2
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    960
    Haha, I've been doing the opposite. Been forgetting semicolons at the end of lines in C++ code.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Doing this in C or js because I've been working in perl concurrently:

    Code:
    return whatever if somecondition;
    Doing this in perl because I've been working in C or js concurrently:

    Code:
    if (somecondition) return whatever;
    Perl requires braces around "return whatever" in this case.

    semi-colons
    In javascript, semi-colons are optional. To me, this is a dubious feature; ultimately it's not good because it makes the code whitespace dependant, when it is otherwise a common practice to compact js by ripping the whitespace out. But sometimes I feel I am being anal by using them, so I don't bother. Other times, I am proud to be anal. After a few revisions, I end up with code that has that is "somewhat dusted" with semi-colons.

    Another big one is the string concatenate operator, which is + in js but . in perl.

    I'm learning java now and I can see ! being an issue. It only applies to booleans:

    Code:
    error: bad operand type int for unary operator '!'
    Oh GFY. Zero is false. Everyone knows that.
    Last edited by MK27; 01-22-2012 at 02:31 PM.
    Epy likes this.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Taking a Java course, and the other day just couldn't figure out why my compiler was throwing a tantrum over the following code:
    Code:
    std::string[] myStrings;
    Had to look at it real hard before i realised the brackets go after the name in C++, whereas in Java they go after the type (Which makes far more sense to me anyways.)
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  5. #5
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,610
    Quote Originally Posted by MK27 View Post
    In javascript, semi-colons are optional. To me, this is a dubious feature; ultimately it's not good because it makes the code whitespace dependant, when it is otherwise a common practice to compact js by ripping the whitespace out.
    Yeah, that's exactly how I feel about it. As such, I almost always use them in JS.
    Quote Originally Posted by MK27 View Post
    Another big one is the string concatenate operator, which is + in js but . in perl.
    Surprisingly, I've not had much of an issue here. You cat with '+' in Python as well as JS, but '.' in PHP. But my favorite in that area, is _definitely_ shell script, where you just sit them next to each other with no operator.
    Quote Originally Posted by MK27 View Post
    Oh GFY. Zero is false. Everyone knows that.
    Sounds like your trying to make Java more C-like. In Java, aren't booleans suppose to be treated more separately from integers, in concept and code design? In some ways I think this was good decision, i mean, programming history aside, 0 is 0, false is false, they're not quite the same thing.
    Quote Originally Posted by Neo1 View Post
    Had to look at it real hard before i realised the brackets go after the name in C++, whereas in Java they go after the type (Which makes far more sense to me anyways.)
    I sort of agree, in fact, instead of declaring pointers with the "official" style, like "int *ptr", I put it on the other side of the whitespace, like "int* ptr". As you say, it makes more sense.
    However, I wouldn't completely agree on the array. Tn old C, arrays were _not_ first class in any way, so it would make sense to put it either way, and they chose after.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Yarin View Post
    In Java, aren't booleans suppose to be treated more separately from integers, in concept and code design?
    Evidently, just none of the material I read up to that point said this explicitly. Which makes a kind of sense. Why would there be any relationship between booleans and integers? I just assumed it in that regard.

    TBH I think booleans are near pointless sugar in any language; I'll use them just because that is convention. The idea that they are communicatively important implies that this could somehow make up for a complete lack of commentary or documentation. So rather than noting somewhere, "returns 1 if successful or 0 otherwise" (or as is common in the absence of booleans, the reverse), I just use boolean? Does that explain what true and false will indicate? In which case I either need to consult the documentation or scrutinize the code myself, meaning using a boolean instead of an int did not communicate much of value.

    OTOH, who doesn't like sugar? After all, you can't have too many keywords.

    In some ways I think this was good decision, i mean, programming history aside, 0 is 0, false is false, they're not quite the same thing.
    Agreed. I would imagine if a language like java were your first, it might seem counter-intuitive to think of zero (or any number) as false. Or true.

    Another whoops because of perl, involving semi-colons:

    Code:
    if (somecondition) { return x }
    Notice, no semi-colon, which is legal in perl if there is only one line inside the braces (but, you must use braces regardless). Since most other languages don't require braces there, where this comes up is simple methods:

    Code:
    int getX () { return X }
    Further encouraged by the fact that is okay in js...
    Last edited by MK27; 01-23-2012 at 06:32 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,673
    i++

    Not in python.

  8. #8
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    960
    Quote Originally Posted by whiteflags View Post
    i++

    Not in python.
    At least you have the += operator though. In MATLAB, a language solely for numerics, there's neither i++ or i += 1.

    Edit: They aren't in FORTRAN either.
    Last edited by Epy; 01-23-2012 at 06:49 AM.

  9. #9
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,610
    Yeah, not having ++ in Python isn't so bad, because it's mostly used in C(++) for iteration. And iteration is done differently in Python. And when you do need it, +=1 isn't so bad.

    Quote Originally Posted by Epy View Post
    At least you have the += operator though. In MATLAB, a language solely for numerics, there's neither i++ or i += 1.

    Edit: They aren't in FORTRAN either.
    I recently discovered that += isn't in QuakeC, either. Who in their right might would exclude such an essential operator from their language?
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  10. #10
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,673
    I thought this thread was about my habits. Even if you guys don't think it's bad, it still gets me. I have to think about it every time.

  11. #11
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Quote Originally Posted by Yarin View Post
    I recently discovered that += isn't in QuakeC, either. Who in their right might would exclude such an essential operator from their language?
    Lua has neither `++` nor `+=`. I was unreasonably upset about this.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  12. #12
    Registered User
    Join Date
    Jun 2005
    Posts
    6,266
    Fortran has neither. And that is a good thing, if you are a mathematician.
    Right 98% of the time, and don't care about the other 3%.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lone wolf c programming habits
    By stabu in forum C Programming
    Replies: 4
    Last Post: 08-07-2011, 04:57 AM
  2. Neurotic bodily habits when coding
    By Sharke in forum General Discussions
    Replies: 36
    Last Post: 06-22-2009, 10:53 AM
  3. Programming Habits
    By lehe in forum C++ Programming
    Replies: 5
    Last Post: 04-25-2009, 05:00 PM
  4. Bad coding habits
    By Magos in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-12-2005, 05:44 PM
  5. Professional Habits?
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 01-17-2003, 01:27 PM

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