Thread: lone wolf c programming habits

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    82

    lone wolf c programming habits

    Hi,

    I was trying to improve my habits in order to program more efficiently. I wanted to post some opinons, in the hope other might make some suggestions (the "stop programming!" one is not allowed ha, ha). NB: I say "lone wolf" not because I am one, but because I believe there is a stage in programming that you have to hack away at a problem on your own. So, it definitely does not refer to large projects, just small implementations of single algorithms which I do on my own. My concern: I want / need to get alot faster at it.

    Anyhow, what works for some people, doesn't work for others. Clearly platform is important. I use gcc on linux. I'm also a traditionalist, and use vim. However, I'm not in a continuous state of bliss because of this: it's just what I'm used to. So here are some opinions:

    - there is a fairly good vim module for c, but actually I hardly use its functionality. I just have a few of my own small vim abbreviations, set up in .vimrc and I use them only. The problem with having more than a few is that I forget them.

    - I had a few bash scripts for generating templates, but ended up only using two ... the very simple ones: sets up the basic headers and the main block.

    - I have quite a large directory of snippets and try to find one which suits the current task. I've had mixed success with this, though. It's common for me to look for the snippet, start modifying it and then abandon and just code straight from zero.

    - I analyse alot of source code, I use ctags and cscope, but I have to say, the benefits of the end-result are debatable. Alot of effort, and you actually are not coding when you analyse, so it's not immersive. It's time spent away from the problem (paradoxically).

    So, myself (different for others of course) I favour simplicity but also need alot of time, and that's not so good. So suggestions on how to improve habits are welcome.

    Cheers!

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    A good syntax highlighting IDE is a big benefit to a programmer.
    Library documentation is also of key importance, you need information at your finger tips all day every day.

    For actual code production... try to write code (as opposed to "scoop and poop" coding) as much as possible. The more you solve problems on your own the easier it gets to solve problems on your own. Nothing makes my blood boil faster than someone in a programming course --where self-created code is everything-- running around asking for libraries or code samples... all they learn is how to panhandle code, they never actually learn the skill of programming.

    Set up your code with some standard of indentation and whitespace that you find easy to read. Add comments for non-obvious code segments. Try to write code you can still follow 5 years from now. You'll be amazed how hard it is to read, even your own code, after time passes and your head is elsewhere.

    Write libraries of canned functions that you use frequently. Having things like DispatchWindowMessages() or InitLANSocket() fully debugged and ready to use can be a real blessing in the productivity department. Code re-use is not a bad thing. It means you already solved that problem once and don't need to solve it again.

    Beyond that... practice, practice and more practice...

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by stabu View Post
    Anyhow, what works for some people, doesn't work for others. Clearly platform is important. I use gcc on linux. I'm also a traditionalist, and use vim. However, I'm not in a continuous state of bliss because of this: it's just what I'm used to.

    - there is a fairly good vim module for c, but actually I hardly use its functionality. I just have a few of my own small vim abbreviations, set up in .vimrc and I use them only. The problem with having more than a few is that I forget them.
    It's really not that great to read you don't use vim's features as the first thing. How exactly are you used to this?

    - I had a few bash scripts for generating templates, but ended up only using two ... the very simple ones: sets up the basic headers and the main block.
    I think that's OK for the kind of work you are describing -- writing snippets. If you want to use other templates though, you need to understand them like you understand main. Usually people branch out from the console and want to start using the rest of the operating system, and provide a GUI for whatever they're making. So maybe you should try that next. That's when some of the other templates can come in handy. And I'm sure there are more templates than GUI-related ones, but there is a certain level of "I know what I'm doing and I think I need to start writing a shared library" or whatever the case may be.

    - I have quite a large directory of snippets and try to find one which suits the current task. I've had mixed success with this, though. It's common for me to look for the snippet, start modifying it and then abandon and just code straight from zero.
    Why exactly do you do that? You might want to chew on this piece of writing: Things You Should Never Do, Part I - Joel on Software
    It's really important in the professional world I think to think like a revisionist, and if you think like a revisionist, you'll spend a lot less time doing things you've already done even though work isn't your concern. You'll be fixing things you've already done, for sure. But that's a lot better than having the attitude of "well I'm just going to completely start over and everything's gonna be the way I like it and that is just damn perfect."

    My $0.02

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    If you have success with the snippets approach, you are doing it wrong.

    If a piece of code gets copied and pasted into so many places, it should be made into a library.

    Imagine using a snippet in 10 programs, then when you used it in the 11th one, you realize there's a bug in the snippet. Now you need to go find all the places you used the snippet...

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    82
    Hi,

    Thanks for all your comments. I take the main point of cleaning up my snippets and turning some of them into libraries. That's going to be a good deal of extra work, but it seems to be a best practice.

    Vim has good syntax highighting, and I *do* use alot of vim's clever functions, but the vim module I refer to is Fritz Mehner's plugin which sort of turns Vim into an IDE. As I say, i do my own vim mini-scripts instead.

    thanks all for the comments and the Spolsky link, if anybody has any more, I'd still welcome them of course.

    Cheers!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Programming Habits
    By lehe in forum C++ Programming
    Replies: 5
    Last Post: 04-25-2009, 05:00 PM
  2. Bad coding habits
    By Magos in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-12-2005, 05:44 PM
  3. Professional Habits?
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 01-17-2003, 02:27 PM
  4. Silent Wolf
    By Leeman_s in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 01:11 PM
  5. Wolf#d
    By kaygee in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-10-2002, 09:01 AM