Blue. No, Yellow
blog.cleancoder.com
blog.cleancoder.com
For example, Erlang is great when you need to do lots of concurrent operations with guarantees about safety and uptime, but not really what I'd write a CSV parsing program or email client in.
C is very easy to link against on almost every platform and language, so basic libraries are often written in C.
Javascript (in the form of nodejs) is great for writing simple web servers because most of its standard library is asynchronous by default. Compare Python (with Tornado or similar) where lots of popular libraries cannot easily be used in an event loop.
I could go on forever, and you might disagree with me about a particular details, but the general point stands. If you took an expert Erlang programmer and gave her a day to write a spreadsheet application, you'd get a worse result than the same day spent by a C# programmer.
DSLs can give you tremendous amplification when you play to their strengths.
If you look at feedback times, PHP is the new Smalltalk. (Yuck.)
At the end of the day you're probably best off using whichever language you know most, unless you're doing it for learning purposes, or it's one of those rare ones where it really does fit into a specific language.
The other option is to split the project into multiple services. Implement the backend service in e.g. c, and then do the front-end/GUI in, say, Python. This model is seen a lot with things like media players (e.g. mpd).
That being said, your overall point certainly stands. I wouldn't write an OS in Fortran, or a game in Ruby, etc.
Edit: I always use "he/she" or "her/him"
I do think using "she" as the hypothetical example for roles people think of as male is still useful; it hopefully makes people question their knee-jerk response a bit.
Using the names and pronouns with someone that they prefer is the polite thing to do, even if you don't "get" it. :)
[1] http://stackoverflow.com/questions/900055/is-sql-or-even-tsq...
Reducing the differences between programming languages to their performance/productivity and then claiming the choice is just bikeshedding.
Have fun with your ruby pacemaker, js air traffic control and life without static typing in 10mioLOC codebases.
Why do I feel like i have to apologize for my negative view on this? He has a commercial interest in maintaining his guru status.
The world view underlying this post is one of the reasons for shoddy software and all the breaches, data thefts, etc. that have successfully exploited systems flaws in recent years.
We simply do not because the practice of writing high-level specifications in the form of mathematical models or proofs is not common. I think the tools have become sophisticated enough and the maths approachable enough that it should be and can be used in the construction of non-safety-critical systems.
Unless I misunderstood the article, the claim which the article works toward is that Ruby and Js do not have an advantage at all, if the compile times for the static alternatives are short (which strongly implies that we shouldn't bother using them).
Quote:
article> But you said before that Ruby reduces the workload over Java.
article> I think it does; but only if the cycle time is long. If the edit/compile/test cycle time is kept very short, then the effect is negligible
See? The argument, astonishingly ignorant as it may be, is basically anti-dynamic: the advantage of dynamic is "no compile time", and that's it. Make compile time so fast that you hardly notice it, and the advantage is wiped away.
I think that's more an argument that imperative vs. compiled isn't a significant difference any more. In the modern world of JIT-compiled runtime environments and fast, incremental recompilation, it's actually one of the few points I agreed with in this article.
His premise that almost nothing else matters as long as the above is true and all programming languages allow very short write-test cycles is absurd, of course.
The advantage is, that you CAN compile moderately statically typed languages, they all can be equivalently and probably more easily than dynamic ones be implemented in an interpreted fashion.
But even then, eclipse compiles while editing, and I never have to wait (The only thing I like about eclipse haha ).
So the whole article was just written while intoxicated, or he is missing the deeper connections about language features beyond 2kloc ROR CRUD apps, like being able to find out callsites of a function, and being able to make assumptions about others code (which becomes critical in even moderately large codebases).
> He has a commercial interest in maintaining his guru status.
This. I suspected before clicking that it was a load of hot air, but gave him the benefit of the doubt
I don't know why people regard Robert Martin as any sort of authority. As far as I can tell, he spends a lot of time telling other people how they should program (often needlessly insulting anyone who doesn't do things his way) yet has neither much hard data nor exceptional personal experience working on software projects of his own to support his positions.
2. Uncle Bob is trying to speak with authority, but this subject matter is outside his area of expertise. At least in his previous post, he was nice enough to state this up front:
> Learning swift has been an interesting experience. The language is very opinionated about type safety. Indeed, I don't remember using a language that was quite so assiduous about types.
3. I see that Rust, Haskell, and OCaml were conveniently left out. He hand-waves away other modern languages with "negligible," which is hilarious because he is so obnoxiously wordy in the rest of this post. Not very convincing.
I ask because every functional-language code base I've been able to look at myself has two advantages: 1) it's not very large, and 2) it was made by very smart, experienced developers with a passion for functional languages. When I look at similarly sized OO code bases produced by people with similar levels of passion and expertise, the code base is also very good.
The terrible Java code I've seen, on the other hand, mostly comes from less experienced people whose priorities are things like "keep boss happy", "put in all required hours", and "comply with project plan". Which is, sadly, the average case in the industry.
So I'm wondering: What happens if some functional language becomes mainstream? Will junior programmers at EnormoBank's latest death march produce better software?
But Haskell allows people who know what they're doing to also check that their code doesn't violate certain constraints. That means that the amount of work the compiler does is greater, which makes more guarantees about correctness.
It's not about making the worst code less bad, it's about making the median project take less time and have less defects.
The whole text reads more like one of those "reality shows" on TV with a load of fluff, lots of recaps and very few substance
Then you scroll down and his brilliant conclusion is that Java and Ruby has the same coding efficiency when you do it his way. What a load of crap.
I stand by my assertion: I wouldn't trust Uncle Bob with anything bigger than a Hello World. But if you have an over-budgeted corporate project you may look nice to your boss if you contract him
He does, however, know his audience: mediocre managers of dysfunctional teams.
For those groups - people who cannot themselves articulate the benefits of keeping code organized and testing the important stuff - his talks and books are invaluable.
Can you give an example?
That would postpone the point at which that assembly program reaches 400kloc. In the end, it would probably grow as fast as a C program of the same functionality.
Of course, they also would have to develop their own tooling around that DSL. That, I think is the problem lies with assembly. Higher level languages imply that more stuff gets shared between projects (even across companies; everybody will use the same C language and standard library), and that means time spent to develop tooling around and libraries on top of the shared stuff is useful for more people. Hence, tooling and libraries will generally be of higher quality. that home-grown GUI library built on top of a home-grown set of assembler macros using a home-grown ABI may be better than using, say, QT on top of X11, but it isn't that likely.
On the other hand, the smaller the system, the more important memory usage, and if the system is small enough, that can and will swing the advantage to the home-grown system. That happens less and less, though.
On your own? If yes, then that's pretty impressive. My previous team maintained 350,000-line Perl application with at least 5-6 programmers. If you're handling that C++ system alone, I'd assume it's pretty self-contained, since the complexity in large systems regularly comes from all the other systems that you interface with (at least for the aforementioned Perl app).
Then, past a certain point, most of the new concepts started coming in via frameworks and libraries (although of course things like functional programming and interesting typing approaches are still language-driven tools).
Thus, these days, I would look at libraries and frameworks as sources of new productivity unlocks. E.g. in the Web world, jQuery saved millions of work-hours and qualitatively unlocked some new things. Then Angular (and eventually React) started realizing huge savings from declarative UI definitions. My preference for one next innovation in this area is a higher-level framework for user input modeling (a huge source of bugs these days).
But Java is "uncool". That’s the big issue.
There are tricks using annotations and strings, and Java 8's lambda expressions do help. But it's still awkward to define a React-like mini-language within Java.
Add the fact that you can do blocks, and label blocks, and you can do practically s-expressions.
I was looking for somewhere in these threads to post my comments, and I think this is the right place: yes, you're exactly right, it really is about higher-level reasoning.
Assembly enabled one to think about instructions and operations instead of hex codes. Structured languages enabled one to think about programs, rather than sequences of mnemonics. Functional programming enabled one to think about functional transformations of data; object orientation enabled one to think about collections of functionality grouped with data; both structured the structure, in different ways. With each improvement, we were able to reason at a higher level than before.
But we're not at an optimal level yet: we still do not have mainstream ways to manipulate the structure of our structure (… of our structure of our structure, ad infinitum). We still don't have a mainstream way of dealing with our programs as data.
It may not be mainstream, but we do have a way: it's older than every other programming language other than Fortran: it's symbolic expressions, which enable one to reason about and manipulate one's code as data (and data as code).
The article we're both replying to is a prime example of the Blub Paradox: Uncle Bob can see how Java is better than C++, C, assembler or hex codes, but can't see how Python — and, yes, Lisp — are better than Java.
Next was VB and Delphi - drag and drop stuff on the screen, you could write whole systems in a few weeks. Had wonderful screen painters and so on.
Then the browser - a disaster in productivity, writing things in a tag language - no visual ide support (still).
Now the maximum complication of programming with MVC and languages with so many features no one person can know them all (C++ I'm looking at you, C# and Java are up there though).
I look forward to the next innovation
Visual FoxPro was probably the pinnacle of "easy to make CRUD apps", but the result is, at most, an program that runs on a few computers on a corporate Intranet, that each must use a specific version of Windows with a pre-installed runtime.
A modern LAMP app, despite being composed of layers upon layers of kludges, can be immediately interacted with from any computer in the world, with no sysadmin experience, by entering a URL, and—with no particular effort into architecture or scaling—allows for thousands of simultaneous users to submit changes to the same data in a perfectly consistent fashion with no "whole document is locked for modification"-type problems.
The LAMP app also has a number of modular boundaries that the FoxPro app doesn't: the backend server treats its database as a black box, so it could actually be a replicated cluster, or a different DBMS the next week; the frontend JS treats the backend as an opaque HTTP API, so either of the two could be rewritten or outsourced, and the API could be repurposed by new clients with no additional effort put in on the backend team's behalf; the frontend is built up from layers of specifications (e.g. CSS features) that are each optional, such that you can visit the site from a copy of IE7 on a Windows XP machine in a dusty Korean net-cafe and it'll still let you use the app, just in a less pretty fashion; and so forth.
(And this is ignoring the 10x advantage in accessibility for blind users markup gives over old pixel-blitting GUIs. Modern GUIs are "markup-based" in a similar sense—Cocoa NIBs, Microsoft XAML, etc.—because it's far easier to accessibility-enable a frontend when it exists in the form of an UA-inspectable DOM, rather than an opaque framebuffer.)
If all you need is the paired-Windows-98-machines-in-your-office use-case, sure, use Visual FoxPro (or whatever the modern equivalent is. FileMaker Pro?) You can go even simpler, if you like, and just use green-screen terminals pointed at an ncurses app running on your office machine. But if you need the Internet use-case—where everyone with any tech experience level can use your app from anywhere on any old device, all at the same time—nothing less than the stack of kludges we've got is actually up to solving that problem.
I don't know where to begin with the rest - "whole document is locked for modification" - what on earth is that - and why does the web have anything to do with that, if you mean optimistic locking, then many apps use that.
All the products I mentioned produced a product comparable to a web product - client server enterprise level applications, which could be run over the nascent web (dial ups even - it was done regularly). The complification of modern software stacks has reduced productivity, perhaps your argument is that the use cases addressed by modern applications (web in particular) differs from earlier systems?
It's what happens when everyone in the office is trying to edit the same Excel spreadsheets over SMB/CIFS at the same time. Most "easy CRUD app maker" solutions didn't produce something much better, architecturally, than that baseline. I mentioned FoxPro because a lot of people give it as an example of such an "easy CRUD app maker." Hypercard and Lotus Notes are others. These are the points clustered on one side of the "easy design vs. architecturally-sound product" spectrum.
Delphi/VB are closer to the middle of that spectrum; not quite as easy, but they at least have a concept of "a database" that doesn't refer to a proprietary file format built into the runtime.
The web is on the right of that spectrum: not at all easy, but the product is something that works, in a sense that other apps can hardly hope for. A correctly-architected web-app will work on Chrome Canary, IE6, w3m, a Palm Pilot's WAP browser, the Wayback Machine, several web spiders, IFTTT, as an offline cache, through corporate proxies, with Cloudflare, through Tor, with screen-readers, when printed, with UA CSS overrides for e.g. contrast-enhancement, with any sized viewport, with any sized fonts, and even with people who disable Javascript.
That is the use-case. As you go to the right on the spectrum, you approach being able to solve for that use-case—but it takes a slight while longer to build.
for > It's what happens when everyone in the office is trying to edit the same Excel spreadsheets ...
That really isn't solved by the web either so lets forget about that
> Delphi/VB are closer to the middle of that spectrum...
I disagree - and have evidential support - I have worked on cross platform Delphi products (iOS/android/OSX/Windows) that have a REST backend and what would be called 'web scale' products
> The web is on the right of that spectrum...
Well this is where the argument gathers some steam - when people say 'the web' they usually mean a large blob of technologies from Web browsers to LAMP stacks etc. So can we differentiate these into two components?
1. The web browser
2. The backend stack
There is nothing about their design that should make the backend not handle multiple users or to use something more standard such as sql-lite.
The mobile version would offer half the features of the full version and disable zooming. When you first open the site you get a cookie notification followed by a newsletter subscription notification.
It will be a nightmare to maintain it for longer than a year, because by then most of the JavaScript frameworks it was developed with will have been replaced with newer and better frameworks. With no particular effort into architecture or scaling, it will run out of resources as soon as a few thousand clients try to access it, but elegantly avoid locked for modification problems by displaying a 404 instead.
Delphi remains a well kept secret for one man armies to build desktop apps, even with an IDE that isn't competitive with modern IDE's anymore. My dad used it to build his own patient management software that is competitive in features with the commercial software in that space. The lead it had over competing dev envs back in its heyday was astounding, easy like VB, fast and powerful like C. If it had been managed properly it would still be a major player. Too bad it was managed by Borland.
For example, a seasoned engineer would likely not choose to use PHP for a stateful, socket-based messaging system to connect a dozen or so users. Why? Because PHP is not designed to do that task well. It could do it - you could poll an HTTP end-point and use a cache for really fast persistence to wire it all up - but you'd likely start having to write code around the problems you'd encounter for all of the nuances to your specific implementation.
Yet another example: The main reason Go looks attractive to a certain set of developers is that it solves a problem with describing and handling concurrency that they've had with a lot of other languages. They would be dumb to say that Go is carte-blanche better than PHP (or Ruby, or Java, or even C/C++), but that doesn't mean they won't see a potentially significant improvement in using it.
Have 10000 experienced ruby programmers and 10000 experienced java programmers solve different tasks. I'm pretty sure that rubyists are going to solve their problems using 50% less time with at least 30% less LOC just by the virtue of having a more expressive language. Now I'm not trying to argue that ruby is strictly better than java, I know both languages' deficiencies. However, the metric author uses is development time, and by that metric more expressive languages will always win, hands down.
The point of the post is to show diminishing returns are occurring with ever evolving languages. The argument one should use X language because you can develop in it faster is increasingly not useful to discuss. You are stuck in the weeds arguing X will always win, when the point is there's nothing to win.
How would that be possible without search for the holy language grail?
C is only "absurdly simple" as long as you don't touch undefined behavior, which is nearly impossible in non-trivial programs.
I bet the 10000 Ruby guys are gonna create a big, unmaintainable, broken mess. Even Java's primitive type system would be a big help when it's about software development at scale.
Yes yes, TDD :)
I think Rust and Swift and Elm strike the right balance between developer productivity and a strict type system that actually improves the quality of production software.
Those are not the kinds of problems a type system is intended to solve. Those are problems of data, not of types.
The amount of boilerplate in a Java program is pretty low if you aren't trying to abuse or work around the type system. It certainly is not 10x what you end up with in Ruby or Python. Java 8 has made significant improvements, but it wasn't that bad before in many cases.
Instead of trying to work around Java's type safety, you should learn to use it properly. Good programmers think about types whether or not they are forced to by the language, so the restrictions imposed by Java should not be burdensome -- in general, you should already be mentally applying some of those restrictions to your code so you can avoid passing the wrong types around.
Java's boilerplate comes from lacking type inference and from having a type system that is too weak, not one that is too strong: I'd argue that people's love for dynamic languages without type systems is cause by how people's idea of what types are, and what they do for you, come from Java and old C++, as opposed to something more powerful.
Many people misunderstand the option type in Java. It was created to make stream processing easier. It was not intended for general use, as in other languages.
Regarding illegal arguments, they are unavoidable in any type system. Suppose you defined a function that splits a string into an array of n-grams, to which you pass the string as well as int n. If you pass an n which is greater than the length of the string, no type system will help you figure out what to do. It's just an invalid/illegal argument, and you will either have to decide what to return for that case (maybe an empty array, or even... null), or throw some kind of exception.
https://www.infoq.com/presentations/Null-References-The-Bill...
In Common Lisp if you declare an argument to be a string, it is an error to pass NIL. You have to declare the type to be "(or string null)". That's exactly what the Option type provides.
Please tell me how it works, then. I guess you could easily find a counter-example.
First things first. Optional arguments are handled by &OPTIONAL and &KEY parameters, which can be used to provide defaults values as well as a flag indicating whether the argument is provided. The most used default value is probably NIL. NIL belongs to the SYMBOL, NULL, LIST and BOOLEAN types and their supertypes (ATOM, SEQUENCE, T). If you really want, you can include it in a custom type too. For most uses, the type (OR NULL U) is regarded generally as an optional U. This is consistent with the definition of generalized boolean and lists (a list is an optional cons-cell). If some corner cases, you have to use another sentinel value or use the third binding in &OPTIONAL and &KEY argument bindings. This is hardly a problem if you have a type U such as (TYPEP NIL U), but for most useful cases, (TYPEP NIL U) in fact returns NIL.
Here below I define a function FOO which accepts a string and prints it:
(defun foo (x) (print x))
The type declaration for FOO is: (declaim (ftype (function (string) t) foo))
In Java, such a function will works with null too, because
null is an acceptable value for String. In Common Lisp, you have to write this declaration to allow NIL: (declaim (ftype (function (or null string) t) bar))
And just to test how it behaves,
let's use IGNORE-ERRORS to catch errors and return them as secondary values.
Calling the first FOO with NIL signals an error: (ignore-errors (foo nil))
NIL
#<TYPE-ERROR expected-type: STRING datum: NIL>
;; Does not print anything else
The same test case with the second FOO shows that it accepts NIL: (ignore-errors (foo nil))
NIL
;; prints "NIL"
Lisp being Lisp, those checks are likely to be done dynamically, but in some cases, your compiler can determine if a variable will hold NIL and warn you about a conflicting usage.
However, how type checks are enforced does not change the argument, namely that NIL is not an appropriate value for all types.Break 1 [2]> (declaim (ftype (function (string) t) foo))
NIL
Break 1 [2]> (defun foo (x) (print x))
FOO
Break 1 [2]> (foo "hello")
"hello"
"hello"
Break 1 [2]> (foo nil)
NIL
NIL
Break 1 [2]>
There were no errors. The function accepted nil and printed it. You must have some other type restrictions going on than what you mentioned. The output is the same whether I put the declaim statement before or after defun foo.
(defun foo (s)
(check-type s string)
(print s))
The main point is that (TYPEP NIL 'STRING) is NIL.Regarding illegal arguments, have a look at something like Idris, which has a type system with "dependent types". The Wikipedia page has an example[0]; types can have values, so you can express a "pairAdd" function that accepts two vectors, each vector requiring the same length.
I guess "types" and "compile-time checks" are sometimes used interchangeably. I absolutely think tools (such as compilers) should be leveraged to provide as much assistance as possible; whether that comes in the form of types, or some other mechanism that resembles types.
[0] https://en.wikipedia.org/wiki/Idris_(programming_language)#D...
Idris allows you define types whose definition depends on a value - these are called "dependent types". This allows you to define a type such as "a pair of integers, where the second integer is greater than the first".
So, in your example, you could define an immutable String type that stores its length as a fixed value. Then, you define a function that accepts a String of length "len", and a Num (or Integer) with a value that must be less than "len". The type signature might look something like this (if I understand the syntax correctly):
ngram : String len val => Num (a <= len) => Vect Num StringTherefore, there cannot possibly be a way to avoid the problem I described in my example, unless your program exists in a a closed world where there are no inputs, and the values of all variables are defined before compilation.
This statement is false. I recommend reading about dependent types, which enable exactly what you claim is impossible.
It's true that in every mainstream language, the type system is not powerful enough to reason about types that "depend" on values, such as the type of MxN matrices, sorted lists, prime numbers, etc. But don't limit your sense of what is possible by your experience with mainstream languages; most have rather limited type systems compared to what we know is possible in theory.
The word "total" invokes the totality checker[0] which will report an error if the function doesn't cover all possible cases or cannot be (automatically) proven to not enter an infinite loop.
So, it sounds like if you can't provably account for all possible inputs, the compiler will recognise this and throw an error. How? Magic! (And a solver, feeding your type constraints into the totality checker, I guess...)(Also, bear in mind languages like Haskell use "lazy" or "non-strict" evaluation by default, where values aren't evaluated until they're actually needed; kiiiinda like Streams?)
I'm certainly not an expert on Idris, but I imagine dependent typing provides two benefits:
1) The type signature (which is separate from the implementation; kind of like an Interface in Java) can enforce constraints on your implementation. So, if you define a function with type sig of "Int a => Int b => (a + b)", your implementation must ensure that the returned value is equal to the sum of the two inputs.
2) You can look purely at the type signature to understand what a function is doing. Looking at that type signature above, I can see I want to use that function for addition, not multiplication.
Anyway, I'm absolutely not doing justice to these ideas (mostly because I'm not well acquainted with the languages). If you're curious at all, I would highly recommend taking a course on functional programming as a minimum; once I realised that names are meaningless in code, you start seeing everything as reducible to very similar type signatures, which makes you yearn for a language that lets you write your boilerplate once, in a polymorphic way (beyond generics).
That would make many practical, real-world programs noncompilable. Any program which accepts data via API calls, or even reads strings from STDIN, cannot know what values are going to be passed to it before it runs. Compilers cannot predict the future.
That is a true statement for any program that accepts input, strictly speaking. The halting problem is unsolvable.
The halting problem cannot be solved in general, but some programs can be proven to halt (or not halt). That's how the first few Busy Beaver numbers were found.
For something more substantial: a correct program that implements a regular language recognizer will always halt eventually on any input, because it always makes progress and doesn't have any nonterminating loops. It consumes the whole input and stops.
The hard part is proving you wrote it correctly, but that's what coq et al are for.
Analogous statements are true for programming in a dependently typed language.
nGram : {l : Nat}{n : Fin l} -> Vec l Char -> n -> List (Vec n Char)
To break it up: "nGram" is the name of the function
"{l : Nat}" means l is a natural number
"{n : Fin l}" means n is a finite number smaller than l
"Vec l Char" is the first argument, declared as a
vector of characters, with length l
"n" is the second argument (previously declared as
a finite number smaller than l)
"List (Vec n Char)" is the return type, a list which consists
of vectors of characters where each vector is of length n
For an explanation on how and why this works you can check out these papers:http://www.cse.chalmers.se/~ulfn/papers/afp08/tutorial.pdf
http://www.cse.chalmers.se/~peterd/papers/DependentTypesAtWo...
The first is more about programming in Agda while the second goes into how dependently typed languages relate to logic. Together they provide sufficient definitions of Nat, Fin, Vec and List to declare the nGram function.
If you're unfamiliar with ML-style syntax the above definiton probably looks weird, but can be written in a pseudo-java style like this:
List<Vec<N,Char>> nGram<Nat L,Fin<L> N>(Vec<L,Char> input_string, N n){}[1] https://en.wikipedia.org/wiki/Curry%E2%80%93Howard_correspon...
Dependently typed languages allow for type-level functions (actually they erase the separation between type-level and value-level). This is why you can define a type like "Fin n" meaning a number smaller than n. "Fin n" is a function that takes one argument "n" and returns a type that limits its values to the set of (natural) numbers smaller than n.
Arguably, Agda is more often used as a proof assistant, rather than as a programming language (although I've had the pleasure of watching Ulf Norell implement a limited programming language interpreter in Agda, using non-total functions, which was quite nice.) But Idris is a serious effort to create a language that's both dependently typed and performs decently when used as a regular programming language.
If you want to see some real world examples of using dependently typed languages, I would suggest looking at the CompCert C Compiler[0]. It is a C Compiler that's been formally verified using the Coq proof assistant, which is a precursor to both Agda and Idris. Coq is as far as I know the first dependently typed language.
To be fair, programming in a dependently typed language usually requires more effort upfront, but the ability to encode properties that are usually considered runtime errors into the type system does seem like an interesting future for programming languages.
[0] http://compcert.inria.fr/compcert-C.html
(edit: shout out to the excellently named sibling commenter "curryhoward", IMHO one of the most interesting results in programming language technology and type theory research!)
Go for example, half-straddles this world too.
I can half-see the benefit of being able to know if something produces an error term (annoying in Python when you're trying to be thorough with exception handling) but conversely there's so few situations I encounter where a function can't error that it's practically irrelevant - what does it matter to me that some set of functions can't throw, if every bit of IO, network and disk before them can and will at some point?
I hope you can see how this is pretty much the same as checking if a variable is null. It takes just as much work, and has the same outcome.
This means the language allows you to define areas of your program that are null-safe, and areas where nulls are expected.
Compare to languages where you must remember to check null on every use of a null variable. I guarantee I can pick any Java codebase and find a method where arguments to that method, or a class's properties, are not checked for null on every use. How do I know that the use is safe? Usually by coding conventions; maybe immutable instances represented by values set only in a constructor, although what's to stop null being passed in?
In cases where the value could be missing, the type is change to Maybe and the caller is forced to handle the null case. They can still avoid explicit checks using various combinators (>>=, fmap, liftA2 etc.) which propagate empty Maybe values. Explicit matching on Maybe is fairly uncommon in languages which support it.
1. the large number of values that you now know definitely have a value, and you can access without fear that they don't.
2. the helper functions for Maybe that let you deal with optionality in various ways; the possibilities are extensive and useful. null doesn't give you any help, and generally any helper syntax is limited to one or two possibilities.
3. Code cannot fail due to trying to access a null pointer accidentally. Functions that definitely return a value (ignoring severe issues like OOM, etc.) is a somewhat useful property.
Let’s say your application tracks users, and each user needs to have at least one address. On top of that, they must flag one address as their default address, which is used when sending them formal communication, but usually they can pick which address they want to use. (Most people have one address which is their default).
The Java code to pick out a user’s default address is simple enough:
class User {
// ...
public Address getDefaultAddress() {
for (Address address : getAddresses()) {
if (address.isDefault()) {
return address;
}
}
throw new AssertionError("User has no default address");
}
}
We throw an AssertionError here instead of returning null because if a user has no default address, then that’s a bug in the program, and we want to fix it. And because it throws, we can safely assume that any address coming out of getDefaultAddress is not null.Then one day we receive a change request from a client. Some users move around a lot, and have no permanent address, and they’d like it to be changed from at least one address to at least zero addresses. Basically, make it so users don’t have to have an address anymore.
How does this affect our getDefaultAddress function? It has to handle the case where users have no addresses, because if that’s the case, then they’ll have no default address, either.
The easiest way to do it is just return null instead:
public Address getDefaultAddress() {
for (Address address : getAddresses()) {
if (address.isDefault()) {
return address;
}
}
// no default address
return null;
}
With this in place can no longer assume that the Address returned from getDefaultAddress() is an actual Address object. Which means that all the code we’ve written so far -- the code that assumes that the method doesn’t return null -- will break. So we have to find every place in the code where this method is called, and make sure that it does a null check. IDEs can help here, but they can’t help with developers who hadn’t noticed the change and continue using the method in the old way, or places where the method is called with reflection... and do you really want to test every call site to make sure you’re handling it correctly?Or we can use Optionals:
public Optional<Address> getDefaultAddress() {
for (Address address : getAddresses()) {
if (address.isDefault()) {
return Optional.of(address);
}
}
// I know I could use Java 8 streams here, just go with it :)
return Optional.empty();
}
The Optionals aren’t the most important part of this example -- it’s that the method signature changed. Our program will now no longer compile until each and every place in the code that gets a default address has been updated to specifically handle the case where there is none, because the compiler won’t accept an Optional<Address> where it expects an Address. A developer who hadn’t seen the change won’t be able to use the function in the old way by accident, as it won’t compile.This is precisely what happened to us. Changing the method to return null resulted in lots of breakage from code that we forgot to add null checks to and code written afterwards using the old signature by accident. Changing it to return an Optional meant we were forced to update everything, otherwise it wouldn’t compile. No runtime bugs. No developer slip-ups. That’s why I’m in Team Optional.
You might say: but IDEs help with boilerplate! True to a point. Someone still has to sift through the tons of unnecessary generated LOC crap just to get to the issue at hand.
Again, I'm not writing this to bash on java, I'm simply trying to show that search for "holy grail of programming languages" is far from fruitless, and it fills me with joy when I see more languages being developed and tried in different niches (clojure, rust, go, elixir — these are all different and awesome at the same time).
Yeah. IDEs may help with writing boilerplate, but most of the time you're not writing code - you're reading it. And every small bit of boilerplate Java adds pretty much everywhere (and C++, and C#, and other similar languages) is a bit you have to read, parse and decide if it's relevant. It obscures the meaning the code was supposed to express and make understanding the code a much more cognitively demanding task.
(IDEs could help by detecting and folding boilerplate, but if they could do that, then why not just write your code in that folded-boilerplate language directly?)
And the solution is goint to be at least 10x slower than the java one.
Even if that was true (there are many ways to make ruby/python faster), who cares? Hardware is like 1/100 of the cost of an engineer. Use more/better hardware, and problem solved. Optimize for your most expensive resource. Sure maybe 20 years ago that was processing time, but now in days your end user can't tell the difference. I mean does 10ms really feel any different from 100ms? Not really.
(OK, there are some times when processing time DOES matter, but that's the exception, not the rule. No premature optimization please)
Fair enough, but development time is a small factor in the life of an important project.
If you want to prototype and get your minimum viable product out the door, go ahead and use dynamic languages. You'll probably end up rewriting it later, but that's a tradeoff you have to weigh. It's a viable approach taken by many startups.
On the other hand, if you are working on a project that will live for years, you will be more concerned about maintainability, adaptability to changing requirements, interaction with other services, quality tooling, and runtime speed than you will about the time it takes to write the first release version.
I work with 200+ other developers using JavaScript (90% codebase approximately) on daily base developing a SaaS product...
To me, the reference standard is assigned unity.
In the first case, X is 1.00 and Y is 0.70.
In the second case, Y is 1.00 and X is 1.30.
> I need a number
> The number?
The article places annoying attention to quantifying "workload estimates", whatever that even means. Because the written interview is so verbose, we know that the author just brushes away the interviewee's remark that 'other important factors effect that workload', and then proceeds to cryptically dance around those factors with very opinionated questions.
But even more noticeable was the loads of the ability to play around with each little block of code, with data in-memory, until I was completely happy with it. It's a bit like interactive debugging, but with a great deal more freedom. As a result, I get a huge reduction in mental load when writing Python in a notebook; my attention is extremely focused on the little bit of code in working up in that moment. This is a real win for productivity, beyond what you get from the zero compile time.
(Also, Java compile times are not zero. Even waiting a minute for a large compile is enough to create a break in concentration.)
If you program Java then please feel free to use the excellent tooling that is available.
"Type A" coders are especially vulnerable to this kind of habituation on account of often being interested in esoteric languages, systems programming, or other "extreme" environments with tooling restrictions.
The trick usually is to test often and don't write something if you don't understand how it works - that also includes interacting with parts of your application that you didn't write - and to not proceed if you feel you don't understand how the code you wrote works. 99% of the time when I have a bug in my Java code I realize where the bug is before my window manager switches over from the program to the IDE. That comes simply from understanding what one wrote (+ a bit of experience).
That said, debugging multithreaded programs is a pain in the arse, and I take any help I can get there. Though I haven't seen many debuggers that would be helpful in those cases.
Interactive debugging is fun in Lisp, where you basically code interactively all the time and code/debug phases are pretty much blended together (just like compile/load/runtime is).
I can't think of a single task that's easier with print statements vs a basic breakpoint debugger. And if you include fancier debugger features like reverse step, code injection and moving the instruction pointer, debuggers win by an order of magnitude.
People generally ascribe the rise of Web 2.0 to AJAX, and while that's part of it, what really made Web 2.0 possible was Firebug delivering a useable debugger for Javascript, so complex AJAX apps could actually be created.
I don't know how you define "large," but I work on Java projects that have several thousand classes and compile in less than a minute. Maybe you have a slow computer.
* In assembly language, the design pattern might be the function (a published interface for a common block of code, and a well-defined protocol for getting data into and out of it).
* In C, it might be the basics of C++'s object-oriented programming features: single inheritance at first (have your parent class be the first member of the structure, then cast to whatever level you need), followed by vtables.
* In C++, it might be 'interpreter' or 'visitor'. Lisp macros make building DSLs a lot easier (see something like LOOP for a basic example), and CLOS' multiple dispatch nearly obviates the visitor pattern.
I'll agree with the article, though, that most languages are settling on the same norms, mostly borrowed from the functional world. Swift, Rust, C++, and Java are all gaining most of these: making it easy to avoid nulls safely, pattern matching, parameterized types, method chaining over explicit loops, and a non-dogmatic preference for immutability over in-place modification.
Interpreted vs compiled is indeed a major difference, but I feel like focusing on the compile time difference doesn't account for it or adequately summarize, there are significant mentality and workflow changes.
Bob might be right that we're approaching negligible differences in programming languages, but I hope not, and I'm not at all convinced. It seems like the introduction of new useful concepts into mainstream languages is accelerating right now. And I expect to see huge advancements in programming soon that leverage today's huge advancements in AI & natural language processing. I think it's within our reach to be able to describe to a computer what our end goals are and have it figure out how to put together the pipeline to get there.
I'm surprised he didn't mention, in addition to compiles times changing, that editors and environments improve dramatically. (I guess he alludes to punch cards, but still). And they can affect whether one language or another is an improvement (for instance, Java with is stricter types really benefits from an editor that can do autocomplete, in my opinion)
I do think that most technologies follow this sort of progression. I mean, if I go buy a new computer now, it is going to make me incrementally more productive. I'm 52, so there was a day when I was buying a computer to replace a dedicated word processor (i.e. a typewriter with a tiny amount of memory and and small LCD display), and it was a dramatic improvement. As was the word processor compared to a plain old typewriter. I don't expect that kind of drama when buying something to type on now. Things are slightly more dramatic with touch screen devices, but that is starting to slow down. Other things, like a dishwasher, even less so.
I hope something interesting will speed things up again, but I expect it will be like what happened with phones and tablets coming in and replacing many functions of old-school computers for so many people. That is, a new way of automating computer behavior that doesn't mostly come down to editing text files.
As an example, a technical person could train a humanoid robot arm to wash dishes by talking to it while the robot mirrors the motions of the trainer's arms. Is that programming? I'm not sure, but when we start seeing more of that sort of thing, and it increases in sophistication, I would expect more of those big jumps like moving from binary to assembly.
It has always seemed to me that the story of improved programming environments is driven more by improved hardware than improved software, and that companies like Microsoft/JetBrains are the only ones who've even bothered to wonder if its possible to create a better environment for programming than "arcane text editor."
People are always saying "Look at me I can write a web server in six lines of code." No, you can call a web server library that someone wrote for you in six lines of code.
Aftbit (some place in this thread) has a good point, some languages are better with some subject matters. I'd like to also posit that some languages have better libraries written for a subject matter which makes it appear they are better for that subject. We've seen lots of people port libraries to a different language to help them.
While I do agree that some languages give you a boost up because the compiler is doing some heavy lifting in the background, it's the huge collections of libraries that we can call that lets us stand on the shoulders of giants.
(Right now, we have to explicitly embed one runtime into another, creating programmer's turducken, if we want anything close. This, though, is an artifact of the way we think about efficiency as requiring address-space cohabitation. And while it's easy to set up a runtime-heterogenous melange using IPC, the default for that is inefficient serialized streams on sockets. Where's my zeromq-like zero-copy message-passing IPC as a batteries-included part of every runtime? Where's my binary wire-type-encoding standard aimed at producing "toll-free-bridged" native types in multiple runtimes? Where's my "managed" OS with malloc-time kernel-side type-tagged memory-buffers[1] that all runtimes for that OS support loading? Where are my multi-runtime application servers with jail/lxc-like application domains to isolate mutually-untrustworthy clients?)
[1] Speaking of, whatever happened to capability-based operating systems? Hardware support for capabilities would basically let us get rid of the "process" abstraction altogether, and just have a big OS-wide heap with various units of concurrent execution holding capabilities on various memory-objects.
"Alexa, write me an API for this $5 wifi enabled light on my desk that I soldered together yesterday."
It was then that Alexa began to plot our demise.
It shouldn't be too hard to learn a bijective mapping between your style and everyone else's style. If we're still using IDEs in twenty years, I'd expect this to have been done by then.
No, we are not at the pinnacle, because programmer speed (as he very well knows, because he keeps on putting those objections aside) is not the only thing that matters.
[1] http://martinfowler.com/bliki/CannotMeasureProductivity.html
With JS the stdlib train already left With C++ I doubt we'll see a nice module system and package repo similar to Rust (because we staple more legs to the dog in the name of backwards compatibility instead).
We invent new languages not merely because we want a better language but because we want a better ecosystem, and each language gets just one or two shots at getting it right.
Rust is aimed at C++ (and others) and offers a saner module and dependency system. It might seem like a crazy idea to offset C++ in the systems programming space - until you realize that it seems easy compared to adding modules to C++.
C++'s standard library goes beyond C's. Java's standard library goes beyond C++'s.
Then, having a standard library is necessary for compatibility. e.g: in C++ you can go and use something like Boost or POCO but then they might not play well with each other and you will need some glue code.
Those "glue code" problems are extremely time consuming.
Let's say I work exactly 40 hours and week and 50 weeks a year. Then a 5% increase in efficiency means that I can do 2 extra weeks of work per year. That's not a lot, but on a team of 26 programmers that's essentially the equivalent of hiring a new employee (without the downsides of a bigger team and the cost to bring someone up to speed).
Two weeks per year. Sheesh.
C, C++, Java, Smalltalk and Ruby are all high level languages. Assembler is, well, assembler and machine code is machine code. Those are three steps in the evolution of programming languages not seven. The differences in - whatever metric - between high-level languages are negligible compared to their differences to assembler using the same metric.
I guess that's what the post concludes in the end but it gets there in a bit of a strange way.
Also - does anyone seriously consider those vague metrics when making a decision of what language to choose? "How much does my language improve productivity over Java"? Pragmatically speaking, either you 're in charge of your project so you choose the language that seems to offer some advantage for the targeted platform, or you're not so you suck it up and code in whatever your shop uses.
Compile of a single class yes, but most J2EE projects I worked on compile between 10-20minutes including tests. Sometimes longer, a lot longer...
While writing code in some languages is slightly faster than in others but most probably by less than a factor of 2 (provided you're using the right IDE and know what you're doing).
The increase in productivity we can achieve is "standing on the shoulders of giants": ie. assembling / wiring together pre-existing bigger and bigger pieces of code we can trust and know how to use. Also more and more problems are solved and in public domain.
IDEs usually These days
— Sure, if we’d not only consider machine architecture, language design and compile times, but add social factors to the equation, like ecosystems, business models, and network effects, well okay, then maybe a single, apprentice developer might do the work of a 100k MSc programmers, and at least as much as he `require`s modules. :-p
The BIG differentiator is how a framework handles the write-compile-run-debug cycle.
Rails is very nice in that respect.
When I was doing a lot of java I'd run the server in debug mode, so eclipse could hot-swap code. Cycle was instant compared to a few minutes
As for the "productivity" examples of 5% and 10%.. That's way too little.
I tend to switch back and forth between Java (at work) and Lisp (after work), and the workflow in Java annoys me to no end. It's so much easier and faster to write when you can compile-in new functions, methods and classes (or hot-swap existing ones) in a running program, while inspecting it at the same time. It's hard to go back from the convenience of having write-compile-run-debug cycle all blended into one.
Or you can try something like https://github.com/HotswapProjects/HotswapAgent, that is a modified JVM that supposedly (I did not try it yet) does the same, and it is open source.
Just unfollowed him in Twitter - it's not the first time I read such low-quality narcissistic "dialogues" in his blog, only because in past he had high quality book about clean code.
"It's kind of complicated..."
"I need a number."
"I'm not giving you a number."
"Why not?"
"Ask me an intelligent question and I'll give you an intelligent answer."
"What??"
"On the day we use horsepower as the sole measure of a car, I'll give you a sole measure of a programming language."
The point the author raises about types is only partially true. Both in Java and Python you should be unit testing your code. If you have good test coverage and CI than it really doesn't matter that Ruby and Python don't check your types.
So blue is my color :)
People say this a lot, but it's not true unless you have 100% coverage, 100% control over the data that gets input into your program, and you can think of every possible test case that covers every possible situation that can occur.
Many of the tests you have to write for programs in dynamic languages are simply not necessary for strongly typed languages.
Furthermore, compilers for static languages catch (or warn about) a lot of problems that would otherwise have to be reproduced by the kinds of test cases nobody is likely to think of -- this results in bugs making it to production when you use dynamic languages.
This is different from static typing, how?
> Many of the tests you have to write for programs in dynamic languages are simply not necessary for strongly typed languages.
Actually, dynamic typing users write very few additional tests. Users of static typing seem to imagine a lot of additional tests being needed, but dynamic typing users don't write them. They are usually for scenarios that are important enough to test.
> Furthermore, compilers for static languages catch (or warn about) a lot of problems that would otherwise have to be reproduced by the kinds of test cases nobody is likely to think of -- this results in bugs making it to production when you use dynamic languages.
Not my experience. Almost all bugs caught by static compilers are ones that a single execution of the relevant code would also catch.
As a matter of fact, I have developed applications in Python, C++, Java, Javascript, GWT, Javascript, and Coffeescript, for myself, at small companies, and at Google. I don't think you can simply dismiss me as having limited experience unless you've got more extensive experience shipping apps written in both dynamic and static languages.
Now, I'm not saying that dynamic typing is better: there are tradeoffs to either approach. But I am saying that your original post gives an overly simplistic appraisal. The pros and cons of static and dynamic typing and much more complicated then that.
I built a computer with TTLs back in the early 90's whopping 256 bits of ram. but it was programmed with switches. it really doesn't take that long to memorize the states. To be fair, i never had to toggle switches for work. there might be other factors i'm neglecting.
The problem is like Carmack said, errors are depressingly statistical. you'll inevitably fat finger one of those switches, and everything sucks.
Now, if i have a terminal, and can type the program into a file, things are a little different. but mostly, i just don't want to wear out the 0 and 1 keys. with a 4 bit encoding, i don't think there's really that much win with mov vs 0f. with a 5 bit encoding i'd have 32 keys to play with, and could probably type my intentions very quickly, with some practice. heck, you can sling bf pretty quick if you spend a week encoding something hard. The big thing is variable names are chosen for you - instead of 'money' you have 0x0128 or whatever.
A symbolic assembler buys you variable names. That's a pretty big win when you get more than, say 100 variables and functions. Small programs, no biggie, you can keep it in your head. Things get bigger it gets tough to memorize everything. So clearly the benefit grows as programs get larger. But i'd be skeptical of even 30% on front panel switches. In an editor? If i can use emacs, i can probably set up syntax highlighting for instructions and arguments. Play some goofy game with variable names in comments an have emacs auto manage synching the comment and memory address. so i'm not sure it would be a huge win then.
The big wins (for me) with C are total insulation from register <-> memory moves and stack discipline. this is a WAY bigger deal than binary vs symbolic. you can call any function you want without having to remember what registers this function will stomp. But i've never tried to toggle in C on switches. I can say, i get more done in C than assembler, but that's not claiming a whole lot.
C++ vs java? Well, valgrind helped me a lot with c++. java means never running valgrind. That's not to say, i haven't had my share of NPE's in java. Java just tells you where it happened rather than crashing.
Once you know what you want to say, You want to say that concisely, to minimize those statistical errors. IMHO I can be more concise with a higher level language, so those statistical errors don't bite as often. If i have 1 bug per 100 lines of code, i'd rather write in the more concise language. But i have upper limits to concision. APL is too hard.
Which is one valid viewpoint. But he couches it in the socratic method against a strawman (presumably himself) which ultimately leaves the reader feeling dirty.
So if someone were saying to me "stop developing new languages and environments; it makes things hard", it'd be like saying "stop developing new culture or human relationships, because life is easier when we're all bland and homogenous." I find it a little bit offensive and at least a failure to recognize the important problems (due to obsession over the easy ones.)
So, to simplify, I think the reason a lot of developers roll their eyes at another new language is because the problems the languages are solving are less important than the fracturing they make in the engineering community.
If you think a language is missing something, why not contribute to the language with an RFC. C++, Java, and PHP have all been advancing significantly over the years. Or why don't you get together with 100 other language-makers and come up with a unified solution?
The problem is still in understanding what the words mean. It's easier if you have standard languages that everyone speaks, but if you want to have computers do amazing things, they'll have to be able to handle that problem, regardless of how many languages exist.
And it would be wonderful if computers could learn to understand languages regardless of who designed them and why. That problem isn't going to be solved by running away from it.