Thread: Compile as you type

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    12

    Compile as you type

    Hi all,

    I had a thought. What does anyone think?

    It would be great to have an IDE which could compile your C program *as you type*.

    Think about it, the compilation process for a single file typically takes a matter of seconds, yet I spend minutes or hours typing and thinking between compilations. This time could be used to compile the code.

    Reasons why this would be a good thing:
    * Compilation would already be done by the time you want to compile. Just linking to do.
    * The IDE could give you much more information as you type. For example
    - type checking information
    - syntax checking
    - 'Lint' type comments
    - How many instruction cycles does each line take to perform.
    - How effective is the optimisation?

    All of these things would be so useful, especially the instruction cycle count. Sometimes it can be surprisingly very high. It would be better to know this at typing time, than having to go digging for it after compiling.

    The screen could be split into several columns. You type code in the left one. The next one shows the first pass of the compiler, producing internal symbolic information. Then the optimisation pass, then the output instructions. (or something like that)

    Is it possible? One of the reasons I have heard that this wouldn't work is that the code would be full of syntax errors as you type, so would not compile. However, I don't think this is a problem. The syntax colouring IDEs don't crash when they see a syntax error, they just do their best until it's fixed. The same could be true of the compiler. It would wait until the errors were gone, then compile that line / function / section.

    What does anyone else think about this idea?

    Hugo Elias

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > - type checking information
    > - syntax checking
    Source Insight is especially good at this. Not only will it tell you whether you actually declared all symbols, but it also shows you diagrammatically class relationships, provides tool-tip type assisted auto completion and a whole bunch of other stuff.
    Visual Assist for Visual Studio does the same thing more or less.
    So do other IDEs no doubt.

    > - How many instruction cycles does each line take to perform.
    A totally meaningless metric IMO.
    Yes, your bubble sort looks very efficient looking at the instruction count for any given line.
    But boy, it sure runs like a crippled dog.
    You should be focussing on things which matter, and which the compiler is oblivious of, like the Big-O complexity of the algorithms you choose.

    > - How effective is the optimisation?
    I prefer to let the compiler worry about micro optimisations over whether i++, ++i or i=i+1 is the most efficient. Mostly, it's not that interesting.
    Also, there isn't a 1:1 correspondence between source code lines and executable code, especially when the optimiser has been at it. There can be considerable rearrangement of code, elimination of variables and other stuff which makes for a very non-linear association between the two.

    > - 'Lint' type comments
    You'd need some heuristic to spot when the user had stopped typing otherwise it would just nag you to death with every character you typed.
    Personally, I use the pause caused by pressing ctrl-s to trigger this.

    > Compilation would already be done by the time you want to compile. Just linking to do.
    Save even more time, just type your code into the debugger!.
    Oh wait, vc.net has editandcontinue debugging.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Not sure about it. Most of the time the code would be "incomplete", unclosed braces, unfinished statements... For example, if I write a function, I usually type the closing brace as the last thing. So, the code couldn't be compiled until I've finished. And this is where I would compile anyway.

    And what would you do with all the optimisation information? The general strategy is to get it working first, and then see if something could be done better.

    As for all kinds of information, code completion, class browsing... I prefer to turn most of this off: my wxDevCpp sometimes hangs up trying to help me

  4. #4
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    The main (no pun intended) problem would be if it tried to compile in the middle of me writing a function. I would stop to think, and then it would spit out a block of errors at me.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    12
    The main (no pun intended) problem would be if it tried to compile in the middle of me writing a function. I would stop to think, and then it would spit out a block of errors at me.
    Not sure about it. Most of the time the code would be "incomplete", unclosed braces, unfinished statements...
    You'd need some heuristic to spot when the user had stopped typing otherwise it would just nag you to death with every character you typed.
    As I explained in my original post, this shouldn't be a problem. The compiler should be unobtrusive and polite, like syntax colouring. The code could be coloured to point out syntax errors etc as you type. If you stop typing for a second, and there are no current syntax errors, then the compiler would start silently, constantly updating the various columns to show its progress.

    You're still thinking of the compilation process being something which spits out streams of error messages. What I had in mind was a very dynamic/interactive process.

    Code which is incomplete would be coloured to show that it contains syntax errors.
    Code with warnings might be underlined, and the warning would be shown when you move the cursor to that line.
    Code with errors would be another colour, and would go back to the correct colour when the error is fixed. - Why wait until I press 'compile' to tell me about these things.

    My PC is 3GHz. !Three Gigahertz! We've become so complacent about computer speeds, we forget that a PC might trivially be able to spare a billion instructions every second. When I'm writing code, is it really too much to ask that my PC spare some time to help me out, instead of just wasting 200W of power waiting for me to press another key?

    > - How many instruction cycles does each line take to perform.
    A totally meaningless metric IMO. You should be focussing on things which matter, and which the compiler is oblivious of, like the Big-O complexity of the algorithms you choose.
    I guess I should explain that I had this idea while I was writing firmare for our robots (http://www.shadowrobot.com). As in much microcontroller code, time complexity is never an issue. There are no sorting, searching, or massive data structures to deal with, just lots of linear, real-time critical code. In which case it's very important to know that you're not accidently setting off the creations of large temporaries etc (this is especially true in C++).

    Also, when writing firmware for portable devices, the number of instructions taken has a direct effect on battery life. And in a battery life competitive market, that is a *very meaningful* metric. When I wrote the firmware for a digital watch recently, moving from C to assembler increased the battery life of the watch from 6 months to 1.5 years!

    Hugo

  6. #6
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Perhaps, but my good old compiler works fine. All that color and underling would honestly get annoying after a while. Maybe you would be able to turn this off?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    If you people want to see the described scenario in action, check out Eclipse's Java environment or Visual Studio's C#. They both do very, very well on this. (Eclipse even a little better last time I checked, because it's smarter about offering corrections for the errors.)
    It does not get annoying; it's in fact very helpful. (Unless it's implemented in the way of VB6. Now that was annoying.)

    The problem with C (and C++ even more so) is include files. It's an awful lot of code that might need to be checked and re-checked all the time.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Eclipse's compile as you type stuff is awesome, I found it pretty helpful, though at times it was annoying, more often than not it helped me.

  9. #9
    Registered User
    Join Date
    Nov 2006
    Posts
    12
    check out Eclipse's Java environment or Visual Studio's C#
    Many thanks. I'm very excited to know I'm not the only one in the world who believes in this!
    Gonna check it out

    Hugo

  10. #10
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Who believes in what?

    This compile-as-you-type thing is funny and fancy, but I don't think it's very useful.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  11. #11
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    it would be a good feature if it could show the error while typing the code. but it annoyers me after a few try. cant type a code without error free at the first time. So every time there is a char missing a error or a colorful code pop up which spoils the intentions of writing the code.

    ssharish2005

  12. #12
    Registered User
    Join Date
    Nov 2006
    Posts
    12
    I reckon there's a bit of fuddyduddyness going on here. The fear of the new. Does anyone here find syntax colouring annoying? Or is it helpful?

    Hugo

  13. #13
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Aftter having worked with Eclipse quite a bit (my university is very java-oriented), I must say that the code completion/colouring/compiling as you type has never really annoyed me to the point to make me wish it were not there. It does make mistakes, every so often, but not enough to warrant taking it off. It's a good feature in my opinion.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  14. #14
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    If you are a competent programmer and know what you're doing, would you really want someone looking over your shoulder all the time saying "That's right. That's right. That's right. That's right. That's right..."?

  15. #15
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Yeah, but one could argue the same about doing math with calculators, or pretty much any process which is automated. If you're good at math, you shouldn't need a calculator. But who doesn't use a calculator ? I mean, computers were invented to do the tedious work for humans, like say...find syntax errors in C or Java code. I for one definitely appreciate that Eclipse does that for me.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  2. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Dynamic array of pointers
    By csisz3r in forum C Programming
    Replies: 8
    Last Post: 09-25-2005, 02:06 PM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM