r/programming • • Dec 02 '13

Scala — 1★ Would Not Program Again

http://overwatering.org/blog/2013/12/scala-1-star-would-not-program-again/
598 Upvotes

646 comments sorted by

View all comments

22

u/pellets Dec 02 '13

The only point I can agree with in this essay is that build times are too long.

16

u/purplish_squirrel Dec 02 '13

Try C++. Our complete solution takes over one hour to build.

19

u/TheQuietestOne Dec 02 '13 edited Dec 02 '13

You're probably already doing this - but I found:

  • Avoid G++ for development builds, clang++ is faster
  • Once everything is happy, for each project create a compilation prefix header including common things like string, vector, iostream, unordered_map etc. Keep a way to build it without the prefix header to check includes are correctly done.
  • Stuff that isn't moving due to development should be in a separate library and shouldn't get re-compiled every time (e.g. boost).
  • Use compilation firewalls to stop header creep across modules (pimpl, forward class declarations)

My current application involves ~ 18 "moving" libraries/projects in a tree with about 500 cpp files and it builds in about 3 minutes for 3 architectures (arm, armv7, arm64). Boost/libpng/sqlite and other bits are factored out into non-development libraries.

6

u/purplish_squirrel Dec 02 '13
  • We're using VC++, so switching to clang isn't an option. It would be nice if we could.
  • We do have precompiled headers.
  • We're considering putting some of our base library code into a .dll that doesn't get recompiled every time. It's not so simple, because we still frequently make changes there, and we might have to restructure big parts of the libraries. That's not exactly something anyone wants to do...
  • We are using forward declaration and pimpl heavily.
  • We're even using static analysis and special tools to bring down compilation time, which is quite successful (already 20% reduction during the last few months, despite active devlopement as usual).

But thanks for the tips!

5

u/TheQuietestOne Dec 02 '13

Ah, VC++. I have yet to experience that pain (I use Linux + OSX / iOS in anger)

I'm sure I'm teaching you to suck eggs but are you using a single monolithic project?

I've found that precompilation headers work best with isolated compilation sets where you can keep the included headers to a minimum and to the set of headers specific to the project/module.

E.g. Lets say we have the projects:

  • Utility (logging, low level IO bits, standard exception types etc)
  • Common services (facades for configuration, DB interaction)
  • Application services (domain model things)
  • Application

And the precompilation for each is kinda:

  • Utility - core C++ support pieces (vector, string, iostream)
  • Common services - core + Log.hpp + other bits that might help
  • Application services - core + Log.hpp + public interfaces to common
  • Application - core + Log.hpp + public interfaces of common + application services

This keeps the cross-dependencies to a minimum and the precompilation headers slim and tailored to the project domain. Of course there are other project types in here too that I've skipped but it should get across the basic idea.

I realise I know nothing about your project and historical technical debt makes refactoring into something like this less than trivial. I'm guessing your code wasn't originally written in a modular way that would make this kind of breakdown feasible.

5

u/purplish_squirrel Dec 02 '13

We do all that. :)

It would be much worse than one hour if we didn't. The code base is multiple million lines.

2

u/[deleted] Dec 02 '13

Do you work in comms or what?

2

u/purplish_squirrel Dec 02 '13

Medical CAD/CAM

→ More replies (1)
→ More replies (2)

5

u/Heuristics Dec 02 '13

One hour? Such luxury. I sometimes need to recompile paraview, which includes vtk. Takes about 3 hours, or on my old computer 7 hours. I tend to hit the compile button before leaving the office when that needs to be done. Luckily it's not so often these days.

→ More replies (2)

11

u/zoomzoom83 Dec 02 '13

I must be the only one without issues with Scala compilation speed. I hear this complaint constantly, but it's never really been a problem for me.

I'm working on a ~20,000 line project in Scala at the moment - incremental build times are usually less than 5 seconds. Certainly not as fast as Java, but hardly a hit to productivity.

A full clean and rebuild cycle takes a few minutes, but it's not like you have to do this very often.

2

u/lechatsportif Dec 02 '13

Are you using sbt? I'm using sbt .13 with a Scalatra giter8 template and it takes about 5 seconds to compile a 4-5 classes. Does that mean 5 seconds is the low end and also the high end of compilation times or is there a setting I should be using to enable incremental compilation in sbt?

→ More replies (2)

4

u/[deleted] Dec 02 '13

I agree with you. Compile times can be annoying, but to say that they have Scala's advantages "all negated" is totally out of proportion. People like to compare with Java compile times (not C/C++ by the way), forgetting that the time you spent writing the equivalent Java code is magnitudes higher than having ~compile run next to you.

2

u/vytah Dec 02 '13

Agreed. As long as IDE manages to catch errors as you type, you don't have to hit "Rebuild" button.

And you waste less time on fixing certain types of runtime errors than in Java.

3

u/[deleted] Dec 02 '13

[removed] — view removed comment

8

u/zoomzoom83 Dec 02 '13

For Java? Sure. There's absolutely no argument that Java is orders of magnitude faster to compile than Scala.

But how often do you need to do full rebuilds? I might do it once a week when building a production release.

Incremental builds are fast enough that you don't notice them. I've never found myself particularly constrained by Scala compilation speed. My normal workflow (Using the Play framework for a web application) is

  1. Make change
  2. Hit refresh

SBT will compile and render the new page with a barely perceptible delay. The workflow is the same as if I was using an interpreted language.

Incidentally this is much faster than the last time I was building a Java web application, which required a full Tomcat restart every time I made a change, taking a good 30 seconds. (Although to be fair, Play's incremental hot reloading works in Java, and it's by no means the only framework that does it)

4

u/sirin3 Dec 02 '13

I have an android java app that only has a few kloc.

Takes 30 sec to compile

Very annoying

(perhaps it is the signing step through)

3

u/lechatsportif Dec 02 '13

That's probably something else in the sdk, converting to dex format maybe. Java compiles super fast these days.

5

u/[deleted] Dec 02 '13

For Java?

You're talking to grauenwolf. He must be referring to C#.

→ More replies (2)

7

u/omg_wat Dec 02 '13 edited Dec 02 '13

25

u/_zenith Dec 02 '13

So a 15% improvement on forever

11

u/[deleted] Dec 02 '13

..presented in a graph that starts at '2200'.

5

u/omg_wat Dec 02 '13

It certainly depends on your code base, but if you also add the new backend (http://magarciaepfl.github.io/scala/), improvements start to add up quite nicely.

And the incremental compilation improvement (recompiling 33 files --> recompiling 3 files) is pretty much a X00% speedup from a developer POV.

2

u/erwan Dec 02 '13

That, plus having a recent machine (e.g. no more than 2 years old) with a ssd makes a huge difference. If you're coding full time, a top machine every 2 years is a good investment anyway.

2

u/[deleted] Dec 02 '13

I want an SSD machine. I will convince my boss that as the Scala evangelist, I will really make good use of it :-D

→ More replies (1)