Explain Basic Programing Concepts To Me

in Genius Bar edited January 2014
I realize that to a knowledgeable person this question will be like asking why I can't make peanut butter with margarine, but it is something that I have wondered about for a while.

My understanding of computer programing is that a programer writes software in one of many languages?C++, for example. He or she then takes that C++ code and runs it through a compiler which converts the language's syntax into the 1's and 0's that a computer understands. If that's correct, then how come one can't take the C++ code and run it through two compilers, one for the Mac and another for the PC? Isn't the actual programing language agnostic, or are there different variants of C++ for the Mac and PC?

Let me make it clear, again, that I understand that my logic is flawed, but I'd like to know how. Thanks.


  • Reply 1 of 3
    If you use C and the std functions, then YES. You can just recompile the source code for any platform that supports the basics.

    But sooner or later, you are gonna wanna call some OS functions to 1.) save you a shitload of programming time, and 2.) to benefit from someone elses experience in an area your not so good with.

    For example:

    On the Mac, you might make a few calls to quartz extreme libraries to do some funky stuff with your window, like transparency.

    This, obviously, would not work under windows. The quartz calls would have to be replaced with directX calls if directX could handle it.

    Hope this helps.
  • Reply 2 of 3
    willoughbywilloughby Posts: 1,457member
    In addition to what Gargoyle said there are different variants of languages as well. Such as Visual C++ from Microsoft. It was created specifically for developing Windows Applications and lets you do lots of things (OS calls) that could never be done in another variant of C++.

    Java was supposed to change all this. You could write your code once and run it anywhere. That dream has never really been realized thanks to good old Microsoft again \
  • Reply 3 of 3
    To give a bit more background here is the example in C:

    C was designed to make like easier on the programmers of the day, most of whom were writing programs for the big iron (timeshare servers). The biggest customer at that time was AT&T (Ma Bell), and they wanted to be able to write programs that could be made to work on their many different types of hardware.

    And C shows its roots in this. The language itself is not that complicated (sometimes hard to wrap your mind around... like pointers to pointers), and in comparison to some of the higher level language (perl, VBScript, etc), not very right in what you can say in one word. But it had to be in order to have compilers that would produce code to run on all those platforms.

    But in order to expand this a bit further people started making libraries, that is collections of code that others could use so that they didn't have to re-invent the wheel every time they started solving a problem. Some of these libraries became known as the "Standard libraries" and have since become requirements of C compilers. These standard libraries are what make C so powerful. I can go to any number of computes and write a "hello world" program, and the same program will get the same results on any number of computers.

    But because the standard libraries have to work on ever computer that there is a full C compiler on, that limits what you can do with the standard libraries. Because many computers out there don have monitors, let alone Graphical User Interfaces, (most I could say... remember most computers are things like the processors in your car, or telephone switches, etc..) there is no concept of even a "window" in the standard C libraries. There is a lot of code to deal with strings, and files, and things like that. And it all works relatively the same on every platform (there are certain differences, like what characters are allowed in the name of a file, and how big numbers are allowed to get).

    There are C libraries on almost every major OS that support Windows, but they have never coalesced into standard libraries, and so you tend to pick a platform and write for it. There are a few libraries out there that you can use to write for multiple platforms: Metroworks PowerPlant is the biggest commercial one, TrollTech's QT is an up-and comer, many X11(ish) systems have ports for a number platforms, etc.. but none of them have really managed to make themselves "the" way of doing things.

    And the target for such a technology is a moving one. Both Microsoft and Apple have made a great number of additions to their GUI libraries that would need to be taken into consideration. People complain about software that is ported without using the "natural" look ad feel of their platform of choice. Eventually, maybe someday this will settle down and we will get a single library, but I don't look to see it anytime soon.
Sign In or Register to comment.