9 ms·
Most used words in programming languages
- kosma 10y agoThis might just be my Python upbringing, but... am I the only one to be troubled by Go's single-letter words? I've always found Go code very hard to read because it isn't self-descriptive at all.
- Walkman 10y agoWhen you have a strong static type system like Go has, you don't need descriptive names that much, because even single letter variable names are evident, because the declarations are there, close to the variable names. It needs a bit of getting used to if you only programmed dynamic or scripting languages.
- masklinn 10y ago> you don't need descriptive names that much, because even single letter variable names are evident That's an annoying lie, and makes codebases in languages with genuinely strong static type systems (e.g. Haskell) much harder to read than necessary. Hell C#'s type system is stronger than Go's, yet there is no such prevalence of meaningless variable names (first one comes in at #23, Go has 7 single-letter variable names in the top 23)
- bnegreve 10y agoStill, I think GP's comment is interesting. I do agree that type name and variable/argument name can be redundant in statically typed languages, such as c++ or java. (I've never used Go) For example, int getAge(Person p); is clear enough, whereas int getAge(Person person) ; is redundant. Haskell does type inference, so even if types are static they are not explicit. That's why you still need explicit variable names.
- masklinn 10y ago> I do agree that type name and variable/argument name can be redundant in statically typed languages, such as c++ or java. Except neither exposes that pattern (they essentially have only one such variable in their top list, and it's "i"). And I already mentioned C# which is very similar to Java. > is redundant. I'm not saying single-letter variables (or no variable at all which is also possible in Haskell) is universally bad, I'm saying it is disturbing to find how absolutely ubiquitous it is in Go. Variable names are sometimes redundant, that is not a universal constant. That redundancy is a factor of the expressiveness of the type system, that's hardly a claim of fame of Go. > Haskell does type inference, so even if types are static they are not explicit. Go has local type inference, and leveraging Haskell's global type inference is usually recommended against. > That's why you still need explicit variable names. No, it is not.
- msluyter 10y agoI think that depends on the length getAge(). If it's 3 lines, 'p' probably is fine. If it's 200 -- which, perhaps it shouldn't be but that's another issue -- then person is probably a better choice because you may lose the original context as you scan the method. Also in Java if you use intellij then you'll probably get 'person' as an autocomplete, which actually makes it roughly as easy to type out as 'p', (and a better choice if your entire team has standardized on intellij.)
- kosma 10y ago> It needs a bit of getting used to if you only programmed dynamic or scripting languages. I'm an embedded C developer. Our shop doesn't let single-letter variables pass in code review.
- bpicolo 10y agoSounds like a good shop! :) Even for loop variables I tend to use `idx` these days in languages without smarter constructs. Just slightly better and more readable for no effort.
- whatshisface 10y agoI disagree, we're so used to reading i that the (actually less phonetic) idx is really slightly harder to read. I take my bikesheds green, thank you.
- sidlls 10y agoMy background is scientific and systems programming in C and C++. Currently I write a lot of Python for my job and a lot of Rust for my spare time hobby programming, which consists of things like writing a BLAS, reimplementing other C and C++ projects, etc. So I haven't only programmed in dynamic or scripting languages. I strongly disagree with the assertion regarding single letter variables. I would gently correct a junior programmer who tried to do that and I would chew the hell out of a senior programmer if he tried it. In any language.
- gribbly 10y agoDepends, if it's self evident in the context what it means, like in a method which is declared as (p *player) Attack, p makes perfect sense (to me) rather than typing 'player' everywhere in the function, just like typing i instead of index. In short, I don't think there is a particular rule that applies, that said my impression is that a lot of variable names in Go code are typically three letters or at least two, like err, buf, src, dst, ok etc.
- the_duke 10y agoDid you mean single-syllable words?
- kps 10y agoGo is a language in the almost-forgotten algebraic tradition (loosely descending Fortran → Algol → BCPL → C → Go), in which people prefer E=mc² to MULTIPLY REST-MASS BY SPEED-OF-LIGHT-IN-A-VACUUM BY SPEED-OF-LIGHT-IN-A-VACUUM GIVING ENERGY.
- mpjme 10y agoThis would improve a lot if they filtered out comments.
- chriswarbo 10y agoReally? I think it's interesting to see "TODO" feature quite prominently in Python, for example :)
- imron 10y agoPerhaps both? I also think filtering out comments would improve it - especially because so many source files include a copyright statement at the top, and the same licenses (MIT, GPL, Apache, etc) are found repeated in many different files and it distorts the results somewhat.
- anvaka 10y agoThe copyrights are filtered out, because indeed there was a lot of them.
- masklinn 10y agoHow interesting is it to see "summary" is the top C# term?
- chriswarbo 10y agoIn that particular case, I'd say it's quite interesting indeed! Presumably "summary" appears quite a lot because C# developers use markup like `<summary>` in their comments, so automated systems can build documentation (I've never used a Microsoft programming language, but a quick search brought me to https://msdn.microsoft.com/en-us/library/z04awywx.aspx https://msdn.microsoft.com/en-us/library/z04awywx.aspx ). In that sense, it's not really a comment anymore: it's one machine-readable language embedded inside another. That's certainly interesting, to me at least. It tells me about the signal/noise ratio of the language, the prevalence of various forms of documentation (e.g. <summary> is conventional, whilst something like <precondition> is not), etc. Such terms clearly have an effect on a system's documentation, even if they don't have an effect on the CPU instructions being executed. But I'm a programmer, not a CPU; text files containing source code are my main I/O interface, and they most certainly do contain such markup, and hence I find it interesting to see statistics about. In comparison, I don't step through very much assembly day to day, so I don't really care very much about the compiler output (the part which the comments don't affect). I prefer to reason at the level of the language I'm using, where not only do comments appear, they're very useful!
- enitihas 10y agoLooking at Scala, the difference between val and var is huge, with val being at 2nd, and var at 38.
- nrinaudo 10y agoAnd else is used more than if...
- virtualwhys 10y agoUsage of `var` as idomatic Scala is an oft used trolling mechanism. I wonder what percentage of `_` usage is value/type discarding in pattern matching and type signatures vs. function application. Would be nice to somehow ditch `case`: adt match { Foo(x) if cond x => ... Bar(x) => ... } pairs.map{ (a,b) => ... }
- cven714 10y agoPretty cool! Some unexpected results, or at least not what I guessed. "summary" as the top for C#, "SELECT" all the way down at #43 for SQL, "err" as the top for Go (I'm sure that will spawn some pleasant discussion).
- donatj 10y agoI think it speaks well towards the ferocity and forced completeness of Go's error handling that err is the most used word.
- di4na 10y agoI would say it shows that this is a place where the compiler could help :D
- Klathmon 10y agoAs much as I hate all the typing I do for error checking in go, I just don't think a compiler can handle errors that well on their own yet. The explicitness of go's error handling forces you to handle every error specifically. There isn't a chance (for the most part) that you'll get an error from deep in the program that you can't easily handle. Forcing you to handle them everywhere and anywhere forces error handling to be a part of your architecture.
- di4na 10y agoErlang took this other way around by designing a system that enable you to not handle all these errors. I am more from this school of designing a system around the reality insteas of trying to patch it everywhere, praying we have enough fabrics to catch it all. But it would meam rethinking how we build stuff. That was not at all a goal of Go.
- imron 10y agoThis is really nifty, unfortunately it includes comments and so with thousands of files all including copyright notices, 'the' is the 3rd most popular word in c++ files.
- kalimatas 10y agoAnd PHP has "div", which seems to be HTML tag name.
- anvaka 10y agoI tried to exclude copyright lines as much as I could. I used "license markers" for that, but I might have missed something. Here is more information about it: https://github.com/anvaka/common-words#how https://github.com/anvaka/common-words#how
- imron 10y agoThat's good to hear. I didn't look in to it in too much depth, I just thought it was strange that 'the' was so high for c++ so clicked on it to see example usage and got things like: ** use the contact form at http://qt.digia.co/contact-us. furnished to do so, subject to the following conditions: * This file is part of the LibreOffice project. // with this library; see the file COPYING3. If not see So assumed licenses had not been excluded. Having a brief look at the source, I think with the licence marking approach it's still leaving in quite a few lines from each licence (see above for examples).
- chriswarbo 10y agoWould be nice to see Haskell included; would ".", "$", "<$>", "<*>", ">>=", etc. count as words? ;) Made even better by the use of the language's logo as the word clouds shape; the Haskell logo is ">λ=" https://www.haskell.org/static/img/haskell-logo.svg https://www.haskell.org/static/img/haskell-logo.svg
- anvaka 10y agoAdded: https://anvaka.github.io/common-words/#?lang=hs https://anvaka.github.io/common-words/#?lang=hs Unfortunately the symbols will not show up, because I'm ignoring them: https://github.com/anvaka/common-words/blob/master/data-extract/ignore/index.js#L4 https://github.com/anvaka/common-words/blob/master/data-extr...
- chriswarbo 10y ago> Added: https://anvaka.github.io/common-words/#?lang=hs https://anvaka.github.io/common-words/#?lang=hs > Unfortunately the symbols will not show up, because I'm ignoring them Makes sense. I notice that some funky unicode stuff has still managed to come out quite high, e.g. ⊇ ("superset of or equal to") :)
- deleted 10y ago[deleted]
- mschuetz 10y agoThe world would be a much better place if self(Python) and this(Javascript ES6 classes) were implicit.
- donatj 10y agoI disagree heartedly. Implicit code leads to easy to write hard to read. I'd much rather have where you are getting a value from be very explicit to not cause hard to see bugs as well as making the code easier to understand from a fragment.
- keymone 10y agofrom all the code i've seen javascript developers have more troubles with explicit "this" and bindings than ruby developers have with implicit self.
- dagw 10y agoJavascript 'this' binding behaves in quite unexpected ways if you're coming from something like python on ruby, which is a major source of trouble for people.
- masklinn 10y agoDo people really use implicit selfs in ruby? Note that @foo is not an implicit self.
- pmontra 10y agoself.attribute = attribute in an ActiveRecord class when the left side is a field of a table and the right side is a variable. A different name for the variable fixes it without using self.
- masklinn 10y ago> self.attribute = attribute in an ActiveRecord class when the left side is a field of a table and the right side is a variable That seems to be an example of not using an implicit self. > A different name for the variable fixes it There's nothing to fix, it works just fine.
- TuringTest 10y agoThe layout algorithm for the word cloud is awesome! How is it made?
- jamessb 10y agoThis is explained in the README of the project's Github repository: https://github.com/anvaka/common-words#how-are-word-clouds-rendered https://github.com/anvaka/common-words#how-are-word-clouds-r...
- delfaras 10y agoThere's a description of the method in the Readme https://github.com/anvaka/common-words#how-are-word-clouds-rendered https://github.com/anvaka/common-words#how-are-word-clouds-r...
- sambeau 10y agoUnfortunately it's not using size as a metric like mouse word clouds. This confused me at first. Look at the size of 'err' in the go layout.
- gjm11 10y agoIt looks to me as if it is. There just are a lot of uses of "err" in typical Go code.
- deleted 10y ago[deleted]
- BoorishBears 10y agoIt's humorous that in Go err/nil happens so often that it's "unbelievable" in a literal sense
- anvaka 10y agoIt uses it as long as there is enough space. Once it fails to find a rectangle to fit a new word, it tries to reduce the size of the word. In general, word clouds are bad for comparing sizes. For that reason I used plain list in the sidebar on the left (or at the bottom if you are on mobile)
- Walkman 10y agoOne can make very interesting conclusions based on purely this. Examples: - Python developers does not follow Clean Code (ala Uncle Bob) as much as Ruby , because if statement is more frequent than def and return. - Ruby makes it possible to write in a much more functional style than Python. OR Ruby developers like to develop more in a functional style than Python developers. - People don't really care about good variable names ("a" is a terrible variable name in scripting languages like JS and Python, still top 11) - PHP developers might practice "return early" in functions (more return than function keywords) OR their functions just do too much :)
- brak1 10y ago'a', 'the' etc seem to be from comments, not 'actual' code (click them and you can see examples of how each word is being used)
- drivebyops 10y agoWell Python also doesn't have a Match/switch flow. So that would bump ifs up
- giancarlostoro 10y agoThis and the fact that the page doesn't filter out comments which may affect results as well.
- dagw 10y ago- Ruby makes it possible to write in a much more functional style than Python. OR Ruby developers like to develop more in a functional style than Python developers. I instinctively think you might be right (at least with your second statement), but what are you using as your metric here?
- smnplk 10y agoI am not sure if ruby devs like to do much functional style, the parent mentioned Uncle Bob and his influence on Ruby community with Clean coders. I think they are more into OO.
- woliveirajr 10y agoJava: funny to see that "if" is used a lot to point to "visit oracle.com if..."
- Dowwie 10y agoI don't know whether I could believe this study as "foo" and "bar" aren't on the list.
- qarioz 10y agoWell I will slay my developers before they put the metasyntactic variables on master. I allow i to pass though. Go to j and you have O(n^2) and I will slay them again.
- d--b 10y agosummary is the most used word in C#! Only from comments! Amazing. EDIT: it looks like this is reading files that are common to all projects... which is why the sentence "// The following GUID is for the ID of the typelib if this project is exposed to COM" appears 459k times!
- masklinn 10y ago> EDIT: it looks like this is reading files that are common to all projects… Yeah, autogenerated files/comments feature extremely prominently e.g. the top two items for "should" in Ruby are autogenerated Rails comments.
- noblethrasher 10y agoAt least in C#, we could probably exclude auto-generated files by looking for the whitespace keywords "partial class|interface|struct".
- pomber 10y agoand the most used word in .cs files is "summary"
- mi_lk 10y agoWell, Lua's word list starts with index 0...
- Noughmad 10y agoIn most languages, the top words are self/this and function/def. On the other hand, in Go, the most common word is "err", and "if err != nil" are three of the top four words. I really wonder how big part of the code in Go is just propagating errors.
- s_kilk 10y agoSame with many node apps. Every other statement is: if (err !== null) { return callback(err); }
- Klathmon 10y agoWith es2015+ this is no longer the case, it's back to good old try/catch statements if using async/await, and .catch(...) if using promises.
- grabcocque 10y agoOne day, maybe half a decade from now, Rob Pike will wake up from a nightmare and suddenly realise they got this one wrong. Maybe it'll occur at the same time as the generics one.
- fagnerbrack 10y ago"err". Because "error" is too hard to type, right?
- matthewmacleod 10y agoWell, `error` is the type, and `err` is the most common variable name. It's not so unusual, just convention!
- the_duke 10y agoAlso, it cuts the characters you have to type and read in halve, while not being obtuse. That's an odd thing to complain about.
- 10y ago
- ddavis 10y agoThe slow adoption of modern C++ is very apparent. Some things not event listed: forward, unique_ptr, shared_ptr, tuple, constexptr. nullptr is much lower than NULL and move is quite low. These features are now 6+ years old! ;)
- mschuetz 10y agoSmart pointers realy need a native way to be specified, similar to how we use & to declare references and * for pointers. Filling your code with shared_ptr<Something> and the likes is just not going to win the majority over, even if it's useful.
- johannes1234321 10y agoA common way is having a "using FooPtr = shared_ptr<Foo>" somewhere and then only use FooPtr. This also reduces the occurrences in that word cloud.
- ddavis 10y ago> This also reduces the occurrences in that word cloud Ah, yes, very good point.
- ddavis 10y agoI agree it's made C++ a bit verbose, though something like the using keyword helps (which is 30 spots below typedef!)
- radupopescu 10y agoNowadays, you can do: auto sh_ptr = make_shared(....); // Since C++11 or auto uniq_ptr = make_unique(....); // Since C++14 It saves you from having to explicitly name the type parameter and you just need to pass in the parameters of the constructor. It's not as terse as & or *, but it's not that bad.
- lgessler 10y agoIs anyone investigating how well these numbers fit a Zipf distribution?
- fagnerbrack 10y agoA lot of meaningful and legible words out there /s
- tomw1808 10y agoSo happy I couldn't find "goto" :)
- Matumio 10y agoYou wish. It's #325 after you switch to cpp.
- nonsince 10y agoLots of uses of "the" in C++ code, massively skewed by giant projects that have the massive section of boilerplate copyright info in a comment at the top of every single file. I didn't realise until I looked at this, but although that's really common to see in C, C++, and Java you barely ever see it in the languages that I spend time in (Rust, Haskell, C#, Python, various flavours of Lisp, JavaScript).
- adrianN 10y agoWait another fifteen to twenty years or so until Python and Javascript are "enterprise ready" and this will change.
- TorKlingberg 10y agoAt least nobody is keeping a revision history at the top of the file any more.
- adrianN 10y agoYou'd be surprised...
- konsnos 10y agoIn C# the first word is "summary" which is massively influenced by the way Visual Studio formats comments. I wonder though if this is an indication that a lot of people write comments.
- AznHisoka 10y agoWord clouds may look cool but they are horrible for conveying information. this should have been just a simple ordered list.
- xyclos 10y agoThere is an ordered list on the page. If you're on a phone you can tap "show list" on the bottom.
- realworldview 10y agoIt would be interesting to see the frequency of words found in comments—TODO, FIXME, LATER, OMG—foreach language too.
- the_duke 10y agoAlso, there is the glorious phrase "Should never happen", with 24 million results on Github: https://github.com/search?q=should+never+happen&ref=simplesearch&type=Code&utf8=%E2%9C%93 https://github.com/search?q=should+never+happen&ref=simplese...
- bpicolo 10y agoPerfect time to throw an UnreachableCode exception or something, hah
- alexwebb2 10y agoInteresting that in JS, `let` is ranked 536, far lower than I expected.
- xyclos 10y agoanyone else find it at all ironic that the <em>least</em> common word in JS appears to be "validate"?
- singularity2001 10y agodjango > try (20 vs 21) try again
- Ensorceled 10y agoIn my django projects, I have many lines like: from django.<path> import <stuff> for every try block.
- dustinmoris 10y agoI am quite surprised that "self" is so much more used than the next word in the list "if". I know many languages where "self" is not a keyword at all, but I cannot think of a single language where "if" is not a keyword. EDIT: Ops, I missed that there is a language filter. Ignore my comment :)
- x1798DE 10y agoThis is broken down by language, the linked list is for python, so it just means that self is more frequently used than if in python.
- RodericDay 10y agoassignments are probably way more common than if-driven program flow control
- goatlover 10y agoI don't think if is a keyword in Smalltalk. IO might not have it either.
- masklinn 10y ago> I don't think if is a keyword in Smalltalk. It's so not a keyword it doesn't even exist. At least in the Smalltalks I've used, they provided ifTrue: and ifFalse: (and compositions thereof).
- macygray 10y agoCool stats about Java. "import" is the most frequently used word. It looks like everything is already exist in Java, so just import all the things, some clue code and you are done.
- gravypod 10y agoThen why isn't this the case for python. It's as equally as kitchen sink, right?
- the_duke 10y agoJava doesn't have syntax for importing more than one member of a package in one statement. Either you import a single member, or all with *. Combine that with IDEs that auto-create the import statement, and there you go.
- the_duke 10y agoI just remembered: also, each class in Java has to be in it's separate file. That might very well be the biggest factor.
- sleepychu 10y agoI think if you grouped the import statements by package the numbers would be similar but typically people import individual classes.
- masklinn 10y agoIn Python you usually import a module and use that as a symbol, or `from module import Symbol1, Symbol2, Symbol3`. Java doesn't have the former, and the latter requires an import per symbol (it also has the ability to import every symbol in a namespace, and so does Python, but that's usually discouraged)
- adrianlmm 10y agoInteresting that for Ruby the most used word is "option", is not even a Ruby but a Rails word.
- bryanrasmussen 10y agothis study is worthless without a section on frequency of swearwords and virulence of same.
- smnplk 10y agoI totally expected "should" to be at the top in ruby. Code bases with 2:1 or even more test code to implementation code ratio = standard.
- HissingSound 10y agoGood site. What did you use to get and analyze code and how much code did you analyze? I thought about something like this but about variables, methods e.t.c. most used words or even variables name generator based on markov-chain.
- Matumio 10y agohttps://github.com/anvaka/common-words#how-was-the-data-collected https://github.com/anvaka/common-words#how-was-the-data-coll...
- igravious 10y agoContrary to popular opinion neither `s' nor `t' are words. At least not in English anyway. :/ Or do they mean that these characters appeared as variable names?
- traviswingo 10y agoWhere do the language files get pulled from? GitHub API or web scraping? Or is it not file parsing and some other method? Super rad project :)
- anvaka 10y agoThanks! The data comes form GitHub snapshot, stored on BigQuery. Here is more details about it: https://github.com/anvaka/common-words#how https://github.com/anvaka/common-words#how
- ape4 10y agoBesides "return", C/C++ doesn't have a particular word that stands out. Probably because you just write write things. eg you don't put "function" in front of a function.
- mojuba 10y agoYes, I also thought that a list for each language shows exactly what's wrong with that language. For some it's self/this, Java is import and return, etc. for C++ there's no clear winner, because it is minimalistic by nature (mostly due to C heritage of course).
- kibwen 10y ago> for C++ there's no clear winner, because it is minimalistic by nature I presume I'm missing the sarcasm here...
- Insanity 10y agoI was really amused by the logos / names in the word clouds. Nice project!
- anvaka 10y agoThank you :)
- cr0sh 10y agoThis is pretty neat! I was surprised to see that for SQL, SELECT was so far down the list. I also wonder what the criteria is for which languages to analyze? There are a few other languages I would like to see, but maybe on github they aren't well represented...
- anvaka 10y agoThanks! I'm using file extension to differentiate between extensions. You can request other languages here: https://github.com/anvaka/common-words/issues/4 https://github.com/anvaka/common-words/issues/4 As long as language's extension is unique, I think I can make a visualization of it.
- cpsempek 10y agoI do appreciate this, but word clouds really are a terrible visualization method for text data. With regard to the python example, I cannot grasp at all if the frequency of self and None are similar or drastically different. The table on the value is more informative and less likely to misread.
- oblib 10y ago"that didn't work"
- pcwalton 10y agoThe Rust compiler seems somewhat overrepresented in this data set. I see "ccx", "fcx", and "CrateContext", which are only used in the Rust compiler itself.
- questerzen 10y agoIt is probably a sign of a good language that the words used most should be similar in frequency to their use in pseudo code. When words like "end" (Ruby), "self" (Python), "import" (Java), "err"/"error" (Go and Node) are over-represented, it's likely a sign that the language is introducing accidental complexity. By this metric Swift looks astonishingly sane.