Jump to content

I think a mistake made by many introductory programming courses is to skip over some important ba...


G+_Lee Crocker
 Share

Recommended Posts

I think a mistake made by many introductory programming courses is to skip over some important basic skills in order to get to the more fun stuff quickly. Too often, they never get around to going back to basics, or when they do, they're harder to teach than they would have been at the start. One of those fundamentals is basic use of the command line or "console".

 

For one thing, some computers (like many small embedded systems) don't have any way to interact with the user except a command line, so it's worth learning about for that reason alone. But even the largest, most graphically-rich modern GUI OSs also have a command line, and there are important things you can do there that just can't be done with a GUI. Think of GUIs and IDEs as fancy luxury cars: they're a great way to get where you're going quickly, in style and comfort. But if where you want to go is a little bit off-road, you may need to use a Jeep, or even get out and hike some. How do you think the GUI itself was first written?

 

In Windows, the standard command line is the program cmd.exe, often called "Command Prompt" or "C:\ Prompt". There are alternatives to this as well for more advanced users: one from Microsoft called "Powershell", and several designed to work more like other operating systems, such as "MINGW/MSYS" and "Git shell". On Mac OS, the command line utility is called "Terminal". Linux desktops also generally come with an app named after the desktop: "gnome-terminal", "lxterminal", or simply "xterm". These are actually graphical front-end programs to what is called the "shell" in Unix-like systems; this shell is the same program you will use on systems with no GUI at all.

 

Programming with command-line tools involves editing plain text files with a text editor program.This is very different from a word processing program that does things like choosing fonts and formatting paragraphs for print. A text editor only deals with the text itself. "Notepad" is built into Windows, but many people use something better like "Notepad++". The standard editors on Unix-like systems (that is, Unix, Linux, BSD, MacOS, and others) are "vi" and "emacs". There are also many popular cross-platform programmer's editors like "SublimeText".

 

After you've created your text files in some programming language, you use command-line programs to convert them into runnable form. This varies from one language to another, and often from one OS to another. You will have to consult the documentation on the particular language environment you are using. There are even advanced tools called "cross-compilers" that run one one kind of machine but produce programs to run on another. 

 

Script-like languages such as Python and Perl combine the compilation and running step into one, so once you've created a file "myscript.py" or "myscript.pl", you can run them directly by typing "python myscript.py" or "perl myscript.pl". On all OSs except Windows, you can even embed the name of the program used to run the script on the first line of the script in a special syntax: #!/usr/bin/python, for example. Then you can just type "myscript.py" to run. Another limitation of Windows is that you have to tell the script ahead of time whether it will be running in a console or in a graphical window. You do thing by running "pythonw" instead of "python" for windowed programs, or rename the program to "myscript.pyw" to make it clickable in the file manager (MacOS and Linux don't have this problem).

 

Even if you intend to program only for graphical OSs, and plan to stick to the smooth highways of an IDE, I think it's also important to at least learn about what's in those woods off to the side.

Link to comment
Share on other sites

As a coder for the past 44 years, I agree about the utility to know how to do something via a command line.  For Windows, I have transitioned to using PowerShell as my preferred command line host.   And, of course, using the PowerShell computer language for my automation and scripting.

Link to comment
Share on other sites

 Share

×
×
  • Create New...