Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iMacNoob

macrumors member
Original poster
Jul 13, 2008
65
0
Hi,

Got a new iMac, so where is python and C installed on this thing?

Can someone help me get a "hello, world!" going in Python and/or C on this thing?

My terminal is open.....please guide me! :)
 
thanks for the help!


I need xcode even if I am not doing iPhone development?

I just want to practise some python and C ?


*confused*
 
Ok all I have to do is open up terminal and type:

python


hahah

No for C...
 
Hi,

Got a new iMac, so where is python and C installed on this thing?

Can someone help me get a "hello, world!" going in Python and/or C on this thing?

My terminal is open.....please guide me! :)

1. Install Xcode, found on disc 2 of the Mac OS X install CDs that came with your computer.
2. Open Xcode, go to File->New Project
3. In the new project window, go down to Command Line Utility and select "standard tool"
4. Name your project, decide where you want to put it, and start coding!
 
1. Install Xcode, found on disc 2 of the Mac OS X install CDs that came with your computer.
2. Open Xcode, go to File->New Project
3. In the new project window, go down to Command Line Utility and select "standard tool"
4. Name your project, decide where you want to put it, and start coding!

XCode for "Hello, World!" in C is like a thermonuclear weapon to get rid of that annoying woodpecker outside your bedroom window.

You need to install the developer tools, but once you do:
Use a text editor to enter the source code:
Code:
#include <stdio.h>

int main(int argc, char *argv[]){
  printf("Hello, World!\n");
  return 0;
}

I recommend vim, which would require:
vim hello.c
Press i
type the code above
Press esc
Type:
:wq

Others think it's too hard to learn vi, but it is my editor of choice.

Once you've done that, from the terminal:
gcc -o hello hello.c
./hello

If you use another text editor, you will need to do this in the directory where you saved the file called hello.c.

-Lee
 
XCode for "Hello, World!" in C is like a thermonuclear weapon to get rid of that annoying woodpecker outside your bedroom window.

You need to install the developer tools, but once you do:
Use a text editor to enter the source code:
Code:
#include <stdio.h>

int main(int argc, char *argv[]){
  printf("Hello, World!\n");
  return 0;
}

I recommend vim, which would require:
vim hello.c
Press i
type the code above
Press esc
Type:
:wq

Others think it's too hard to learn vi, but it is my editor of choice.

Once you've done that, from the terminal:
gcc -o hello hello.c
./hello

If you use another text editor, you will need to do this in the directory where you saved the file called hello.c.

-Lee

Just asking, but is there anything wrong with using Xcode for coding in C? I understand that it's overkill, but it does the job and seems to do it well. I'm new at all of this, so please excuse me if I'm being ... um... silly?
 
Just asking, but is there anything wrong with using Xcode for coding in C? I understand that it's overkill, but it does the job and seems to do it well. I'm new at all of this, so please excuse me if I'm being ... um... silly?

Nothing wrong with it. It is just so much harder. Using the command line means all you need to worry about is the code in the file.

In Xcode you need to worry about if it is including the right libraries, where it is looking for your header files etc etc. Took me a while to work out how to use a third party library in my applications with Xcode I'll tell you.
 
Nothing wrong with it. It is just so much harder. Using the command line means all you need to worry about is the code in the file.

In Xcode you need to worry about if it is including the right libraries, where it is looking for your header files etc etc. Took me a while to work out how to use a third party library in my applications with Xcode I'll tell you.
Personally, I use vim and Makefiles, however I never had any issues using XCode and thought it was pretty simple to add a library, so I would say try it, and if you don't like it there are always alternatives (including command line).
 
Personally, I use vim and Makefiles, however I never had any issues using XCode and thought it was pretty simple to add a library, so I would say try it, and if you don't like it there are always alternatives (including command line).

How is going to the project menu > Edit active executable > then adding the library simpler than adding -lpython or whatever on the end of a command line command? Plus the fact if you want your libraries you have built from source to actually show up you need to add the relevant /usr/local directories to your path arguments in the .profile file, because rather stupidly Mac OS X does not come with /usr/local/* on the path by default.

I've never really got on with IDEs, a) because I want to learn the language, not take time to learn the IDE and b) because they always hide things away from you so you are never 100% sure if there was a setting you forgot about or if it is just an error you made.
 
Hi!

Actually I didn't want to use the IDE, so can someone tell me how to write a simple 'hello, world!' in C using Terminal window only?
 
Not that taxing

XCode for "Hello, World!" in C is like a thermonuclear weapon to get rid of that annoying woodpecker outside your bedroom window.

It is just so much harder.

Guys, really?

1. Open XCode
2. File > New Project
3. Select "Command Line Utility" > "Standard Tool", press return
4. Type a name for your project, press return
5. Click "Build"

DONE. Seriously, you've just created the hello world program. And you didn't even have to write any code.
 
Guys, really?

1. Open XCode
2. File > New Project
3. Select "Command Line Utility" > "Standard Tool", press return
4. Type a name for your project, press return
5. Click "Build"

DONE. Seriously, you've just created the hello world program. And you didn't even have to write any code.

Uh-huh. Easy up to that point.

What about changing the optimisation of the compiler? Changing the path of a library that your program links too? And many other things that are 100x harder to do in Xcode than on the command line for a beginner.

Plus it is bad form to rely on an IDE. Best to learn how to code with a text editor and the command line because if you ever get a job that does not have or use an IDE you will be up the proverbial creek.
 
What about changing the optimisation of the compiler?

1. Project > Edit Project Settings (or just double click on the project name)
2. Click on "Build Tab"
3. Change the "Optimization Level" drop down to one of the 4 available gcc -O levels.

If you want detail level control (for example if you just want loops unrolled) most options are also right there on the build tab in a nice searchable list. If you need more control, just add your arguments as a user-defined setting.

Changing the path of a library that your program links too?

Project > "Add to Project"

And many other things that are 100x harder to do in Xcode than on the command line for a beginner.

You seem to be asserting that for a beginner the following things are all 100x easier:
1. Learning vim is easier than a gui code editor with both native and readline key bindings, code sense, live indexing, jump-to function drop-downs, header/source toggle buttons, split panes, etc.

2. Using GDB's terminal interface is easier than using Xcode's GDB interface and typing out things like "info func main", "info locals", "bt", "info frame", "info threads", "break main", and "disass" is easier than having it done automatically or via point-and-click.

3. Hunting through various poorly indexed man pages with a pager and whatis is easier than apple's ever improving "Help" > "Documentation" tool.

4. Editing make files every time you add or rename something is better and easier than letting it get done on it's own or via point-and-click. (Remember that everything you do in a make file can be done in XCode too.)

If any of these things are true, then apple has failed the developer community.

Plus it is bad form to rely on an IDE. Best to learn how to code with a text editor and the command line because if you ever get a job that does not have or use an IDE you will be up the proverbial creek.

You are no longer talking about what's easiest for a beginner.

Although I personally first learned coding via command line and terminal tools, I think your blanket dismissal of IDEs is wrong. Add together just the users of XCode, eclipse, java studio, and visual studio then divide that sum but the number of active developers in the world. You clearly get a very large percentage.

An IDE just brings all the tools to the table right up front so you can focus more on the project and less on the process. How often do you really get a job that can't be imported/exported through an IDE? How often do you get a job that MUST be developed remotely? How many of those jobs CANNOT be done via something like sshfs or nfs?

I'm not saying that an IDE is right is all circumstances (for example I prefer Smultron to IDLE when I'm writing python) but I am arguing that nothing about the IDE concept is "bad form."
 
Uh-huh. Easy up to that point.

What about changing the optimisation of the compiler? Changing the path of a library that your program links too? And many other things that are 100x harder to do in Xcode than on the command line for a beginner.

Plus it is bad form to rely on an IDE. Best to learn how to code with a text editor and the command line because if you ever get a job that does not have or use an IDE you will be up the proverbial creek.

And the beginner in the first place shouldn't have to be exposed to the complexity of the toolset until they are ready for it. One of the great things about an IDE is that used the way they are expected to be used, they do a great job of just getting out of your way and letting you learn the code. Of course, the nice thing about the CLI is that it really isn't any worse for the beginner. It is when you go beyond learning the language and start trying to learn all these exterior APIs and libraries that form BSD or OS X that it gets tricky. And as long as you aren't delving too heavily into the BSD layer from XCode it isn't really bad at all.

My personal suggestion to the OP is instead of being shoehorned into one environment or the other, try both a little, and then pick the one working best for you while you are learning the language. Then go back to using both when you are ready to really dig in and understand what the toolchain is doing. The CLI will let you build full-blown GUI apps, but it will be harder than just using XCode. XCode will let you build command-line apps, but it will be more involved than just using the command-line to build.

If you intend to make a career or serious hobby around programming, it is best to understand both. Just as ignoring the CLI can hurt you, ignoring the IDE can hurt you when you get shoehorned into a job that requires you to use it. I still get dinged in my Windows programming job when my stuff works from the command-line, but I keep forgetting to make sure the VS IDE project also works correctly and update the IDE projects.
 
I don't think IDEs should be dismissed outright, but I think that if you are learning something platform-independent like C, it might be harmful to only know how to build in a platform dependent IDE like XCode. IDEs are great tools, but if you can't function without one you are less versatile, even if day to day most people have ready access to their IDE of choice.

If you want to write a C "Hello, World!" program, searching for the right menu to show you the console output seems backwards to me, but it may be the case that using an IDE lets some people focus on the code while they're learning. I find the opposite to be true, and find being able to use vim and a command line compiler for learning something new is easier than learning an IDE at the same time.

My exception is languages whose syntax is dwarfed by their libraries, in which you cannot write "Hello, World!" without digging into a few objects. I wouldn't try to write too much Java without an IDE, but write a ton of C and Fortran without one.

This is, essentially, a battle which cannot be won. This is a matter of opinion, and everyone will have an answer for the gripe offered by the other side.

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.