If you read my previous post you know that I came from a Microsoft only world and so it should be no surprise to you that I actually struggled to make the switch to Ubuntu at first. I mean the only tool I really needed for my programming needs was Visual Studio. I may have installed some new libraries that were necessary for my projects (SDL2, GLEW, …). But everything else was just always there, and it worked. I pretty much never used other IDEs. If I could use Visual Studio, I would. The thought of leaving Visual Studio behind seemed insane to me. I started to panic. And like all people who start panicking I did the only thing I could think of: search for an IDE that is as close to Visual Studio as possible. It’s not that there is a shortage of programming environments out there: Code::Blocks, Geany, Aptana, Anjuta or Qt Creator. Just to name a few. But there was one thing that really stood out for me. Something I was not expecting at all. And thinking back now it seems a bit silly that I was so stuck in my ways and that I really thought I needed a Visual Studio replacement. How about no IDE at all?
I can hear a million voices screaming right now and probably a few of them just fell out of their comfy chairs while doing so. But let me try to explain how I got to this point. I got the idea to go without a complete IDE after I discovered how Ubuntu and other Linux distributions work. The first thing that was actually pretty new to me was the fact that there is already a default compiler installed on the system. All you have to do is write something along the lines of
g++ myFile.cpp into the terminal window. I thought that was pretty cool. Then I wondered: But how can I get other libraries like SDL2 installed for example? Well this was another revelation for me because it could be answered with the same phrase that probably answers every second Linux question on this planet: “Use the packet manager to get what you want!”. So instead of dealing with a webpage download, unzipping a file, searching for the right folders, putting it in the right path and then tell my IDE where the hell this library is installed, I just had to do something like
apt-get install libsdl2-dev. No worries afterwards. This was the defining moment where I begun to ask myself what exactly is the IDE doing for me? What are the essential parts? I came up with this small list:
- Keeps files bundled in a project hierarchy
- Helps me in typing and editing my code
- Shows me possible errors while typing the code
- Compiles and links the code and gives me detailed error messages if something went wrong
- Debugging my code with useful data
The list could possible be a bit bigger depending what you do. For example I mainly write code that does not need a GUI Window so I did not put a WYSIWYG editor on the list. Although most of the modern GUIs are written in a descriptive language anyway so I think a WYSIWYG editor is not really necessary. Compiling, linking and showing error messages is the part that already got covered with the pre-installed compiler. Also a project hierarchy could just be a simple folder structure. And that is something every basic file browser can handle. This left me with three things: editing code, debugging and showing errors and information while typing.
The first thing I searched for was a nice text editor that could open multiple documents, had syntax highlighting, lots of editing short-cuts and it would be nice if it also was extensible through plugins in case it was needed. And all my searches pointed me to Sublime Text. And oh my goddess what an fantastic editor that is. I highly recommend you take a look at it for yourself. It has many editor features, out of the box syntax highlighting and it even could open folders and treat them like a project tree. And after I found the Package Manager, in which you can extend the editor features in a very simple way, I fell deeply in love! The only thing that is a huge let-down is that code completion and syntax watching is not supported. There are some extensions out there but neither of them do a really good job in my opinion. But not having code completion at hand has certainly helped me to be more focused while writing code. Still there are these moments where I wish somebody would have told me that there is a semicolon missing while I wrote the code… and not in the middle of a 15 minute compiling session.
The last item that was missing on the list was the debugger. And I heard many horror stories of debugging code on Linux. Of clunky command line debuggers where you have to read a 500 page manual to get the basics going or that you have to use an IDE after all because they have the only decent and easy to use compiler in them. But I searched a bit more because at this point I wanted to see if there was a way to really go without an IDE. And that brought me to the Nevimer C/C++ Debugger. An excellent debugger that does its job and is actually really easy to use. By now I created an environment that was based on many different tools and not restricted to one IDE. There was still one small nagging problem though.
Do I really want to type in all the compiler parameters every time I have to compile my application? Of course not! So what should I do? Write a script? Well my research brought me to makefiles and then to a platform independent make variant called CMake. Basically CMake is a type of script that defines a project for every platform and IDE that is out there. And this caught my attention pretty quickly because I was wondering if there was a way where I could also compile my code on windows without maintaining an extra Visual Studio branch. And this was the solution.
So I now have a good way of working without a IDE and without the worry of working around certain IDE specific issues. All I have is a folder with my code and a collection of tools. Let me describe how a code-compile-debug step looks like right now:
- Open project folder in SublimeText and start coding
- Adding potential new files to my CMake script
- Configure and run CMake. The CMake configuration step has to be only done at the beginning.
- At this time I have a terminal window open within the “build” folder. I just type in
makeand wait until compiling is finished.
- Run the debugger with my compiled binary.
I know it looks a lot more complicated then just pressing F5 in Visual Studio and it may not seem that logical to go through all this trouble if one could just use one of the many IDEs out there. And I know that this may not be a viable option for everybody. But there are certain advantages to this:
- Creating an IDE specific project file thanks to CMake without knowing the IDE
- Distribution of code on version control systems without forcing a certain type of IDE
- Cross-platform compatible because it is not IDE bound
- Only few and very specific tools needed without all the other bloat of general purpose IDEs
The disadvantages are:
- It takes a lot of time to create a new project
- It takes many steps to get to the debugging point
- No code completion out of the box
Although there are extensions for code completion out there but I just don’t like them. And for the time it takes to create a new project: there are some steps you can take to make it a lot less stressful. I show you my template for new projects in another post.
Now you know how I work on Ubuntu. And to answer some questions: Is it possible to code without Visual Studio? Yes! Is it possible to code without another complete IDE? Yes! Is it useful for everybody? Absolutely not! Is it useful for me? Actually it depends. For my current projects I am more then happy to code like this but if I would create something like an android application then I would definitely use the excellent Android Studio. This is just a solution for people who want to distribute their code on many platforms and for many IDEs without managing different branches. And that is exactly what I need right now.
23 July 2014