a thoughtful web.
Good ideas and conversation. No ads, no tracking.   Login or Take a Tour!
comment by user-inactivated
user-inactivated  ·  3290 days ago  ·  link  ·    ·  parent  ·  post: Pubski: November 18, 2015

That's quite a programming journey you've had. Let me ask you a few questions, if you don't mind.

If I were to build a small app - something like "act as a clock and tell me when an hour since I've launched the app has passed" - would it be quicker for me to do it in C or in Java?

What are C and Java generally used for? Is there anything one's better for than the other? Keep in mind: I have no experience in either, or in programming apps for a PC.

    What text editor/IDE do you use?

Brackets, and loving it. What amazes me is that Brackets itself is written with JS while acting as a Win application - the only thing giving it away was error logs: something in there implied of its nature pretty clearly to me. It allows for good project management - both inside the project and between several of them - which is good for me since I can easily look up previous projects I did and copy/learn from how I solved the problem encountered previously. Instant testing - "live preview", they call it - is what I enjoy very well: it allows for instant checking and correcting whatever error I may have made or changing the style that didn't work out so well. Good stuff, and I'm enjoying it. Can't see a reason to switch off to anything else.





caelum19  ·  3289 days ago  ·  link  ·  

Assuming I understand what you mean, here's how you'd do it in C:

    #include <windows.h>

    #include <stdio.h>

    int main() {

        printf( "starting to sleep...\n" );

    Sleep( 3000 ); // sleep three seconds

    printf( "sleep ended\n" );

    }

And this is how you would do it in Java

    package ...

    public class SleepExample{

      public static void main(String[] args){

    System.out.println("Starting to sleep");

    try{

    Thread.sleep(1000); // Sleep 3 seconds

    }catch(InterruptedException e){

    e.printStackTrace();

    }

    System.out.println("Sleep ended");

    }

As you can see, Java's is bigger, but I've made a shitty gifv to demonstrate that it's not really a problem when you're using an IDE like IntelliJ IDEA http://i.imgur.com/XUPWXeb.gifv

Edit: The program actually sleeps 1 second because I'm an idiot

Another thing to note is

    #include <windows.h>
in the C version, this code would only work on Windows(Someone correct me if I'm wrong) and you'd need different implementations for different operating systems, optimized for different CPUs...

If you want to make an alarm that's actually useful, with a GUI etc. Java is defintely the way to go out of the two languages, there's no argument. C is pretty old, it's very fast and very low-level, which will mean you will need to reinvent the wheel pretty often, but also you're not limited(Very rarely a concern, but you will know when it will be). C is better for a few very specific tasks, but that's about it.

However, the answer to that question when it isn't limited to just Java and C will depend on who you ask. Personally, I'm conflicted on Java or C# (Leaning slightly toward Java because the JVM is full of potential and mono is pretty slow)

Brackets sounds cool. It's always good to look out for better things though, I was happy using Eclipse and so regret being lazy and not checking out IntelliJ IDEA sooner. Plus, if you're looking for a job, it's good to at least know the basics of an IDE you're likely to use if you get hired.

briandmyers  ·  3289 days ago  ·  link  ·  

Replace "windows.h" with "stdlib.h", and replace "Sleep" with "delay", and it'll run almost anywhere.

user-inactivated  ·  3287 days ago  ·  link  ·  

Thanks for the lesson! What do you think about C vs. Java, then?