ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I'm going to be taking a programming class in the spring, either Java or C. I already have expereince with VB.NET and a small amount of java experience. When I look at C code i think "ick" (even though I don't understand most of it). Java just flows better to me.
The problem is C is much more versatile. The only thing java has on C is applets. But nobody writes kernels or device drivers in java, and rarely are non applet programs made in Java. So I think that it would be worth me learning C. Here is my question though:
Right now I am running a mac mini (no linux on it yet) and have no PC. I'd assume whatever C class I take would teach it in a windows centric way. So just how useful to me would this be if I want to primarily code for Mac OS and linux PPC/x64/x86? How OS/processor specific does C get?
I would say the opposite, the number of applets written is certainly very very small compared to the number of java applications.
C and Java is not fully overlapping, low level programming still requires C or even assembly language, while C isn't able to generate portable web-applications or enterprise applications suitable for a J2EE application server.
That said, developing kernels and kernel modules is limited to a very small group of programmers, while a lot of the professional work done with java are web applications.
If you stick to ISO standard C, your programs will be source compatible accross about every platform in existence. Likewise you can use stuff from other standards such as POSIX and expect it to work on POSIX platforms etc.
And yes, Java is used for much more than for applets. Look at what all gets done with J2EE for instance. I use both Java and C -- they each have their own place in the world.
well, i think the question is not "how portable is C" ... the question should be "how portable is your code" ... some people tend to use OS specific stuff that is not really necessary ... for example: there are people that open a file in windows with CreateFile (i think is the name of the function !?) and they are wondering why their code does not compile on another OS.
if you use portable toolkits, libraries and so on your code is also portable, so you may direct the problem of portability to the libraries and toolkits you use :-)
If you make importable(?) calls only when there no other way not to, and seperate the portable from the importable portions, your code is at nearly maximum portability, and you only need to reimplement your minimal OS specific stuff. And there is a java discussion thread here.
If your taking a computer science class then the code your write should be basic ISO C code. When I took my CSCI class all the work I did in class was on a Mac and all the work I did at home I did on a PC running linux. I didn't have any problems as the class didn't ever go into developing platform dependent code. Now if your taking an application development class then you maybe in some trouble as likely they will be teaching you to use Visual C++ and using MFC to develop for Windows and that is not portable code.
The CS track at Dartmouth College (hanover) is mostly java.
In terms of portability, java really does beat C. Yes, you can write hello world and maybe one or two levels up from that portably with C, but AFAIK all realisticly sized C applications that run on both windows and linux have a lot of conditional compilation, either through #ifdef's or makefiles. (Speaking of which, Makefiles don't port to windows all that well...)
That said, the C you learn in a class will probably be perfectly helpful on linux. You may not use exactly the same libraries (and completely different ones for guis)
If you care about kernels or device drivers, you don't have much choice. Similarly if you care about applets. In terms of a first language, Java pushes OO concepts on you where C doesn't (which is either good or bad) and C attempts to confuse you with pointers and memory management. If you already know OO, java will be easier. Otherwise maybe it's a wash.
My sig refers mostly to those who refuses to capitalize anything, writes how Yoda talks, and have every other word mispelled, not just the trickier ones. I think I was almost asleep when I posted that as well. For some reason "non portable" didn't sound right to me.
On topic, ISO C means that you have exactly the same classes for string, vector, map, set, etc... If you use those classes and methods, it is guaranteed to work on any platform.
As for your comments on C and Java, pointers are insanely powerful when you realize all the flexibility they can add to a program. Managing your own memory will also be much more efficient then having Java handle it for you, cause as a programmer, you should know exactly how the data flows. Java pushing any concepts onto you is bad. That means Java is programming you, you are not programming Java. OO is not pixie dust.
Managing your own memory will also be much more efficient then having Java handle it for you, cause as a programmer, you should know exactly how the data flows.
That's "more efficient than having ..."
Well, I disagree with your comment about memory handling.
It is true than in an ideal world, a programmer should know exactly how the data flows, but in the real world, a C programmer has to deal with many libraries and foreign functions he just can't master enough to know if a returned value has to be freed or not.
This is leading to many subtle bugs, like pointer freed twice, or never (memory leaks), not to mention the other pointers errors.
There are certainly tools that ease the memory issues detection, but using them, and the whole task of building a memory bug free program is simply non productive. That time would be better used focusing on the real purpose of the program.
Garbage collection algorithms used in modern JVMs are faster and less intrusive than the old ones.
Moreover, there is no demonstration that malloc/free is faster and more efficient than using a garbage collector. When you call malloc, the library has to follow links until it finds a free location large enough to hold the size requested, when java needs memory, it just knows where free memory is and give it to the program, so this part should be faster in Java. When you free a pointer in C, there is a couple of links that are updated, while in Java, as you never free anything, no time is lost ...
Finally, in Java, the garbage collecting threads are free to move the memory blocks during their job, and this has the side effect of reducing the memory fragmentation. In C, no such thing is possible, due to the direct access required by the pointers, so you may need a much larger heap than in Java for the same memory usage profile, especially with programs running for several days.
Also, the garbage collector is running with a low priority, so the CPU cycles it uses are more likely to have a smaller impact on the program main task, while with C, all the memory handling is done when the program is running, so are always slowing it.