1

I have some (or just a little) experience in writing web application backend with interpreted language, php, python and javascript (node js). When writing the backend app, usually what I do is write some code, see the result on the browser, if anything wrong fix the code, see the result on the browser, and then add some code. Because it is interpreted language, the changes will be available immediately.

Now, about go language which is compiled language. If the code base grow very large, may be more than ten thousands lines of code, the compile time will take very long to be done. So, the development workflow like I mentioned above will not efficient anymore because changing code take times to compile.

Yes, I've tried go, just tried with some a few of code and of course it just take around a second to compile. But, I want to know what to do if code base grow very large. How the development workflow will be?

  • 1
    Learn how to unit test (for many reasons). Then learn how to use your tools in the way that they are the most productive. Visual Studio has incremental compiling during debugging, so you can change a line of code on the fly and re-execute it, without having to recompile the entire project. – Robert Harvey Jun 23 '16 at 17:58
  • 3
    more than ten thousands lines of code, the compile time will take very long to be done - you should try first. I haven't tried Go, but assume that compile time of 10K+ LoC may be faster than launching heavy PHP app without caching. – scriptin Jun 23 '16 at 18:02
7

I work on a code base in a compiled language (Scala) which is tens if not hundreds of thousands of lines long. The first thing commonly done in such situations is to break the application into microservices that usually max out at two or three thousand lines of code each, spread out among maybe 50 source files. Many are much smaller.

Next, as others have mentioned, you use incremental compilation, so you are only recompiling a handful of files each time, not the entire project. This compile time is generally under a second. Clean builds are reserved for continuous integration servers.

Third, on projects of this size, you very rarely open a browser to test, at least if you're not a UX designer, and most of the code of the largest projects is in the back end. My quick cycle tests are all unit tests, which are absolutely critical to maintaining continuous delivery on a project this size. If I exclude integration tests, I can usually do a write/compile/test cycle in 5-10 seconds, and that's tests for the entire microservice, not just the small part I'm working on. It's faster if I limit it to only the class I'm working on.

I know that's faster than a write/browser refresh/manual test cycle, and my unit tests are testing way more things with more accuracy than a human can. It should be to the point where your unit tests are so good, you work in them all day, then have a good set of automated integration tests, and checking it manually in a real browser is just a formality before you push your changes.

In other words, your workflow isn't inefficient because of the compiler in the loop, but because of the human in the loop. As your code base scales, that's what you have to take into account.

1

There's a widely used tool for Java which allows you to reload classed on the fly when they are recompiled. I've used it and it's reliable for the kind of thing you are talking about. Combine that with an IDE that compiles each class on saving (faster than I can blink,) it's basically just like what you describe. I don't know if anything like that exists for Go but it's been done for compiled languages.

  • Is java compiled language? I don't have any experience with java but I heard it's an interpreted language which is run in a virtual machine (jvm) just like node js which is execute javascript code inside v8 virtual machine. – Mas Bagol Jun 23 '16 at 17:07
  • 1
    @MasBagol: Java "compiles" down to Java byte code which runs on the Java Virtual Machine. Don't confuse Java with Javascript; they're not the same thing. – Robert Harvey Jun 23 '16 at 17:12
  • It runs on a virtual machine, yes but the VM runs what is called 'bytecode' which is basically a virtual machine language. If what you are asking is whether a language that compiles to machine code could do this. That's probably a lot harder to pull off (not that it was easy in Java.) – JimmyJames Jun 23 '16 at 17:15
  • @JimmyJames Yes, what i'm asking is about the language that compiled to machine code. That's why I mention go. Because I see it somewhat like C/C++ in term of compiled language. – Mas Bagol Jun 23 '16 at 17:21
  • @RobertHarvey I understand the difference between java and javascript. It just like car and carpet :). May be my question is not clear, I'm asking about compiled to machine code. – Mas Bagol Jun 23 '16 at 17:24
0

Go's niche is really back-end services. While Go can certainly run your blog, its targeted purpose is to do the heavier lifting on the back-end where the design and coding part of the development cycle is typically more involved. So the 'inefficiency' of waiting for the compile isn't a big factor.

Plus, there's some perspective involved. The code-compile-results cycle of Go is slower than PHP, but on the other hand, is significantly faster than C++.

0

Not compiling everything after changing a single line in a single file is a big part of how we keep compile times low. This is partly what makes build management tools like Make or Gradle so much better for this than general purpose scripting languages like Bash or Groovy. That is, Make and Gradle provide easy syntax for defining dependencies, whereas Bash and Groovy do not. Instead of recompiling everything, we recompile only the things which changed, and the things that depend (directly or transitively) on what changed.

  • Why are you giving Bash as an example of “recompiling everything”? – Arseni Mourzenko Jun 23 '16 at 18:00
  • @MainMa I'm giving Bash as an example of a general purpose scripting language that could be used to manage building a C program, but which would be much less convenient than Make. – 8bittree Jun 23 '16 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.