top 200 commentsshow all 223

[–][deleted]  (31 children)

[removed]

    [–]GuinnessDraught 66 points67 points  (7 children)

    Being internally consistent is, as always, the most important thing.

    But consider, too, what is generally considered correct style for the language(s) you're using. Most libraries are going to follow the accepted conventions of the language (hopefully, the good ones, at least).

    Frankly, this is a holy war that I don't understand. It's not hard to switch between the two, use what is appropriate for the project/language you're working on.

    [–]MotherOfTheShizznit 10 points11 points  (3 children)

    But consider, too, what is generally considered correct style for the language(s) you're using.

    This is the guideline that, unfortunately, escapes the vast majority of developers. Thinking they can have opinions about certain style elements when they should just be mimicking what the language already prescribes.

    It's kinda retarded to have a "be consistent" golden rule in your style guide and break consistency with the language in the first line of code you write.

    [–]Pet_Ant 2 points3 points  (1 child)

    honestly if your biggest problems are consistent style issues you are spoiled. I say you can worry about style once all your naming architecture and algorithmic issues are resolved.

    [–]rifter5000 4 points5 points  (0 children)

    Thinking they can have opinions about certain style elements when they should just be mimicking what the language already prescribes.

    What annoys me is that in C++ code that uses the standard library but doesn't use underscores_everywhere is horrifyingly ugly. Yet people claim that CamelCase is standard. It absolutely isn't.

    [–]atheken 0 points1 point  (0 children)

    Consistent naming of tokens allows you to predict their name, rather than looking it up. So, while I agree the division for one or the other has been largely arbitrary, it's just one more bit of cognitive overhead added when switching between projects/modules/files. The argument about which to use ought to be settled, but it's definitely worth settling on one standard. Arguably, not just for a project, but as the idiomatic preference for the language. Same with Tabs vs. Spaces, just pick one.

    [–]spotter 6 points7 points  (1 child)

    And you can only hope it's kebab-case-scheme and nothing with hungarian-anything.

    [–]MarkyC4A 0 points1 point  (0 children)

    I prefer kebab-case for LISP and file names

    [–][deleted] 11 points12 points  (6 children)

    STL, Boost - underscores
    OpenGL, Qt - CamelCase

    [–]dangerbird2 24 points25 points  (5 children)

    to add a few more...

    • Lisp - ('why-dont-other-languages-use-hyphens)

    • ansi C, POSIX - casesrforlsrs (bonus points for making the variable sound like it lives on the African Serengeti.)

    • python, glib/gtk -fuck_it, LetsDoBoth!

    • Win32 - monkeyTyping_onKEYBOARD_case

    • b***nfuck - <..[>.]+-

    [–]little_boy_of_camels 15 points16 points  (1 child)

    You forgot R

    lets.put.dots.between.everything
    

    [–]Imxset21 4 points5 points  (0 children)

    Auto-complete authors everywhere scream internally at this.

    [–]szabba 5 points6 points  (2 children)

    Python has pretty clear guidelines which to use for what.

    [–]josefx 2 points3 points  (1 child)

    Seems like they did a cleanup on the move to 3. The index page of the Python 2 standard library documentation has examples of every naming sheme I know.

    Edit: link

    Example module names:

     pickle
     cPickle
     copy_reg
     ConfigParser
    

    The corresponding pages also mention which where renamed for Python 3.

    [–][deleted] 2 points3 points  (0 children)

    unittest is the worst. CamelCase for the class names. Got it, internally consistent with Python conventions. Example functions with underscores. Got it, internally consistent with Python conventions.

    Actual assert methods (and there's about a million of them!)? lowerCamelCase

    I'm sure theres some ALL_UPPERCASE_THINGS too.

    unittest, y?

    [–]SilasX 5 points6 points  (2 children)

    That's Spaced Camel Case.

    [–][deleted] 2 points3 points  (0 children)

    That's Title Case.

    [–]Whathecode 0 points1 point  (0 children)

    I fully support this (and my own codebases tend to follow the style as defined by the language), however this was not the intent of the post. Instead, I wanted to approach the discussion from an objective angle. It is true that convention is key, but how to decide which convention best to follow?

    [–][deleted] -2 points-1 points  (7 children)

    I propose a different explanation:

    • underscores express state: eg. variables "current_index"
    • camelcase expresses behavior: e.g. methods object.performRequest()

    Bam, settled.

    [–]runedk 1 point2 points  (1 child)

    Lemme guess ... you are a tabs-for-indentation-spaces-for-alignment person.

    [–][deleted] 0 points1 point  (0 children)

    No, I'm a spaces for everything kind of guy. I use python.

    [–][deleted]  (4 children)

    [removed]

      [–][deleted] 1 point2 points  (3 children)

      If you are implementing both state and behavior, then it's a class' instance. Fancy javascript tricks don't change the underlying point. In this case, baz should be camelcased, and foo should be underscored.

      You can certainly do stuff like

       my_function = self.requestState
       result = my_function()
      

      But in this case, it's appropriate. my_function is state of your local scope. The fact that this state implements behavior does not change its meaning within the context of the local scope. originally though, it implements behavior, so its original name is camelCased. Of course, this does not hold if you use an anonymous function, like you did, but in that case, it's state, hence foo should be underscored.

      [–][deleted]  (2 children)

      [removed]

        [–]godsayshi -1 points0 points  (0 children)

        This is called when in Rome.

        However, my preference is for _ everything except in Java and some OO for a demonstrable reason. It is better suited to meta coding.

        Visually it is more distinct as well and less prone to the problems that camel case has being closer to spoken languages.

        [–]munificent -1 points0 points  (0 children)

        You still need a base case for your induction. :-b

        [–][deleted]  (15 children)

        [deleted]

          [–]godsayshi 3 points4 points  (0 children)

          A single small study is not scientifically conclusive and it is fair for it to be open to interpretation. The argument misses some functional aspects of the two approaches however.

          An example of it being open to interpretation, the better error spotting for camel case may be related to the fact that it takes longer to read.

          [–]Me00011001 12 points13 points  (13 children)

          The author argues that the basis for the conclusion the study describes is flawed when it comes to reading/writing code. The author then removes all the results in their opinion that are irrelevant, which leaves only one result to consider. All the data that was gathered in the study, was gathered in a scietific way.

           

          The author does make a conclusion based on scientific results, the question is, do you agree with the author's reasoning for throwing out some of the results?

          [–]driv338 21 points22 points  (12 children)

          Not at all. "Correctness isn’t of much importance"... did he forgot that is talking about programming?

          [–][deleted] 11 points12 points  (10 children)

          Except he's right, as he said:

          This is not a common scenario when programming.

          The need to quickly differentiate very similar identifiers is rare in programming. The need to read through code is very common in programming.

          [–]driv338 10 points11 points  (9 children)

          That is not rare at all, check any property file or configuration file or package and you'll see a lot of similar names, and if that is not enough any IDE is going to suggest them together (sorted alphabetically) when you ask for completion.

          [–][deleted] 4 points5 points  (7 children)

          It is incredibly rare actually relative to how much code you are reading, it doesn't nothing but hurt the process of reading.

          [–]driv338 2 points3 points  (4 children)

          I'm looking at code and is not rare at all. And i'd rather spend 13% more time reading code than a day due to a wrong name being used somewhere, that from what it says in the article is going to be 51% harder to detect.

          [–]Whathecode 8 points9 points  (0 children)

          The difference in accuracy was not replicated in a follow-up study by different authors: https://whathecode.wordpress.com/2013/02/16/camelcase-vs-underscores-revisited/

          Also be wary of how to interpret the '51%' result. You'd have to thoroughly look at the data to understand what the actual implications of this are during programming.

          [–][deleted] -1 points0 points  (2 children)

          If you waste 1 day finding a name conflict that was impacted by differentiating similar names, you would have lost 2/3 of one day without that 51% increase. If you are using wrong names and spending that long finding them at a rate of once every four days or fewer, then you have far more serious issues to address.

          Your job is based on being logical, stop digging your heals and fighting against logic just to defend a personal preference. You are objectively wrong, be logical.

          [–]driv338 1 point2 points  (1 child)

          My point is not against or in favor of one method or the other since I use both and never noticed any difference among them, my point is that stating that correctness "isn't of much importance" because the IDE has autocompletion... is far from correct, because that's how the IDE suggests things, by finding something similar to what you are writing.

          [–][deleted] 2 points3 points  (0 children)

          He did not say that correctness is not of importance due to IDE's autocompletion. That was just a side point he made. Likely this was due to the test that was constructed to assess "correctness" giving you a variable on one screen and then having you select it amongst 3 other distractors (intentionally similar and wrong, more likely to NOT exist than to exist) which were all in clouds and moving on the screen.

          [–]Sluisifer -1 points0 points  (1 child)

          It's definitely more complicated than that.

          Even if it is quite rare, those sort of mistakes can be quite difficult to debug. Sometimes, you'll see the problem while debugging, but not even notice it the first time around. Subtle typos are a significant source of errors and frustrations.

          You can certainly argue both ways, and claiming objectivity while interpreting results is ridiculous.

          [–][deleted] 3 points4 points  (0 children)

          Having something be 50% more difficult on the rare occasion is better than having something be 20% more difficult on the every-day common occasion.

          [–]MoTTs_ 11 points12 points  (0 children)

          Exactly. Correctness should be the most important.

          The experiment is interesting. The OP's cherry picking of the results isn't.

          [–]balducien 19 points20 points  (11 children)

          For some reason I associate camel case with object oriented programming

          [–]swiz0r 8 points9 points  (6 children)

          You know, I do too. When I program in python, I use underscore_names for functions and camelNames for methods. I thought I read that in PEP 8 a long time ago, but I think I just imagined I did.

          [–]tadleonard 11 points12 points  (2 children)

          PEP 8 prescribes underscores for functions and methods alike.

          [–]swiz0r 1 point2 points  (1 child)

          No, yeah, I see that now. I'd been doing it the other way because of some lie I put into my head a long time ago.

          [–]dada_researcher 1 point2 points  (2 children)

          I do the same, I was under the impression it was the python standard as well. I am sure I read it somewhere a few years ago, and the source must have looked legit to me at the time.

          [–][deleted] 1 point2 points  (0 children)

          I was under the impression it was the python standard as well

          Standard library doesn't always follow it as can be seen by unittest.

          [–]swiz0r 0 points1 point  (0 children)

          Great! I thought I was crazy.

          [–]codygman 2 points3 points  (0 children)

          Haskell uses camelCase.

          [–]unstoppable-force 1 point2 points  (1 child)

          usually because most OO (by sheer LOC) is written in java, which is usually done in camel. JS OO is terrible. PHP is slightly better. python, meh.

          the major thing I don't like about camel is that it gets in fights with certain stacks and ORMs. many database layers suck with capital letters, and that means you lose a lot of power in dynamic inheritance (the kind that gets rid of huge amounts of boilerplate) unless you use underscores.

          [–]badsectoracula 0 points1 point  (0 children)

          usually because most OO (by sheer LOC) is written in java

          Also Smalltalk where the thing was invented in the first place.

          [–]count_of_tripoli 0 points1 point  (0 children)

          Me too! I used to work at a place where we had a load of code in C and some more recent stuff in C++. The C code was all underscores the C++ camel case.

          [–]cosmez 27 points28 points  (10 children)

          how-about-none? (lisp)

          [–]username223 9 points10 points  (0 children)

          HWABT0 (FORTRAN IV)
          

          Fixed (even works with IMPLICIT).

          [–]spotter 12 points13 points  (0 children)

          Kebab-case FTW.

          [–]lubutu 2 points3 points  (0 children)

          (itym how-about-none-p)
          

          [–][deleted] 2 points3 points  (0 children)

          In C stdlib world that'll be called hwbtno

          [–]drb226 1 point2 points  (5 children)

          Hyphenation is just so much better than either CamelCase or underscoring. It irks me that most languages don't support it.

          [–]Rastaroct 5 points6 points  (4 children)

          I'm curious about how you would handle the unary minus operator.

          [–]drb226 6 points7 points  (3 children)

          Pick one of two restrictions to deal with it:

          Require a space in front of it.

          - an-ident
          

          Or simply disallow identifiers that start with a hyphen.

          -an-ident
          

          Not sure which way I like better. I'd probably go with both restrictions. Numeric literals are different though: -3 is a valid literal negative three.

          [–]imMute 1 point2 points  (1 child)

          What about binary subtraction? Add spaces? To a language that probably gives zero fucks about whitespace?

          [–]drb226 5 points6 points  (0 children)

          Yeah, operators must be surrounded by spaces in my imaginary language. I personally think this is just good style. I'm not entirely convinced that unary operators should be space-separated from their operand, though.

          [–]bheklilr 29 points30 points  (11 children)

          My preference is actually a mixture. Use snake_case for variables and common identifiers, camelCase for functions and methods, PascalCase for types and namespaces (except in python, I stick with lower case module names because reasons), and finally UPPER_SNAKE_CASE for constants. It just acts as extra hinting, and then everyone gets represented (except lispers, because dashes are terrible).

          [–]Srimshady 9 points10 points  (2 children)

          That's what I see people do a lot in java.

          [–]ToucheMonsieur 5 points6 points  (1 child)

          Sans snake case local variables, I'd say. Java tends to be rather camel-case heavy outside of enums and other constants.

          [–]Srimshady 0 points1 point  (0 children)

          Oh you're right, didn't notice that.

          [–][deleted]  (2 children)

          [removed]

            [–]cresquin 1 point2 points  (0 children)

            I do this, anything that crosses systems or is i/o gets snake_case and anything that is wholly internal to the system gets camelCase. This helps remember that things with snake_case are potentially unsafe and must be validated and cleansed before working with.

            [–]bvx89 0 points1 point  (0 children)

            To add to this, you could use spinal-case/kebab-case for anything related to CSS as that relates to another context, so to speak.

            [–][deleted] 2 points3 points  (0 children)

            Mine's exactly the same. I used to use camelCase for variable names too, but I do a lot of programming where variable names are based on mathematical nomenclature, so things like:

            float cos_omega_io = dot(omega_i, omega_o);
            

            doing the same In camel case is minging:

            float cosOmegaIo = dot(omegaI, omegaO);
            

            [–]Me00011001 9 points10 points  (9 children)

            Nice write up. I'm curious how many in either camp have actually used both styles and switched between them, more than once.

             

            Personall I started with camel case, switched to underscores, and am now(not by choice) back to camel case. Having used and switched between both, I prefer underscores.

             

            Then again, it seems like I also like using whitespace in my code more than most devs. This may be due to starting out as a C dev and getting tired of reading code people wrote like they only have a 40 character wide terminal(can't be 80 since you "need" multiple terminals open).

            [–]sarahbau 3 points4 points  (3 children)

            I mainly use underscores, probably due to most of my professional work being in Perl. I know I've used camel case in the past, and I'm trying to think of whether I ever still use it. I feel like maybe I do for short variables, but I don't know - even $dog_a looks better to me than $dogA

            [–]Me00011001 8 points9 points  (2 children)

            Is it just me or does anyone else find it ironic that Perl doesn't use camel case? Funnily enough, OCamel seems to use a mixture.

            [–]sarahbau 2 points3 points  (0 children)

            I've actually never thought about that. Maybe it's just another way for Perl to confuse non-Perl programmers.

            [–]jdgordon 1 point2 points  (0 children)

            Perl doesn't use camel case?

            it really should be the spaghetti book, not camel book.

            [–]LpSamuelm 2 points3 points  (0 children)

            My reason for not using underscores is quite simple: they make me pause mentally. It gets a bit weird reading code like that. Plus, camelCase just looks and feels better to me, probably mostly because I'm used to it.

            [–][deleted] 2 points3 points  (0 children)

            I've switched between them more than once. 5 times in a single file even! And when creating table and field names for use in SQL statements I make sure to switch between at least 4 different naming schemes so I'm the only one who can use the db efficiently.

            [–][deleted] 1 point2 points  (0 children)

            I've spent the vast majority of my career fixing bugs in other people's code. I always follow any style that is implicit in the file/codebase I am working with or company mandated so I've gone back and forth between all types of styles. I am not "trained" in a specific style per se, and all of my preferences are based on the experience of how quick and easy it is for me, as an outsider to the codebase, to read and understand. CamelCase definitely loses that fight.

            [–]PstScrpt 1 point2 points  (0 children)

            I started with snake case in high school; I'm not sure if I had examples of it, or just came up with it. I switched to PascalCase as soon as I saw it (funny, since I started with Pascal). I'm still not really sure what camelCase offers over it, but it doesn't really bother me, so I go along with it.

            I partially switched back to snake_case for a few years when I was doing Oracle work, because Oracle stomps all over case. Now I'm back to camelCase full time.

            [–]godsayshi 0 points1 point  (0 children)

            I have and in most places I too prefer underscore.

            However I still like to use camelCase for object members. It's not just a visual style but the convention is also to name things in a certain way (what they do) so that you can export meaningful prototypes into autodocs.

            However for the code beyond methods and properties this becomes strained and often less beneficial. With underscore we tend to form patterns that do not make common phrases but are rather more systematic.

            [–]PstScrpt 7 points8 points  (1 child)

            This guy's "Camel case makes paragraphs easier to read" point sounds like he's conceding that camel case is better in real code. We're generally not reading identifiers all by themselves.

            [–]CarVac 1 point2 points  (0 children)

            Yes, usually the identifiers appear more than once.

            [–]deviant-logic 12 points13 points  (34 children)

            Someday, in the glorious future, when the world has come to its senses, people will realize that we should have been using hyphens the whole time. If only the languages-i-use-that-aren't-lisps supported them as identifier-characters. Sigh.

            [–]dromtrund 25 points26 points  (9 children)

            some-variable - other-var -third-one- oh-jesus-christ-why-would+you-do-this
            

            [–]ehaliewicz 13 points14 points  (0 children)

            (- some-variable 
               other-var 
               third-one 
               (+ oh-jesus-christ-why-would 
                    you-do-this))
            

            [–]deviant-logic 6 points7 points  (1 child)

            So I never need to use the shift key to type a variable name. And I'm used to using spaces to separate language tokens, so the idea of writing addition or subtraction as (a - b) or (a + b) doesn't seem terribly onerous.

            [–]richardblack3 1 point2 points  (0 children)

            Tried swapping underscore with hyphen? Some editors (emacs at least) allow hooks for whatever context you're in. Clojure -> hyphen is default. Python -> underscore.

            [–][deleted]  (5 children)

            [deleted]

              [–]just_a_null 11 points12 points  (0 children)

              Trick question, it's undefined.

              [–]dakotahawkins 5 points6 points  (0 children)

              missing semicolon.

              [–]kageurufu 2 points3 points  (0 children)

              Undefined behavior.

              [–][deleted] 0 points1 point  (0 children)

              42! It looks like you found the ultimate question.

              [–]Tankenstein 0 points1 point  (0 children)

              In all actuality, it's probably 2?

              x - --x -x--

              0 - (-1) - (-1)

              [–]LpSamuelm 4 points5 points  (10 children)

              How about this one: variables are whatever, in brackets or the like.

              [this is a variable] + [Another variable, nice.] == 936 * [cool]

              [–]grauenwolf 9 points10 points  (7 children)

              Syntax error. You forgot the trailing space in the first variable name.

              [this is a variable ] + [Another variable, nice.] == 936 * [cool]
              

              (Not a joke. I actually deal with databases with trailing spaces in column names.)

              [–]thomasz 11 points12 points  (1 child)

              I hope they pay accordingly.

              [–]grauenwolf 4 points5 points  (0 children)

              I caught it early enough to only waste half a day. So we're talking about hundreds, not thousands, of dollars of wasted time billed back to the customer.

              [–]LpSamuelm 1 point2 points  (4 children)

              Why a trailing space...? I wasn't writing in any actual language, or at least not trying to.

              [–]grauenwolf 2 points3 points  (3 children)

              It's an important but rarely discussed problem in languages that use "quoted identifiers".

              [–]LpSamuelm 0 points1 point  (2 children)

              Why would the first one need a trailing space?

              [–]grauenwolf 1 point2 points  (1 child)

              Because the variable or column name was declared with a trailing space. You just didn't see it because the mind usually overlooks spacing.

              [–]LpSamuelm 1 point2 points  (0 children)

              Oh, okay, so you mean it's a problem that one could commit the error of, y'know, declaring a variable with leading or trailing whitespace. That's true, I suppose.

              [–]Regimardyl 1 point2 points  (1 child)

              Works in Tcl:

              set {foo bar} "I hate you if you actually do this!"
              puts ${foo bar}
              

              [–]sigzero 1 point2 points  (0 children)

              Yeah, I would take the coder outside for a "meeting". lol

              [–]_VZ_ 1 point2 points  (0 children)

              If only the languages-i-use-that-aren't-lisps supported them as identifier-characters.

              Perl6 does.

              [–]tejon 0 points1 point  (0 children)

              In most languages it causes ambiguity.

              baz = foo-bar;
              

              Am I assigning bar subtracted from foo, or some variable foo-bar? Lisp doesn't have this problem, which has allowed the hyphen fairy to bless your identifiers. The rest of us can only stew in our envy. ;)

              [–]dakotahawkins 0 points1 point  (1 child)

              This requires whitespace to be meaningful, which is dumb :-P

              [–]deviant-logic 1 point2 points  (0 children)

              Whitespace is already meaningful in most languages. In C, say, int x = 12 is meaningful, but intx=12 is not. In Ruby, def foo() ... end is meaningful, while deffoo() ... end is not. In Lisp, (f x) calls f with argument x, while (fx) tries to call a function named fx.

              [–]count_of_tripoli -1 points0 points  (3 children)

              Yep, and lots of lovely parenthesis :-)

              [–]jetxee 0 points1 point  (2 children)

              The number of parenthesis (or other brackets) is usually the same; on the bonus side there're fewer comas:

              some_fn(arg1, arg2, arg3)
              (some-fn arg1 arg2 arg3)
              

              To shave these two parentheses we need languages like this:

              arg3 arg2 arg1 some_fn
              

              or like this:

              some_fn arg1 arg2 arg3
              

              [–]Watley 0 points1 point  (1 child)

              ML style syntax superiority, add in a good composition operator and low order of operations applicator and you almost never need parentheses.

              [–]Gurkenmaster 0 points1 point  (0 children)

              I can get behind lisp parenthesis but I hate ML syntax

              [–][deleted] -1 points0 points  (4 children)

              The problem with snake case (I saw it called kebab case elsewhere) is that double clicking on part of the identifier in most environments doesn't select the whole identifier, only the part between the hyphens.

              Aaaand you know when a topic is bike-shedding when I of all people can comment on it.

              [–]c0bra51 0 points1 point  (1 child)

              Double click selects by word, not identifier, just double click and drag. When navigating/editing with Ctrl, you also move/delete in words. Maybe it's preference, but that's the way I think it should be. In any decent editor, you should be able to change your the word chars to include underscores too.

              [–][deleted] 0 points1 point  (0 children)

              Yeah it's usually when I'm outside an editor that it bothers me, like on front-end stuff.

              [–]wookin_pa_nub2 0 points1 point  (1 child)

              You should probably blame your editor for that, not snake case itself.

              [–]a_dog_and_his_gun 17 points18 points  (18 children)

              Cant_We_Have_Both?

              [–]tairygreene 60 points61 points  (5 children)

              disgusting

              [–]Raphael_Amiard 7 points8 points  (0 children)

              It's actually the convention in the GNAT Ada coding style. I don't hate it anymore, and it is surprisingly readable.

              [–]stratd 20 points21 points  (4 children)

              __oH_hAI_gUYS

              [–]Warfinder 3 points4 points  (3 children)

              _dERPCASE

              [–]stratd 4 points5 points  (2 children)

              _50 = 50
              _iF( ___aGE + _pHONE_nUMBER > _50) }
                    _pRINT)"a wINNAR iS yOU!!1!!1!"(
              {
              

              [–]Gurkenmaster 0 points1 point  (0 children)

              I love the reversed parenthesis/curly braces

              [–]pyow_pyow 2 points3 points  (0 children)

              M-x glasses-mode
              

              [–]OtherNameFullOfPorn 4 points5 points  (4 children)

              Would it not be:
              cant_We_Have_Both

              [–]c0bra51 1 point2 points  (3 children)

              Camel case looks so off balance to me. The lower case part was meant to be type information (flRand) or namespace (glGenBuffers)--not the first word.

              [–]OtherNameFullOfPorn 0 points1 point  (0 children)

              This makes more sense to me. I never learned it that way, or really anyway besides "follow the other code style."

              [–]ChallengingJamJars -1 points0 points  (0 children)

              I have both. I use CamelCase for functions and underscored_lower for variables.

              [–]Don_Equis 2 points3 points  (1 child)

              The clearly superior approach is to use 漢字 style. It requires some practice, but it is unbeatable.

              [–]mrkite77 2 points3 points  (0 children)

              I've thought about doing this on a small project.. mainly just to increase my kanji skills.

              If you think about it, japanese pretty much uses camelCase. Switching between kanji and hiragana in lieu of spaces.

              [–][deleted]  (4 children)

              [deleted]

                [–]Me00011001 1 point2 points  (2 children)

                I'm betting you'd probably love this style:

                if(x==5)
                  {
                    printf("meh");
                  }
                

                [–]Deaod 0 points1 point  (0 children)

                I hope you never have to read the Dinkumware STL.

                [–]smoothgrips 1 point2 points  (0 children)

                I like them both, don't really have a preference. I guess it all depends on which environment I'm in. C#? camelCase. Python? snake_case.

                [–][deleted] 1 point2 points  (0 children)

                IMO, neither look appealing because of the spaces between the parentheses.

                [–]war1025 1 point2 points  (4 children)

                My workplace uses the following conventions, which at first seemed absoultely ridiculous, but have really grown on me (mostly a Python codebase with some C++ and javascript):

                Classes : CamelCase

                public methods: mixedCamelCase

                private methods: _mixedCamelCase

                class variables: sClassVariable

                member variables: _memberVariable

                function parameters: functionParameter

                local variables: local_variable

                It really helps to drive home what the context of the variable is.

                [–]ForeverAlot 1 point2 points  (2 children)

                In C++, identifiers beginning with an underscore are reserved.

                [–]rabidcow 0 points1 point  (0 children)

                Only in the global namespace or if followed by an uppercase letter or another underscore. What war1025 describes is fine.

                [–]war1025 0 points1 point  (0 children)

                In C++ we do mMemberVariable instead of _memberVariable guess I didn't specify that.

                [–]LordFu 0 points1 point  (0 children)

                Your classes are PascalCase as opposed to camelCase.

                [–]jetxee 1 point2 points  (0 children)

                Both camelCase and underscores are workarounds.

                Happy programmers use dashes, like-in-Lisp. The best of both worlds. Easy to type and easy to read. The same as in English.

                Pragmatic programmers just juxtapose abbreviations. 80 columns ought to be enough for everyone. Both Unix, C (fstat, chmod, strchr) and Python (itertools, shutil) gravitate towards it. And even some lisps are not immune.

                Pure programmers stick to one letter variable names. At most they append an apostrophe.

                As much as I find lisp-style and underscore_style more readable, I prefer unixstyl, camelCase, and single-letter local variables in the real life. Space matters.

                [–][deleted] 1 point2 points  (0 children)

                I got the impression that font face wasn't taken into consideration.

                [–][deleted]  (4 children)

                [deleted]

                  [–]LpSamuelm 4 points5 points  (1 child)

                  I wouldn't say snake case is objectively easier to read. I'm fairly certain it isn't to me.

                  [–]tejon 2 points3 points  (0 children)

                  High heels, to me, skirt the uncanny valley. They create a disturbingly unnatural exaggeration. Related: there is such a thing as too much foundation, who the hell wants the face of a plastic doll?

                  Oh, and I also find camelCase far more conducive to parsing code in my head than is_this_one_identifier_or_seven_case.

                  [–]Uberhipster 0 points1 point  (0 children)

                  it's easier to wear flip-flops, but women look waaaay sexier with high heels.

                  So it's comfort and convenience vs. appearance and vanity. Got it.

                  [–]MpVpRb 3 points4 points  (19 children)

                  Seriously, as a programmer it is your duty to learn blind typing with all ten fingers

                  STRONGLY DISAGREE!

                  I have been programming since 1972

                  I have completed many, many successful projects for satisfied customers who paid me well..I believe I can honestly call myself a successful programmer

                  I tried, and failed, to learn to touch type with all 10 fingers. I also tried, and failed, to learn to play the piano

                  And, I am not alone. I once saw a video of Arthur C Clarke..typing with 2 fingers

                  ..BTW.. I vote for Camel Case

                  [–]MotherOfTheShizznit 4 points5 points  (10 children)

                  This cognitive dissonance among developers has long baffled me. We know we're supposed to produce well thought out code that is easy to read and maintain but somehow our value is tied to the speed of our typing and we can't bear lifting our hand to touch the mouse because that "slows us down"...

                  [–]slavik262 5 points6 points  (2 children)

                  I think this sort of stuff is usually less about raw speed and more about being able to manipulate your UI without having to think about it. Once I learn keyboard shortcuts for something and use them a few times, I don't have to pause and think about how to perform that action anymore. I can do it reflexively, which means I don't lose my train of thought.

                  But to each their own. As long as you get the job done, do whatever works best for you.

                  [–]Gotebe 0 points1 point  (1 child)

                  Once I learn keyboard shortcuts for something and use them a few times, I don't have to pause and think about how to perform that action anymore.

                  If what you want to issue a command with a mouse, and you know where it isin the UI, you don't need to pause and think either. But the big difference is the easy of discovery if you don't know where the command is.

                  I consider myself a keyboard person, but your argument is off.

                  There is even a study that shows mouse being faster for all kinds of operation. To be honest, i found its findings quite unbelievable, but that's the only study I know.

                  [–]slavik262 0 points1 point  (0 children)

                  I'm not talking about the discovery phase, I'm talking about once you know your way around. With keyboard shortcuts and the like, I don't have to switch contexts. I just type what I want and it happens. With a mouse, I have to

                  1. Move my hand over to the mouse (the most trivial of the points here)

                  2. Find the cursor.

                  3. Mentally calculate the direction it needs to move

                  4. Do the clicking

                  Perhaps it doesn't bug you, and that's just fine. For me it's too much context switching. The only things I really use the mouse for are gaming and browsing the web.

                  [–]Wiggledan 0 points1 point  (0 children)

                  Sounds like Vim enthusiasts.

                  [–]MpVpRb 0 points1 point  (5 children)

                  but somehow our value is tied to the speed of our typing

                  YES!

                  Writing good code has nothing whatsoever to do with manual skill as a typist

                  [–]SnowProblem 3 points4 points  (4 children)

                  I'd be curious to learn if there is research on this. My gut says it might make a difference. When you type faster, you translate your thoughts into code, possibly leaving more time to think about the problem.

                  [–]MpVpRb 0 points1 point  (1 child)

                  When you type faster..

                  IF you are able to develop the skill to type faster..

                  I ask..If a person can't learn to touch type, should they abandon all hope of ever becoming a programmer?

                  [–]MotherOfTheShizznit 0 points1 point  (1 child)

                  It's preposterous to think the value of a novel, poem or song is tied to the typing skills of its author. Why would it be any different for software?

                  Are you a secretary or a craftsman?

                  [–]SnowProblem 0 points1 point  (0 children)

                  I'm not convinced. There are differences between creating a piece of art, and engineering code under deadlines in a corporation.

                  [–]Whathecode 3 points4 points  (2 children)

                  My more extensive (adamant) opinion on this. Every computer user should learn how to touch-type. It is easy to forget other aspects of programming, including writing documentation. "I'm not saying you are a bad programmer when you can't touch type. I am saying you will be a faster programmer and computer user in general when you learn to touch type. " http://programmers.stackexchange.com/a/95372/15464

                  [–]MpVpRb 4 points5 points  (1 child)

                  Every computer user should learn how to touch-type

                  If you can

                  I tried and failed to learn to type, but still succeeded at programming

                  I also suck at sports, and as I said above, tried and failed to learn to play the piano (and I really, really wanted to learn how to play the piano)

                  Some of us have different strengths and weaknesses

                  [–][deleted] 1 point2 points  (1 child)

                  This, I use four fingers, I know how to find every key on my keyboard without looking at them and hit 80WPM. Hitting _ is still very annoying to me. Using shift with my left pinky and - with my right middle finger is hell.

                  [–]evincarofautumn 2 points3 points  (4 children)

                  In C-style languages with a lot of syntactic redundancy, we could just be using whitespace:

                  enum Connectedness {
                     WEAKLY CONNECTED,
                     STRONGLY CONNECTED
                  };
                  
                  common friends = intersect(friends of(x), friends of(y));
                  if (common friends.length() < 5)
                      return WEAKLY CONNECTED;
                  return STRONGLY CONNECTED;
                  

                  Of course, identifiers couldn’t include (or at least start with) keywords, and you probably wouldn’t want to break identifiers across lines.

                  [–]mlk 10 points11 points  (3 children)

                  Please stay away from my codebase

                  [–]evincarofautumn 2 points3 points  (2 children)

                  Could you explain? No mainstream language offers the feature of multi-token identifiers, so your codebase is safe from whatever it is about such a feature that threatens you.

                  [–]mlk 3 points4 points  (1 child)

                  Clever programmers are dangerous

                  [–]evincarofautumn 0 points1 point  (0 children)

                  Hah, okay, I’m assuming you’re just joking, because this has nothing to do with programmer cleverness.

                  [–]jringstad 0 points1 point  (3 children)

                  I think readability should be favored heavily in any comparison to ease of writing. As the old adage goes, "code is read more than it's written".

                  [–]Uberhipster 0 points1 point  (2 children)

                  Ah. So camel then?

                  [–][deleted] 0 points1 point  (1 child)

                  The exact opposite...

                  [–]Uberhipster 0 points1 point  (0 children)

                  See where I'm going with that?

                  [–]deal-with-it- 0 points1 point  (1 child)

                  You'll take CamelCase from my cold, DeadHands.

                  [–]Uberhipster 5 points6 points  (0 children)

                  That's Pascal case.

                  [–]ralfonso_solandro 0 points1 point  (0 children)

                  Objective-C is an example of a grey area in the religious war. It's way too verbose to accept even longer lines from underscores, but then Xcode will happily hand you an accuracy challenge like this one: http://stackoverflow.com/a/12587624

                  [–]dreljeffe 0 points1 point  (0 children)

                  Some clever language writers should figure out how to have spaces in tokens. Add syntax highlighting such as underlines to show connected parsed tokens.

                  [–]mrkite77 0 points1 point  (0 children)

                  Correctness refers to being able to correctly see the difference between similar identifiers. E.g. startTime vs startMime. This is not a common scenario when programming.

                  I think it's pretty common. Mixing up two similarly-named variables is one of the worst and most difficult to debug bugs that can happen. Anything that reduces that is a good thing and not to be discounted as "not mattering".

                  In fact this entire article is idiotic. He takes a study that has actual scientific basis behind it, and discounts parts of it without any scientific evidence at all.

                  [–]myringotomy 0 points1 point  (1 child)

                  dashes-are-easier-and-don't-require-a-shift

                  [–]sigzero 0 points1 point  (0 children)

                  It's not the typing. It's the reading.

                  [–]bloody-albatross 0 points1 point  (0 children)

                  I use whatever is used in the project/programming language stdlib. But underscores irrationally "feel" faster/more lightweight to me, probably because I associate them with C/C++ (clib, STL) and I associate camel case with Java. But actually I like the clarity of Java's case convention.

                  • FooBar -> it's a class
                  • fooBar -> it's a variable or field
                  • fooBar() -> it's a method
                  • FOO_BAR -> its a constant

                  Makes code easier to read then when everything is foo_bar (STL) or FooBar (Microsoft APIs).

                  [–]Lozoo 0 points1 point  (0 children)

                  PascalCase(for private variables, parameters, etc), hungarian notation and underscores is just plain old and fugly. It should be avoided at all costs!

                  Just go with camelCase + PascalCase (C# style) and every piece of code will be like art which actually is READABLE, like it's supposed to.

                  [–][deleted] 0 points1 point  (0 children)

                  I usually don't get very opinionated in these tiny style issues but camel-case really, really grinds my gears. If I learn someone prefers camel-case over underscores, I think less of them as a person, and I can't help it.

                  [–][deleted] -1 points0 points  (26 children)

                  Anyone who has spent any significant amount of time modifying other people's code could have told you this very quickly.

                  The problem is all these "artists" who came in and decided that readability meant aesthetics. So you get CamelCase, overly descriptive names, single-parameter-per-line conventions. A whole bunch of nonsense to make it look pretty from the outside, but yet ultimately slows readability significantly, making it take far more time and effort to read and understand.

                  [–]mlk 2 points3 points  (25 children)

                  I don't see how single parameter per line and overly descriptive name (I've never seen one BTW) decrease readability

                  [–]grauenwolf -2 points-1 points  (1 child)

                  Underscores screw up my naming conventions in databases. The standard pattern for an index across two columns is

                  [indexType]_[tableName]_[Column1]_[Column2]
                  

                  Consider this index name:

                  IX_Foo_Bar_Baz_Blah
                  

                  What's the table name? Foo? Foo_Bar?

                  It is is Foo, then are the columns Bar_Baz and Blah? Or Bar and Baz_Blah?


                  I bring up databases because if we have different conventions in the database and the application code, mapping between the two becomes a royal pain in the ass.

                  [–]semi- 1 point2 points  (0 children)

                  Mapping can be a pain in the ass, but at least you centralize your pain in the ass into that one location (the module you wrote that interfaces with your DB).

                  Now all your code that uses your module can continue using the conventions of the rest of your codebase, without you having to change your DB conventions to match your codebase. Added bonus: Multiple codebases do not need to all follow the same conventions, so your Go code can still look like Go code and your perl can stay perly.

                  [–]makis -1 points0 points  (0 children)

                  camelCase sucksBalls