Slashdot Mirror


The Effect of Programming Language On Software Quality

HughPickens.com writes: Discussions whether a given programming language is "the right tool for the job" inevitably lead to debate. While some of these debates may appear to be tinged with an almost religious fervor, most people would agree that a programming language can impact not only the coding process, but also the properties of the resulting product. Now computer scientists at the University of California — Davis have published a study of the effect of programming languages on software quality (PDF) using a very large data set from GitHub. They analyzed 729 projects with 80 million SLOC by 29,000 authors and 1.5 million commits in 17 languages. The large sample size allowed them to use a mixed-methods approach, combining multiple regression modeling with visualization and text analytics, to study the effect of language features such as static vs. dynamic typing, strong vs. weak typing on software quality. By triangulating findings from different methods, and controlling for confounding effects such as team size, project size, and project history, they report that language design does have a significant, but modest effect on software quality.

Quoting: "Most notably, it does appear that strong typing is modestly better than weak typing, and among functional languages, static typing is also somewhat better than dynamic typing. We also find that functional languages are somewhat better than procedural languages. It is worth noting that these modest effects arising from language design are overwhelmingly dominated by the process factors such as project size, team size, and commit size. However, we hasten to caution the reader that even these modest effects might quite possibly be due to other, intangible process factors, e.g., the preference of certain personality types for functional, static and strongly typed languages."

38 of 217 comments (clear)

  1. Take away for me by just_another_sean · · Score: 5, Interesting

    e.g., the preference of certain personality types for functional, static and strongly typed languages.

    My guess is that this has a bigger impact on most projects than actual features of a chosen language. I was thinking it the whole time I read the summary and then, sure enough, it's mentioned as a disclaimer at the end...

    --
    Creationist Textbook Stickers Declared Unconstitutional by CowboyNeal
    1. Re:Take away for me by Anonymous Coward · · Score: 5, Funny

      My take away is that strong typing is best. I need to start lifting weights and get my fingers stronger.

    2. Re:Take away for me by jythie · · Score: 4, Interesting

      That was my initial thought too. Each language and framework within the language seems to have developed its own developer culture, with people generally gravitating towards languages popular among others like themselves. I am not even sure if it is really 'personality type' of the individuals, but instead seems more likely to be the cultural norms within the developer community and what the 'right' balances when it comes to acceptable practices and such.

    3. Re:Take away for me by Mr+Z · · Score: 3, Interesting

      I wonder if you can do an analysis of code bases across languages for the same team? I regularly write significant amounts of C++ (these days, C++11), Perl and assembly language. Those are three rather different languages, with strong, weak and largely non-existent type systems, respectively.

      Of course, all three languages also open themselves to a wide range of programming styles, and I imagine if you picked any other set of languages you could make a similar statement. But if you measure the same programmers programming in across them (assuming a reasonably high level of proficiency in all of them), then perhaps you can determine what portion of the effect is due to the programmer vs. due to the language.

      After all, Real Programmers can write FORTRAN in any language.

    4. Re:Take away for me by Mr+Z · · Score: 4, Informative

      BTW, this ACM Queue article was linked from the blog post I linked above. It's another good, somewhat relevant read, IMHO. It makes largely the same point, though: It's more the programmer than the language.

    5. Re:Take away for me by Mr+Z · · Score: 4, Interesting

      I finally brought up the PDF. It appears the authors consider C++ weakly typed because it allows type-casting between, say, pointers and integers.

      While this is strictly true, I find myself avoiding such things whenever possible. Main exception: When talking directly to hardware, it's often quite necessary to treat pointers as integers and vice versa.

      I guess to fairly evaluate a language like C++, you need to categorize programs based on how the language was used in the program. If you stick to standard containers and standard algorithms, eschewing casting magic except as needed (and using runtime-checked casts the few places they are), your program is very different than one that, say, uses union-magic and type punning and so on every chance it gets. (I've written both types of programs... again, FORTRAN in any language.)

      One of my more recent projects was written ground-up in C++11. It relies on type safety, standard containers, standard algorithms, smart pointers (shared_ptr, unique_ptr) fairly heavily. It's been quite a different experience to program vs. my years of C programming. Way fewer dangling pointers, use-after-free errors, off-by-one looping errors, etc. But, the paper lumps both languages into the same bucket. That hardly seems fair.

    6. Re:Take away for me by Spazmania · · Score: 3, Interesting

      the preference of certain personality types for functional, static and strongly typed languages.

      Translation: because only very high-skill programmers attempt to use the very unpopular functional languages (like lisp and erlang) the resulting code is, on average, of better quality.

      --
      Moderating "-1, Disagree" is simple censorship. Have the guts to post your opinion.
    7. Re:Take away for me by psmears · · Score: 4, Insightful

      the preference of certain personality types for functional, static and strongly typed languages.

      Translation: because only very high-skill programmers attempt to use the very unpopular functional languages (like lisp and erlang) the resulting code is, on average, of better quality.

      There is another possible interpretation: that programmers who are very concerned about quality - and hence are happy when their language gives them lots of information about potential mistakes - like using languages with features (such as a strong type system) designed to allow detection of certain types of mistake. That is, it's specific features of the languages, rather than the fact that the languages are "unpopular", that draws quality-focussed programmers to them.

      Of course, that is just as much conjecture as any other interpretation :-)

  2. More factors to normalise out. by beelsebob · · Score: 4, Interesting

    It's clear that there are more factors here that need to be normalised out. For example, they found that the category that "had" the most performance bugs was the procedural, static, unmanaged memory category, i.e. C, C++ etc, far outstripping languages like ruby. To me, it's clear that that is caused by people using these languages actually caring about performance, while people using languages who's implementations are many orders of magnitude slower, don't really file (or fix) bugs about perf.

    1. Re:More factors to normalise out. by Wootery · · Score: 3, Informative

      C/C++ certainly let you shoot yourself in the foot regarding correctness, but they generally don't make it easy to shoot yourself in the foot regarding performance. (C++ templates, exceptions, and RTTI being exceptions.)

      And the fact idiots still use those languages in areas where performance isn't an absolute priority is simple idiocy.

      Other legitimate reasons include legacy codebase, existence of useful libraries accessible from only these languages, extreme practical portability (yes you can technically run C# on Android, or Java on iPhone, but it takes proprietary external tools), etc.

    2. Re:More factors to normalise out. by K.+S.+Kyosuke · · Score: 3, Insightful

      The car analogy should include the fact that since the vast majority of people isn't facing the need to solve the Indy 500 problem, the very same vast majority of people is better served with learning to use more practical tools. A computer analogy would be using assembly language for a bootloader vs. using Python for whatever non-bootloader problem you happen to have.

      --
      Ezekiel 23:20
    3. Re:More factors to normalise out. by Wootery · · Score: 3, Interesting

      Not really. Which data-structures are immediately available in a language, does matter. Ruby has associative arrays as part of the language, and they're used for all sorts of things despite that traditional arrays would be more efficient. Ruby doesn't care much about efficiency.

      On the other hand, up until quite recently the C++ standard-library didn't include a hash-map, so a busy developer might be tempted to just use an array and a linear-scan; that's easier than setting up Google's sparsehash library.

    4. Re:More factors to normalise out. by naasking · · Score: 3, Interesting

      Oh, I also forgot to mention:

      and that your resources are freed deterministically the instant you are done with them, rather than "at some time in the future, maybe".

      Except this can lead to extremely high latency due to cascading deletions, which is another potential source of performance problems in C/C++. If you try to bound the amount of work to do to avoid this problem, you necessarily introduce reclamation latency. Reclamation latency isn't necessarily a bad thing.

  3. So by stealth_finger · · Score: 3, Funny

    it says basically nothing

    --
    Wanna buy a shirt?
    https://www.redbubble.com/people/stealthfinger/shop?asc=u
  4. Or, to put it another way... by jeffb+(2.718) · · Score: 5, Insightful

    "We aren't saying that functional, static and strongly typed languages are inherently superior. We're just saying that if you don't prefer them, maybe you aren't really cut out for programming."

    1. Re:Or, to put it another way... by Z00L00K · · Score: 5, Insightful

      So far my preference lies with static strongly typed languages, and from the question of code quality it's certainly helpful.

      However the real strength of static strongly typed languages is when it comes to maintenance. The original programmer knows what he's using, but someone inheriting an old code base will need to put down a large amount of time to figure out how it's actually built and what a certain type do. A dynamically typed solution tends to be elusive and can change the semantics depending on how it's used, which can range from confusing to outright hilarious.

      --
      If builders built buildings the way programmers wrote programs, then the first woodpecker would destroy civilization.
    2. Re:Or, to put it another way... by i+kan+reed · · Score: 3, Informative

      I'm going to put out an alternate conjecture:

      Interfaces are the magic that tend to make strongly typed languages work well. That, for example, C and C++ don't positively contribute to the trends this article discusses(though I can certainly imagine that people who know how to manage their own memory tend to have a more robust understanding of code).

      The ability to abstractly describe the kinds of behavior that are needed to fulfill a class of task in an application lends itself to a framework that's intuitive to complete. In other languages you expose yourself to a lot of time spent manually lining up the requirements of external pieces to what you're writing now.

      Again, all conjecture, but it comes from my own observation of when I tend to make mistakes.

    3. Re:Or, to put it another way... by i+kan+reed · · Score: 4, Funny

      Using abstract classes in C++ (with multiple inheritance) is a bit like surgically cutting a hole in your foot so that when you shoot yourself, it doesn't hurt too bad.

      Yeah, it achieves the goal, and makes it a little less messy to clean up, but it doesn't really guide the coding process to protect yourself the way compiler recognized interfaces do.

  5. Other factors. by LWATCDR · · Score: 4, Interesting

    Almost no casual programer uses functional languages and do not tend to be used for large FOSS projects.

    --
    See my blog http://ilovecookes.blogspot.com/ for light hearted technical information.
    1. Re:Other factors. by naasking · · Score: 3, Informative

      Having closures does not make a functional language, instead, what makes a functional language is referential transparency.

      Scheme, Lisp, OCaml are all functional languages that are not referentially transparent. Pure functional languages require referential transparency, but impure functional languages do exist.

      JavaScript is a functional language, but it's also procedural and object-oriented.

  6. Also which languages that beginners choose. by EmperorOfCanada · · Score: 4, Insightful

    I would say that there are three other critical factors; which languages beginners chose, which languages are rarely used, and potentially even more importantly which languages become the programmer's only language ever.

    If someone is new to programming then their programming is probably going to be poor. So certain languages tend to be "gateway" languages such as PHP, Python, VB(in the past), C#, etc. It is doubtful that someone is going to start out their programming career with the C in OpenCL or Haskell.
    I have seen many people learn PowerBuilder and never learn anything else, and while they might master powerbuilder they never really master programming. I have also seen the same thing with accountants who master the VB in excel resulting in some of the strangest agglomerations of code I have ever seen.
    But also certain languages are sort of throwaway for many programmers such as whatever the language is inside Make scripts; as most programmers that I know have not mastered make and do what they have to do to get things to compile. The same with bash; I have only met a few programmers who truly knew bash. They did what they had to do and ran away after that.

    So it would be very difficult to tease out the quality of a language based on these statistics. But regardless of the results the religious zealots who think their language is the very best and that all others are for children won't be swayed by facts anyway.

    1. Re:Also which languages that beginners choose. by Mr+Z · · Score: 3, Interesting

      As for which language is your gateway language, it probably depends on what era you started programming in, too. My path was Microsoft BASIC => Assembly => Turbo Pascal => C => Perl => C++11, with some shell scripting and other goodies around the fringes. I've probably written more C than anything, but C++11 rules my future. Turbo Pascal was my short-lived gateway to C, where I then spent most of my career. I wrote some truly regrettable neophyte-programmer code in C there at the beginning, so really C was where I grew from a college-aged hacker to someone who can actually program. Now guess how old I am. ;-)

      I guess for an analysis like this, you really need to limit yourself to people who consider themselves competent programmers. Those VB macro whizzes in accounting likely consider themselves accountants, not programmers. Likewise for the physicist with a pile of creaky MATLAB models.

      BTW, I have to agree with you 100% on make and bash. I consider myself above average on make as compared to my coworkers, but that's an extremely low bar. And while I've done some crazy stuff in bash in the past, these days I'll hop over to perl for anything more than 10 - 20 lines, especially if I find too much 'sed' showing up or find myself wanting an actual data structure.

  7. You need enough rope to hang yourself by msobkow · · Score: 4, Informative

    The more flexibility and power a language provides, the more opportunities you have to hang yourself with it.

    Personally what I hate are loosely, dynamically typed languages. They provide no compile-time checking at all that I can detect, which means that in order to even guess whether the code is "correct" you have to run through all the possible use cases. I realize that it's an ideal to test all possible inputs (especially boundary conditions), but that just isn't practical for most project schedules and budgets.

    As powerful as functional languages can be, the restrictions imposed by them can lead to difficulty implementing certain behaviours in the code. In fact, one Erlang project I worked on proved to have such an extreme difficulty implementing an algorithm that we had to cancel the project, even though the rest of the project had been completed. (That function was *the* heart of the system: the scheduling algorithm>)

    Much as the researchers discovered, I've never really found the programming language itself to have much of an impact on the code quality or readability of the code if the code was competently written. That said, even the best of languages can be turned into unmaintainable gobbledygook by a dedicated bonehead, especially consultants who know damned well they'll be long gone before the project enters maintenance/enhancement mode.

    What I found really degrades quality is not the language, but an overemphasis on code style at some companies. Instead of code reviews focusing on the functionality of the code being reviewed, they spend all their time nit-picking about variable names and whether to use camel-case or underscores.

    I consider the maintainability and readability of code to be at least as important as any metrics about the number of bugs in a project. If you can't read and understand the code easily, fixing a bug when it is discovered becomes a hellish nightmare.

    --
    I do not fail; I succeed at finding out what does not work.
    1. Re:You need enough rope to hang yourself by Shados · · Score: 3, Interesting

      For functional languages, the ideal is a language that supports both procedural and functional construct, so you can use either when it makes sense. Scala, and to a lesser extent C#, fit that bill quite nicely.

      Dynamically typed languages are great in cases where you'd be writing all the test cases anyway. UI code is a good example. Its faster to write proper JavaScript unit tests. provided you have the necessary infrastructure, than to manually test click click click. Since you're writing all the tests anyway, then having a dynamic language has very little drawbacks.

    2. Re:You need enough rope to hang yourself by SQLGuru · · Score: 4, Insightful

      This. Languages that enforce their rules at compile time vs run time should inherently lead to higher quality code just by "accident". You can still write bad (or good) code in any language, but a language that lets you do whatever you want requires you to be much more rigorous in your testing strategy to ensure higher quality......and we all know how much developers love to test (and to document).

    3. Re:You need enough rope to hang yourself by cdrudge · · Score: 4, Funny

      and we all know how much developers love to test (and to document).

      What are these "test" and "document" things you speak of?

  8. KISS by polar+red · · Score: 4, Insightful

    The KISS-principle is probably the most important thing to keep software quality up, more so than tools and language.

    --
    Yes, I'm left. You have a problem with that?
    1. Re:KISS by internerdj · · Score: 3, Interesting

      The motivation behind this paper was probably the intuition that language choice greatly influences KISS. But frankly, I've never had a real project where language choice wasn't driven by external forces.

    2. Re:KISS by Anne+Thwacks · · Score: 5, Interesting
      I have been responsible for language choice on many occasions, and I can say with confidence, sometimes I made the right choice and sometimes not.

      For a project starting in 1983, and expected to last 8 months, Basic seemed like a good idea. By 1995, it should have been obvious to everyone that a re-write in ANYTHING ELSE was justified (not that I would personally recommend using Perl to write a Basic interpreter to re-interpret the original Basic code or using Snobol4 to translate the Basic into Fortran).

      I could have used C instead - the project would probably have taken a couple of weeks longer, but would have saved countless people years of grief. I have C programs from the 80's that compile on *BSD unchanged, and still work as intended*. It was a toss-up at the time.

      My point is that the language choice may be influenced by incorrect information about the external world - because the external world is subject to massive change.

      * I had to rewrite some C from the 70's cos they were written for Idris and all in capitals :-{ Fortran4 programs from the 70's may compile and run, but you certainly need to re-test them!

      Yes its true: my lawn is written in Fortran, but my Mum's has an Ibjob border.

      --
      Sent from my ASR33 using ASCII
  9. Language by ledow · · Score: 4, Insightful

    You can code sloppily in any language.

    All this tells me is that there's so little difference as it not to be a major factor in your choice of language. As such, other more practical considerations (such as hiring programmers, project time, and even speed of the final code) should take far more precedence than the triviality of what language you happen to use.

    As with all things "programming language" - apply them to real language. I'm certain that in some languages, it's easier to mis-speak at a critical moment, or to say the wrong thing, or be misconstrued. I'm also certain that some languages are more prevalent, easier to learn, clearer in their intent and grammar, etc.

    But it doesn't mean at any point that you should change what you're doing to the language of the moment, nor that you should choose what language to do a project in taking any notice of the structure or grammar of the language over who you have who can speak it and how well everyone can be understood if they speak it together.

    Also, there are languages and dialects that make specific tasks easier (for instance, IT has a language all of it's own, talking about SCSI, buses, cloud, etc.). If everyone is able to "speak the lingo", then that's a good choice, but it's not the be-all and end-all of a good project.

    As such, all the programming language discussion is really like saying "We should all speak and write only in Chinese, because the Chinese for death and dearth sound more different and we won't get confused". Don't. Program in the language that you're comfortable with, that the people you hire can read and write fluently, and that is most common and available.

    Personally, that's always been C / C99 for me. So I always find it hard to justify the use of other languages except when there's a functional difference that gives a distinct advantage (e.g. a scripting language for scripting, or string-handling in Perl, etc.)

    TL;DR version: Who cares what language? Stop arguing about it and start coding.

  10. Development effort not considered by pem · · Score: 4, Insightful
    They discuss prior studies that looked at development effort, but hand-waved away the fact that dynamic languages take less development effort.

    This may well be because their study cannot discern the amount of programmer effort per check-in, but it is a fatal flaw. Open development methods mean that a lot of dirty laundry gets checked into repositories. If dynamic languages have more bugs per check-in, but require significantly less work per check-in, then measuring bugs per check-in without measuring effort per check-in is meaningless, and that's before you even get to the functionality provided by the checked-in code.

  11. Language by TVmisGuided · · Score: 4, Insightful

    You can code sloppily in any language.

    True, but some languages make it more difficult to do so. Ada, for example, won't allow code to compile with (what should be) obvious logic or syntax errors that most C/C++ compilers will happily ignore, and hence allow to go undiscovered until runtime...errors that could be catastrophic in the real world.

    Ada has acquired a reputation as a niche-market language, but that niche market takes heavy advantage of Ada's strengths: strong typing and a requirement that the developer properly design the software before writing code. Unfortunately, deciding to develop commercial software in Ada also comes with a fairly steep price tag, because it's a niche market...thus perpetuating the cycle.

    DISCLAIMER: I am not affiliated with any company which produces or sells Ada compilers.

    --
    All the world's an analog stage, and digital circuits play only bit parts.
  12. How did they measure quality? by MobyDisk · · Score: 5, Insightful

    The problem with these kinds of studies is that there is no actual way to objectively measure software quality. You can correlate all the data you want, but garbage in means garbage out.

    For this study they used two thinfactor gs to determine software quality: one is the number of bugfix commits. Ugh. I'm not even clear if the number of bugfix commits means higher quality, or lower quality. That could go either way. It might mean you had better testers, or that you committed things in small batches, or that you had more branches. The other factor was a natural language processor that read the check-in comments. While this is a really cool idea, you would need a lot of research just to prove that this approach actually works before you can start using the technique to draw conclusions about some other data.

    So while this was very cool, and very ambitious, the results are completely meaningless until someone can prove that this technique actually measures software quality at all.

  13. Concurrency bugs found in highly concurrent langs by Count+Fenring · · Score: 4, Insightful

    Also striking - they point out that functional languages, in particular Scala, Erlang, and Clojure have more concurrency bugs, without bringing up that concurrency support is basically the primary feature those languages are selected for. I'd love to see the defect number correlated with the percentage of code dealing with concurrency.

  14. Emacs! by Bob9113 · · Score: 5, Funny

    I don't care what they say, software written with Emacs is way better than software writen with Vi!

  15. Re:Concurrency bugs found in highly concurrent lan by jeorgen · · Score: 3, Interesting

    Absolutely! They write:

    "The major languages that contribute concurrency errors
    from these classes are Go, C#, and Scala and their regression
    coefficient is also statistically significant. These results confirm,
    in general static languages produce more concurrency errors than
    others. Among the dynamic languages, only Erlang is more
    prone to concurrency errors. The regression analysis also shows
    that projects written in dynamic languages like CoffeeScript,
    TypeScript, Ruby, and Php have fewer concurrency errors"

    Well, there isn't much concurrency to be had in TypeScript or CoffeeScript since they operate in single threaded environments, and it wouldn't surpise me if the same goes for the other ones. And saying that Erlan has problems with concurrency is... the cart before the horse.

  16. low level programmers understand data structures by Anonymous Coward · · Score: 3, Interesting

    Python also uses hash tables everywhere, including for global and local variables and instance and class members.
    The implementations of the hash table is extremely optimised.

    There was an interesting discussion on usenet about someone who wanted to optimise a piece of Python code by writing a C++ module to do the heavy lifting. It was about adding C++ strings into a C++ hash map. The naive version was 10,000 times slower in C++.

    Of course the naive function was copying strings many times since this is what the string class does when passing by value. After many posts they came up with a optimised version, it was about 100 lines of code (original was 10 lines), with lots of references passing and explicit and complex template instantiation of the hash map and its iterators. It was still 1.2 times slower than the Python implementation.

  17. so, static == more defects? by Fubari · · Score: 3, Interesting
    Wait. Aren't they saying that static typing needs more defect-fixes and dynamic needs less defect-fixes?
    Relevant parts highlighted:

    "The remaining coefficients are significant and either positive or negative.
    For those with positive coefficients we can expect that
    the language is associated with ... a greater number of defect fixes.
    These languages include C, C++, JavaScript, Objective-C, Php, and Python.

    The languages Clojure, Haskell, Ruby, Scala, and TypeScript, all have negative coefficients
    implying that these languages are less likely than the average to result in defect fixing commits"

    Isn't the real message here to choose static typing if you like fixing bugs?