8 ms·
What I Wish I Had Known About Developing C/C++ From Linux Before I Started
- keefe 18y agoThis is a nice list! However, I really think that increasing speed of development with better tools is a cornerstone of being one of those elite programmers, and vim<<eclipse, at least for Java! I haven't done C/C++ for some time... but I expected similar IDEs exist. "The way our development environment is set up though, there was really no good way to use Eclipse because everything is done on a remote development box, and they won’t let us run Eclipse and forward over X (which is reasonable; Eclipse has a lot of overhead)" I think this is just a horrendous setup and unless there is some compelling reason (e.g. scientific computing on a cluster? even then...) that there should be a much cleaner separation between development boxes and production boxes and most of your code should be developed on a local box with some canned data for testing and then pushed out to production when that is done. This may require some effort, but the decrease in turnaround time for changes will be worth it in almost every scenario.
- allenbrunson 18y agomy thoughts exactly. in my last job, i spent over two years writing linux server apps. but i developed all my code on a mac. the low-level posix apis are nearly identical between the two, so other than a few ifdefs, i could barely tell the difference.
- derwiki 18y agoIt's a rather massive codebase, and our remote dev machines are a lot beefier than our laptops -- also 64-bit, whereas our laptops are 32-bit. I'm not saying it couldn't be done locally, but it might actually cause more headaches than it solves.
- dkarl 18y agoIDEs can work well editing code that is targeted to a different platform. The code is edited locally (and parsed, analyzed, colorized, etc. by the IDE locally) but built and run remotely on other machines. That setup used to be pretty common for enterprise and web development before Moore let us run entire enterprise application servers on our laptops. It takes more work to set up than just sshing into a remote box and firing up emacs, but it can be done.
- keefe 18y agoIt might and your approach may be optimal already. I guess it's a question of how much the environments differ? When I am moving to a new project I try to get myself setup so I can make changes and test them as quickly as possible and it's always a judgment call about how much time to spend doing that setup. Also, there is a cultural element like one poster said if everyone is using vim them that becomes a clear choice...
- scott_s 18y agoEclipse is an Integrated Development Environment. That is, all of the development tools are integrated into the editor. I don't develop using an IDE, but I still have access to the same kind of functionality. It's just not integrated into my editor.
- keefe 18y agoand so imho this increases your turnaround time for changes unless you are a real wizard with your tools, which is certainly possible
- scott_s 18y agoYou don't have to be a wizard, just competent.
- keefe 18y agoif you want to compare yourself to someone competent with an IDE, you better be a wizard
- scott_s 18y agoI think you're overestimating the difficulty of developing on the command line.
- keefe 18y agoI'm really not. I've done both. IDEs were created because they make it more efficient to write code, do you really think this whole line of technological development was a mistake? Even a 10-20% decrease in time on average is huge.
- scott_s 18y agoI think they were originally created for environments like Windows where the basic development tools weren't part of a normal operating system install.
- dkarl 18y agoUnfortunately, your expectations would not be met. IDEs make up for their limited text-editing features by providing language-dependent, code-aware functionality. Because C++ is such a hairy language, IDEs aren't able to do much with it. They don't give you anything like the cushy, comprehensive support that IDEs provide for Java. With C++, giving up the relatively lame IDE features to get a powerful text editor is a no-brainer. (I use Eclipse for Java and emacs for everything else.) You're absolutely right about their development environment; it's adapted for one set of tools. It doesn't necessarily mean other tools are inferior in general, as the author seems to conclude.
- derwiki 18y agoSorry, I didn't mean to imply that one set of tools is inferior. If I was doing Java development, I would fight harder to make Eclipse work for the project. But the specifics of our infrastructure, SCM, and utilities (we do have ctags and cscope) set up -- and the fact that the team has been using vim/emacs to do this job for the last 15 years -- makes vim/emacs a more natural choice.
- keefe 18y agoI find this post highly questionable. What is so hairy about C++ for an IDE exactly? It's strongly typed and yes, if you do too much C style stuff it may be a bit harder to navigate but if you stay in a clean OO world it should be very, very similar to Java. Microsoft put out a competent C++ IDE well over a decade ago and Borland has done so as well... It's my personal opinion that IDEs are in general superior to text editors because this integration reduces the cognitive load of solving particular programming problems. People that say eclipse doesn't have a good text editor are being a bit ridiculous - out of the box it is not that great, but there are many 3rd party editor plugins, you could configure shortcut keys however you want and of course extend eclipse... now I am somewhat biased in that I work daily on an eclipse RCP project, so I am already spun up on extending eclipse. This all has me curious though, I'll spin up eclipse C++ development against my thesis code the next (likely imaginary) opportunity I have time to kill...
- hfinucane 18y ago
- donaq 18y agoI haven't done much development in Java since my days in college, but... However, I really think that increasing speed of development with better tools is a cornerstone of being one of those elite programmers, and vim<<eclipse, at least for Java! For every other language that I have encountered, the utilities listed by the OP (especially vim/emacs) are the better tools, as far as I'm concerned. Firstly, they were written by hackers for hackers, and because of that, they generalize just about all the functionality a programmer is likely to need when coding in any language. Even supposing there were eclipse-like IDEs for every language out there, it is more than likely that there will necessarily be differences between them (since they were written for different languages) which will be jarring for the power user. One would have to learn an IDE for every language. With vim and the assorted tools mentioned in the OP, one just needs to learn one set of tools and can use them for every language. If you foresee that you will only code in one language for the rest of your life, then sure, find the best IDE for that language. In my job, however, I have to code in C++, Python, Perl, PHP and shell (most times editing source files in more than one language at the same time), so to increase speed of development, (though I am no elite programmer) I use vim.
- keefe 18y agoDo vim and emacs really have all the features of eclipse? Autocomplete, integration with Javadocs, automated refactoring, integration with bug tracking systems, integration with source control, full debugging inside of the server all with the click of a button? Do you have a resource for how to setup emacs this way? I used to use emacs...
- hfinucane 18y agoI don't use emacs, but yes, yes, no idea, yes, yes, it's not a button it's a keystroke. Of course that last one was also tied to lisp.
- mblakele 18y agoI use "screen" a lot, but I wish it had a better name. It helps if you search for "gnu-screen", but not much. Here's a tip that has saved me once or twice. If you start a long-running process, but forgot to use screen or nohup, bash lets you 'disown -h' its jobspec.
- silentbicycle 18y agoOne day I took the time to work this out for my .screenrc, and it's served me well since: # Set up my status line at the bottom of every frame caption always "%{gb} %{ck}%m-%d %C %{gb} %{gb}%?%-Lw%?%{ck}%n*%f %t%?(%u)%?%{gb}%?%+Lw%?" All of the %{gb} things are color codes. It looks like this: http://shenani.gen.nz/~scott/screen-statusbar.png http://shenani.gen.nz/~scott/screen-statusbar.png Binding ! @ # etc. to select 10, 11, 12, ... is handy, too.
- mblakele 18y agoThat's good. Here's what I'm using: hardstatus alwayslastline hardstatus string "%n: %H (%h) %t" For bindings, I find '10 '11 etc to be efficient enough. But I also make heavy use of :number to reorder my windows so that I know which one is which. There's also shift-A, to give them meaningful labels in the ctrl-A " list.
- joeyo 18y agoThere are more .screenrcs (including my own) in this thread: http://news.ycombinator.com/item?id=425890 http://news.ycombinator.com/item?id=425890
- thingie 18y agoThe biggest problem with screen is that it breaks ordinary virtual terminal scrollback, which is something that I can live with, but…
- derwiki 18y ago"Ctrl-a [" will put you enter the copy buffer mode and let you scroll up
- hboon 18y agoThere's an incremental find option in Eclipse. Ctrl-j or was it Ctrl-i (or something like that) which is pretty nice and I wish all IDEs (read: IDEs) have that. That beats Ctrl-F any day. How did you do refactorings? Or you just don't?
- barrkel 18y agoWhich IDEs don't? Borland/Codegear IDEs have had that at Ctrl+E for over a decade, while Visual Studio defaults to Ctrl+I. F3/Shift+F3 scroll backward and forward through matches by default.
- jballanc 18y agoIn Vim, install ack, then put "set grepprg=ack" in your .vimrc. Then, open your project in Vim, do a ":grep <your-symbol-here>", and use ":cn", ":cnf", ":cp", ":cpf", ":cr", etc. to move about. Combined with strong knowledge of setting marks and using ":s/" substitutions, and I often wonder how people who use IDEs do refactorings! ;-)
- miloshh 18y agoI think you misunderstood what refactoring means in an IDE. Suppose you want to rename a method. There might be many other methods of the same name in different classes, local variables of that name in other methods, or even classes with that same name in differen packages. Eclipse automatically does all of this for you. I honestly don't understand how regexps and strong bookmarking skills could help you - the editor needs true knowledge of the language to carry out this task.
- deleted 18y ago[deleted]
- kingkongrevenge 18y agoI doubt it's realistically possible for this to work reliably with C++. How could the parser deal with a predeclared type pointer in a header file that is resolved at link time? How about unions?
- zandorg 18y agoI just use Kdevelop.
- Periodic 18y agoWhen I started developing in C in Vim there are two things I've gotten used to that I can't live without now: ctags and auto-complete (they help with eachother). Ctags is great, especially for navigating someone else's code. What does this function do? Just ctrl-] and suddenly I'm at its definition. Something in there I don't recognize, same thing. Ctrl-t to go back up the tag stack. Ive become so used to navigating my code this way I have trouble without it. Completion is just the way that Vim will give you completion matches in insert mode if you hit ctrl-n or ctrl-p. With C it's very smart about it and will automatically search included files. It's great for not having to worry about exact spellings on things. If you really like this sort of stuff there are a few plugins that do Textmate-like snippets.
- barrkel 18y agoOf course, if you use an IDE, it can do all of this for you and much more, and more accurately than ctags.
- silentbicycle 18y agoOf course, it's easier to write a program that generates tags for a new language than to build an IDE around it.
- ori_b 18y agoCtags is just as accurate at scanning C declarations as an IDE, and with a bit of vim magic, it even auto-updates when you save files. One thing to realize is that vim IS an IDE of sorts. Only, it's far more extensible for the same effort. (although, from my brief forays with emacs, emacs certainly beats vim for extensibility)
- ramchip 18y agoEmacs also supports ctags. I didn't find it very useful with C++ though, which is my usual language, since it didn't autocomplete member functions - I think it's supposed to work, though I couldn't be pushed to tweak it. Cscope, as commented on the article's website, sounds quite interesting too.
- dkarl 18y agoc++filt - an absolute necessity. Also, he should have just pointed out that all IDEs are ass for C++. Java is simple enough that an IDE can be a big help, but C++ is too complicated and too slow to compile. (The remote access thing is just a matter of the work environment being adapted to one set of tools and not another -- the real issue is that text editors beat IDEs for C++.) Otherwise, an excellent list.
- silentbicycle 18y agoThe real issue is that C++ is too complicated and too slow to compile. Languages that are easier to throw together a reasonable parser for (Lisps, Smalltalk, Lua, or even C) have a much lower barrier to entry for development tools. Keeping the language syntax simple enough means that somebody scratching an itch can write something useful in an afternoon or a weekend, rather than taking a team and months.
- ido 18y ago> Languages that are easier to throw together a reasonable parser for (Lisps, Smalltalk, Lua, or even C) Heck, even Java. People (rightfully) complain a lot about how verbose some parts of java are (like how instead of anonymous functions or functions that can be passed as a parameter you have anonymous classes), but ignore the fact that the designers intentionally made that sacrifice to maintain consistency.
- silentbicycle 18y agoIndeed. I'm working on a tool to help maintenance coders undo the damage from copy-and-paste programming on huge legacy code bases. One approach it uses is language-specific, but requires a bit of configuration (via Lua's wonderful LPEG), and the other is language agnostic. It's searingly obvious how much worse C++ is in this regard.
- fix3r 18y agoActually, no. The real issue is using compiler's front-end from the IDE itself. While it's true that C++ is hugely complex IDE writers shouldn't try to replace compilers (ie. trying as hard as they might they'll never get around C++ templates and their touring-completeness). MS got this right. gcc and every IDE that relies on it (like Xcode) is crippled in this regard.
- deleted 18y ago[deleted]
- johnrob 18y agoAnyone else find themselves typing this way too often?: awk '{print $2}' Is there a way to achieve this that's easier to type?
- randomwalker 18y agocut -f 2
- ori_b 18y agocut -d'delim' -f'fieldno'
- kingkongrevenge 18y agohttp://perl.plover.com/classes/mybin/samples/slide010.html http://perl.plover.com/classes/mybin/samples/slide010.html
- bf 18y agoWhy are we taking C/C++ programming advice from somebody who has been doing it for just over a year? And not to troll, but anyone who honestly believes vim is a better development environment than one of the mature Linux IDEs (Eclipse, Code::Blocks, KDevelop) is an idiot.
- ramchip 18y agoI upvoted this by mistake. But I don't believe "not to troll" and "anyone who believes vim is a better environment is an idiot" can go together. And this is coming from an emacs user ;)
- davidw 18y agoNot to mention the "would you say that to someone's face?" test. There might be an argument for Eclipse (although I think it's terrible compared to Emacs:-), but calling people idiots is not the way to make that argument.
- donw 18y agoLinus Torvalds has pretty much always used an Emacs variant for his work on the kernel. Matz uses Emacs for his work on Ruby. DHH uses TextMate, a text editor. Pretty much every major piece of software that you can name on the Unix platform was and is developed in either Emacs or Vim. Anybody who thinks that a text editor is better than an IDE is an idiot? I think not.
- vorador 18y agoWell, some people used ed.
- silentbicycle 18y ago?
- vorador 18y ago
- mahmud 18y agoWorse is NOT Better; use a safe and high-performance programming language and learn its foreign-function interface to call out to C and C++. Life is too short for core-dumps and premature optimization, plus you only have two feet to shoot at. The better designed a language the better its development process feels. You can get immersed in a lowly Lisp, J, or Forth listener. Just a little black xterm with nothing else to it, and you feel productive already (never mind the amazing environments there are for Lisp.) BADLY designed and malignant languages have 3rd party tools to augment its functionality. There are things to bolt on, hammer in and stuff to bake into the scaffolding before you stuff in boxes. The C and C++ equivalent of a listener is `cat` or maybe the system-shipped vi or nano or pico. Can you seriously feel yourself getting something done?* * (I will answer myself and say yes; I learned Unix programming over a serial line, but it was not an immersive experience; I had books on my desk and lap and was flipping back and forth to get anything done; a masochistic sort of fun, fueled by the mischievous possibility of breaking into another account ;-)
- derwiki 18y agoI didn't really mean for this to be a battle of which language is better, although I prefer not to use a screwdriver for a nail -- I'm doing systems level/kernel programming, so C makes a lot of sense.
- mahmud 18y agoPoint taken. Although I personally don't see C as "another" programming language, more like a system building-block, closer to a portable processor binary format :-) When I wrote kernel modules I used C; today I'm writing an in-memory cache for a mulithreaded webserver. It has to maintain user-sesions in memory across several load-balancing servers. It has a multi-stage storage system. It has a queue manager that maintains a private queue for all concurrent users of the system; everything dynamically scheduled in realtime with a bunch of matrix munching algorithms. Allot of intricate stuff that I would have written in C when I didn't know better. I would still write C code though, but only if I absolutely must, as in your case. Regards.
- kmavm 18y ago
- atypic 18y agoThere is one thing I feel have been neglected here: Debugging. Debugging C in Linux is a dream with gdb. Debugging (heavily templated) C++ in gdb is a nightmare. I therefore have one additional tip, though it doesn't work in console: Run Visual Studio in wine. It's debugger can pick up running Linux processes and is awesome to work with.
- messel 18y agoGreat point, maybe that's why I fell in love with visual studio, the debugger?
- dryicerx 18y agoI feel the same way about GDB lacking in C++. I ran across project Archer... apparently better debugging support for C++ http://sourceware.org/gdb/wiki/ProjectArcher http://sourceware.org/gdb/wiki/ProjectArcher
- davidw 18y agostrace is another extremely useful tool. Sometimes it's really nice to be able to see exactly what's happening at the OS/program boundary (what exactly are we reading from the file? from the network?), and strace can do that in a very non-intrusive way - no root reqired, no recompile required.
- jbert 18y agoSeconded. That apache process is chewing cpu, is it spinning in an inf loop internally to userspace? No, strace shows it repeatedly doing backend conn/op/disconnect - aha! Another trick in this vein is/was to use 'pstack' to pull a C backtrace from a looping process. If you do that every second for 10 secs, you'll probably find where the process is looping. As a bonus, it also acts as a poor-man's-retroactive profiler (process X intermittently takes 30s to handle it's job instead of 2s - watch for one and when it happens, strobe the process with pstack to see what it's up to). Can be used in production, no need to deploy profiling build and run for ever to catch problem, etc. (And a variant of this trick for interpreted languages is to hook an unused signal (SIGUSR2?) in your language to say "dump me a perl/python/etc backtrace to the log file". Assuming the loop is in your app code this will give you a language-level backtrace if you strobe the process with the signal) NB1: pstack doesn't do anything which scripted gdb couldn't do, it's just more convenient NB2: pstack is unavailable on 64-bit arches? NB3: pstack needs some symbols to work with in the binary, which probably won't be the case with your system apache+mod_xxx
- adeleinr 18y agoHow about ktrace, I think it is slightly better than strace
- messel 18y agoI started with makefiles and emacs but fell in love with Visual C++ and eventual .NET. Netbeans is aok, but the article has prompted me to review "the impossible" and check out yet another interface. My ideal user interface for programming? A brilliant group of younger smarter coders with better memory.
- Raphael_Amiard 18y agoI guess the big drawback for theses kind of tools for me is the time it takes to setup a nice developpement environnement. To fine tune my vim as i like it with ctags completion , good keybindings, a nice colorscheme and all, it takes me around 5 hours minimum. I'm currently dev'ing for QT under QT Creator, and everything is nicely integrated, with some really neat features you can't reproduce in vim, and it even has an (incomplete) vim emulation mode ! I used to be an hardcore vim / cli fan, but i'd go back to that for nothing in the world now, at least for this current dev setup. Also i hate having to mess with makefiles.
- bcl 18y agoGood list of tools. All of those usually show up on any Linux developer's list of what's in their toolbox.
- gvb 18y ago"diff: pretty standard utility, but this is what I use it for: I loop through all the files I’ve modified and diff to the previous version, then pipe to a grep where I can search for something I think I’ve changed but can’t remember where." NOOOOOOooooooo. That implies he is using ad-hoc version control (uniquely named files or directories with non-revisioned copies). Tracking and finding changes is what git is for. Commit early and often! If you mess up, it's got your back! If your compatriots use SVN, that works, but not nearly as well (when I used SVN, I would still revision control my local copies with RCS in between SVN commits). If you are developing by yourself, rcs is the minimum acceptable alternative.