Apply minor reformatting and consistency improvements to sloum's submission.
This commit is contained in:
parent
6f900506b2
commit
25711eaeda
1 changed files with 22 additions and 40 deletions
|
@ -8,71 +8,61 @@ With computers it is comparatively easy to make things once you have a general p
|
|||
|
||||
I believe just about anyone can do this (write applications for computers), if they are so inclined. This is not something solely available to C programming wizards that have been doing it for decades. There are lots of easy to approach programming languages and environments for people new to the concepts.
|
||||
|
||||
|
||||
## Why Build Your Own Tools
|
||||
|
||||
At the end of the day the best reason I can think of is for the satisfaction of using something you built and of knowing how a thing works (at least at the level of abstraction needed to be able to mostly control or modify it).
|
||||
|
||||
Of course there is also knowledge. The learning that happens when you build a piece of software can be quite valuable. It can help you learn to think and reason in different ways. Solving problems is good brain exercise.
|
||||
|
||||
|
||||
## How To Get Started
|
||||
|
||||
As stated above: you do not need to have prior programming experience to start building your own tools. The first step is to pick a language to work with. This choice mostly doesn't matter too much, at least from a certain perspective.
|
||||
|
||||
|
||||
### Languages
|
||||
|
||||
When starting out it is good to choose a language with good documentation and lots of resources online for working with that language, but most languages you will find nowadays will be fine. A few good/popular choices that come to mind:
|
||||
|
||||
|
||||
=> https://www.python.org/about/gettingstarted/ Python
|
||||
|
||||
Python code is generally easy to read and reason about (at least at beginner levels) and there is a lot of information about writing python programs available online. The built-in library has just about anything you'd need to write most types of programs, even graphical programs.
|
||||
|
||||
If you are on Linux or OSX it is likely that Python is already installed on your system. Read ahead to learn a small bit about terminals/shells and then run 'python3 --version'. If you get a response that says it is not found, try running 'python --version'. If it is still not found then you will need to install it with the instructions on the python website (linked above) or with your package manager (if you system uses one).
|
||||
Python code is generally easy to read and reason about (at least at beginner levels) and there is a lot of information about writing Python programs available online. The built-in library has just about anything you'd need to write most types of programs, even graphical programs.
|
||||
|
||||
If you are on Linux or OSX it is likely that Python is already installed on your system. Read ahead to learn a small bit about terminals/shells and then run `python3 --version`. If you get a response that says it is not found, try running `python --version`. If it is still not found then you will need to install it with the instructions on the Python website (linked above) or with your package manager (if you system uses one).
|
||||
|
||||
=> https://www.lua.org/start.html Lua
|
||||
|
||||
Lua, like Python, is straight-forward and easy to read and reason about. Lua's built-in library is MUCH smaller. This has a lot of benefits though: Lua is a small enough language that a person can reasonably hold pretty close to all of it in their head at one time. So after a bit of practice you should just be able to write things without constantly looking at the documentation. Some downsides are that the built-in library does not have things like sockets (which let you communicate over the internet as a client or server, among other things). A lot of video game engines allow games to be written in Lua (Love2D, Pico-8, etc.), so if you like video games Lua might be a good choice.
|
||||
|
||||
|
||||
Both of the above are interpreted languages. To run any programs written with them, a person needs to have the Lua or Python program installed on their system. Thus, sharing your creations has an added step of getting someone to get that interpreter on their system.
|
||||
|
||||
There are also compiled languages. These languages use a compiler (another program that converts the code you write into lower level code of some sort - it varies from compiler to compiler. Once a program is compiled it can generally be run without needing to have the language installed on the system or invoking and interpreter). Most programs on your system were likely written in the programming language 'C'. This is a fairly old programming language that I do not generally recommend as a first language to people these days. It is VERY powerful, but can be harder to reason about than Python or Lua, especially for a beginner. It can also be tricky to find actionable information on. There are a number of compiler and library implementations, and they may vary in how they are used. The language features and available functions/macros can also vary from OS to OS and architecture to architecture.
|
||||
There are also compiled languages. These languages use a compiler (another program that converts the code you write into lower level code of some sort - it varies from compiler to compiler). Once a program is compiled it can generally be run without needing to have the language installed on the system or invoking and interpreter. Most programs on your system were likely written in the programming language 'C'. This is a fairly old programming language that I do not generally recommend as a first language to people these days. It is VERY powerful, but can be harder to reason about than Python or Lua, especially for a beginner. It can also be tricky to find actionable information on. There are a number of compiler and library implementations, and they may vary in how they are used. The language features and available functions/macros can also vary from OS to OS and architecture to architecture.
|
||||
|
||||
'Rust' is a newer programming language that can work in similar domains to 'C'. But it is a complicated language in comparison the the others being recommended here. The programs it creates, when coded well, can be really solid and safe (from a memory standpoint)... but it can be a lot for someone just starting out.
|
||||
Rust is a newer programming language that can work in similar domains to C. But it is a complicated language in comparison the the others being recommended here. The programs it creates, when coded well, can be really solid and safe (from a memory standpoint)... but it can be a lot for someone just starting out.
|
||||
|
||||
As such, I tend to recommend learning Go as a first compiled language:
|
||||
|
||||
|
||||
=> https://go.dev/learn/ Go
|
||||
|
||||
Go is a more modern compiled language. It differs from C in a number of ways, that mostly make it easier for you to program... but make it less suitable for certain types of applications (anything where garbage collection would be a problem - but that won't be an issue for 99% of people learning to program). The documentation is fantastic and the code is easy to reason about. The built-in library is almost as complete as Python's (though there is no direct help with GUI programming built in).
|
||||
|
||||
|
||||
All of the links provided above are to "Getting Started" instructions. Again, the language doesn't matter so much. If you see something out there other than one of these three that tickles your fancy and have found readable documentation that makes some level of sense to you: go for it!! I just recommend these three to give novices somewhere to start.
|
||||
|
||||
|
||||
You may have noticed I did not include JavaScript. This is intentional. I do not think it is a good place to start. The ecosystem is complicated and the tooling is difficult. To effectively use JavaScript in a modern way in a browser you will likely need to learn HTML and CSS along with JavaScript. Additionally, it has become trendy to use various frameworks and libraries rather than just writing JavaScript code (using React, Vue, Angular, Svelt, jQuery, etc). These extra things to learn can make approaching JavaScript as a beginner confusing and difficult and may create long term confusion about some basic programming concepts. It is also harder to look up documentation due to the wide variety of frameworks that people work in. While you could use nodeJS to build console applications like you would when starting out with Python or Lua, I just feel like nodeJS is not as good as Lua or Python and that its ecosystem is terrible (opinions on this will vary, and I am just giving you mine).
|
||||
|
||||
You may also notice, if you have experience in such things, that I have not included any sort of shell programming (bash, fish, zsh, etc. scripting). While these options can be very useful for system automation and can even be used to make larger programs... their syntax is often not clear and the ability to just call as if in the shell is unlike most of the rest of the programming world. They might be something good for people to look into, but not a great choice as a first language as I think they would create some misunderstandings and possibly bad habits.
|
||||
|
||||
There will likely be many opinions that disagree with me and encourage starting with Rust, C, or some functional language (Haskell, Clojure, Elixir, Erlang) or other. All of these languages are powerful languages that can be really great to work with. I have made my recommendations based on my experience and a desire to allow someone to "dip a toe in". Not everyone needs to become a systems programmer, and my advice is really geared toward people that just want to try out coding to see what it is all about. In earlier times BASIC or Pascal would have been recommended for this purpose, but those days are largely past us. I think Python, Lua, and Go are sensible choices for someone to try things out.
|
||||
|
||||
|
||||
### Terminals, Shells, and Text Editors
|
||||
|
||||
Once you have followed the installation instructions for the language you have chosen, you will likely need to open a terminal window.
|
||||
|
||||
Many folks that do not program may not know much about terminals (on any modern system it will likely be a terminal emulator... but you don't need to worry about that). Each of the major operating systems includes some textual interface to the system. On OSX the application is "Terminal.app". On Linux or BSD there will be a terminal of some form, but its name will vary by distribution/os (gnome-terminal will be present on ubuntu, for example). On windows, if memory serves correctly, it is called "Cmd.exe", but don't quote me on that (I have not used a Windows machine, even in passing, for over a decade).
|
||||
Many folks that do not program may not know much about terminals (on any modern system it will likely be a terminal emulator... but you don't need to worry about that). Each of the major operating systems includes some textual interface to the system. On OSX the application is `Terminal.app`. On Linux or BSD there will be a terminal of some form, but its name will vary by distribution/OS (`gnome-terminal` will be present on Ubuntu, for example). On Windows, if memory serves correctly, it is called `Cmd.exe`, but don't quote me on that (I have not used a Windows machine, even in passing, for over a decade).
|
||||
|
||||
Once the terminal is open you will be presented with a prompt of some sort (likely ending in '$', '#', or '>', but that is not a rule). You can type commands at this prompt and get output. On Linux/BSD/OSX type 'ls' and press enter; on Windows type 'dir' and press enter. You should see a list of files in the current folder. You entered the name of a program: 'ls'/'dir'. This program takes your current directory and loops over all of the files in the directory and outputs their names. It then exits, returning control to the terminal (actually the shell, which is running inside of the terminal, but lets not get ahead of ourselves).
|
||||
Once the terminal is open you will be presented with a prompt of some sort (likely ending in `$`, `#`, or `>`, but that is not a rule). You can type commands at this prompt and get output. On Linux/BSD/OSX type `ls` and press Enter; on Windows type `dir` and press Enter. You should see a list of files in the current folder. You entered the name of a program: `ls`/`dir`. This program takes your current directory and loops over all of the files in the directory and outputs their names. It then exits, returning control to the terminal (actually the shell, which is running inside of the terminal, but lets not get ahead of ourselves).
|
||||
|
||||
Your first programs will likely be similar: you will call them from the terminal, they will do their thing, and then exit. Many programs can take arguments, additional pieces of information being passed into the program. For example, the 'ls' program can be entered as `ls -l`. The `-l` is an argument that tells the `ls` program to output extended information about each file... its owner, access settings, size, etc. So, the 'ls' program has code to look at the arguments that were sent into it and do things with them. Your early programs will likely not include many arguments, but it is good to know about them since passing in paths to files or other input will quickly become useful.
|
||||
Your first programs will likely be similar: you will call them from the terminal, they will do their thing, and then exit. Many programs can take arguments, additional pieces of information being passed into the program. For example, the `ls` program can be entered as `ls -l`. The `-l` is an argument that tells the `ls` program to output extended information about each file... its owner, access settings, size, etc. So, the `ls` program has code to look at the arguments that were sent into it and do things with them. Your early programs will likely not include many arguments, but it is good to know about them since passing in paths to files or other input will quickly become useful.
|
||||
|
||||
I do not know much about windows command line, so from here on I will be talking about Linux/BSD/OSX. If you enter:
|
||||
I do not know much about the Windows command line, so from here on I will be talking about Linux/BSD/OSX. If you enter:
|
||||
|
||||
``` shell input
|
||||
cd ~
|
||||
|
@ -80,7 +70,7 @@ mkdir programming_practice
|
|||
cd programming_practice
|
||||
```
|
||||
|
||||
You will move directories to your home directory. The program 'cd' takes a file path as an argument. In this case the '~' is something the shell (the actual program running inside the terminal that lets you input commands) knows to expand to meaning a user's home directory. We then create a directory in your home folder called 'programming_practice' and then 'cd' into it.
|
||||
You will move directories to your home directory. The program `cd` takes a file path as an argument. In this case the `~` is something the shell (the actual program running inside the terminal that lets you input commands) knows to expand to meaning a user's home directory. We then create a directory in your home folder called `programming_practice` and then `cd` into it.
|
||||
|
||||
You can always go directly to this folder with:
|
||||
|
||||
|
@ -88,7 +78,7 @@ You can always go directly to this folder with:
|
|||
cd ~/programming_practice
|
||||
```
|
||||
|
||||
Then you can run 'ls' to see any files or subfolders you may want to work on/in.
|
||||
Then you can run `ls` to see any files or subfolders you may want to work on/in.
|
||||
|
||||
You now have a place to work on programs. You can navigate to this folder in a graphical file browser as well.
|
||||
|
||||
|
@ -107,15 +97,13 @@ For those that are used to terminal environments and have used them before, or f
|
|||
* vim
|
||||
* emacs
|
||||
|
||||
Both of them offer graphical versions as well as terminal versions. But neither are as simple as just opening it up and typing. They require you to learn lots of commands and key combinations to use them. They offer very powerful editing capabilities for coding and other writing, but may not be a good place to start if you are not familiar with them. Vim is likely installed on your system and can be invoked by typing 'vim', followed by an optional filename, at the shell. You will immediately notice that it does not respond like you are used to when keys are pressed. It is a common joke that vim, or its predecessor 'vi' (also likely on your system), traps people in it if they don't already know how to use it. If you end up in one of them and can't get out, type: ':q!'. I have less experience with emacs, but it is not without a steep learning curve as well.
|
||||
|
||||
|
||||
Once you pick and editor and a language and get them both installed you may want to try running a program. Here are some very basic example programs that you can type into a file for each of the three languages I recommended above:
|
||||
Both of them offer graphical versions as well as terminal versions. But neither are as simple as just opening it up and typing. They require you to learn lots of commands and key combinations to use them. They offer very powerful editing capabilities for coding and other writing, but may not be a good place to start if you are not familiar with them. Vim is likely installed on your system and can be invoked by typing 'vim', followed by an optional filename, at the shell. You will immediately notice that it does not respond like you are used to when keys are pressed. It is a common joke that vim, or its predecessor 'vi' (also likely on your system), traps people in it if they don't already know how to use it. If you end up in one of them and can't get out, press Escape, then type: ':q!', then press Enter. I have less experience with emacs, but it is not without a steep learning curve as well.
|
||||
|
||||
Once you pick an editor and a language and get them both installed you may want to try running a program. Here are some very basic example programs that you can type into a file for each of the three languages I recommended above:
|
||||
|
||||
### Python Example File
|
||||
|
||||
Create a file named 'hello.py' in the current directory ('nano hello.py', for example) and enter the following text:
|
||||
Create a file named `hello.py` in the current directory (`nano hello.py`, for example) and enter the following text:
|
||||
|
||||
``` Python code
|
||||
def say_hello():
|
||||
|
@ -131,14 +119,13 @@ Then run the following in your terminal/shell:
|
|||
python3 ./hello.py
|
||||
```
|
||||
|
||||
If it doesn't work, make sure you have python3 installed (type 'python3 --version' at the shell and see if you get a python version number printed. It is possible that the program may be called 'python' on your system, in which case replace python3 in any of the above with python).
|
||||
|
||||
If it is installed and still not working, make sure you are in the folder containing your file. Run 'ls' to see the folder contents. If you don't see your file, run 'pwd' to see what file-path you are at and navigate as needed to where the file is using the 'cd' command. Then try running the program again.
|
||||
If it doesn't work, make sure you have Python 3 installed (type `python3 --version` at the shell and see if you get a Python version number printed. It is possible that the program may be called `python` on your system, in which case replace `python3` in any of the above with `python`).
|
||||
|
||||
If it is installed and still not working, make sure you are in the folder containing your file. Run `ls` to see the folder contents. If you don't see your file, run `pwd` to see what file-path you are at and navigate as needed to where the file is using the `cd` command. Then try running the program again.
|
||||
|
||||
### Lua Example
|
||||
|
||||
Create a file named 'hello.lua' and enter the following text:
|
||||
Create a file named `hello.lua` and enter the following text:
|
||||
|
||||
``` Lua code
|
||||
function say_hello()
|
||||
|
@ -157,16 +144,15 @@ Then run the following in your terminal/shell:
|
|||
lua ./hello.lua
|
||||
```
|
||||
|
||||
If it doesn't work, make sure you have lua installed (type 'lua -v' at the shell, if you get a version number printed then you are good to go, if not then you should check your install instructions for Lua).
|
||||
|
||||
If it is installed and still not working, make sure you are in the folder containing your file. Run 'ls' to see the folder contents. If you don't see your file, run 'pwd' to see what file-path you are at and navigate as needed to where the file is using the 'cd' command. Then try running the program again.
|
||||
If it doesn't work, make sure you have Lua installed (type `lua -v` at the shell, if you get a version number printed then you are good to go, if not then you should check your install instructions for Lua).
|
||||
|
||||
If it is installed and still not working, make sure you are in the folder containing your file. Run `ls` to see the folder contents. If you don't see your file, run `pwd` to see what file-path you are at and navigate as needed to where the file is using the `cd` command. Then try running the program again.
|
||||
|
||||
### Go Example
|
||||
|
||||
You may notice that this is very different from the Python and Lua. Go has some rules for how file structure should be set up, they aren't too complicated.
|
||||
|
||||
Create a directory for the program by running `mkdir go_hello && cd go_hello` at your shell/terminal. Then create a file named 'main.go' and enter the following text:
|
||||
Create a directory for the program by running `mkdir go_hello && cd go_hello` at your shell/terminal. Then create a file named `main.go` and enter the following text:
|
||||
|
||||
``` Go code
|
||||
package main
|
||||
|
@ -190,10 +176,9 @@ go build
|
|||
./go_hello
|
||||
```
|
||||
|
||||
You may notice that running the program is a little different here. We call `go build` first. This compiles the program into an executable file. We then run that file by giving the shell the path to the file ('./' just means "inside the current directory").
|
||||
|
||||
That file will run on any system with the same OS and Processor architecture (there are maybe two or three in common consumer usage at present, though retrocomputing enthusiasts or people on the cutting edge may have others). This is a cool benefit of using go: you could just share that file (or output one that works on a friends machine) and they do not need to have Go installed on their system at all.
|
||||
You may notice that running the program is a little different here. We call `go build` first. This compiles the program into an executable file. We then run that file by giving the shell the path to the file (`./` just means "inside the current directory").
|
||||
|
||||
That file will run on any system with the same OS and Processor architecture (there are maybe two or three in common consumer usage at present, though retrocomputing enthusiasts or people on the cutting edge may have others). This is a cool benefit of using Go: you could just share that file (or output one that works on a friends machine) and they do not need to have Go installed on their system at all.
|
||||
|
||||
### An Actual Application
|
||||
|
||||
|
@ -212,7 +197,7 @@ Here are some steps for thinking about how to code your first bigger application
|
|||
* Come up with the idea
|
||||
* Understand the problem well, and think out a few different ways to solve it (from a high level perspective, not in code)
|
||||
* Think about what the inputs and outputs are (often text, but sometimes numbers, or key presses). Think about how they could best be represented in your code. How you structure data will be among the most important things in your code, and there are LOTS of options, from simple variables to arrays, structs, objects, databases, etc.
|
||||
* Once you have a basic sense of how you will be holding onto and thinking about your inputs/data, you can start to reason about working with that data. This could be a good point to write out a flow chart in plain english for how you think things should flow through your program... or you could just start coding and see what happens. Either way will provide good lessons.
|
||||
* Once you have a basic sense of how you will be holding onto and thinking about your inputs/data, you can start to reason about working with that data. This could be a good point to write out a flow chart in plain English for how you think things should flow through your program... or you could just start coding and see what happens. Either way will provide good lessons.
|
||||
* Start coding! Where possible try running your program as you reach different milestones. Sometimes things will break, most interpreters or compilers will give you a message telling you what line something is broken on and, hopefully, a hint about how to fix it. Get good at reading this output.
|
||||
* An easy way to test as you develop, that some people frown on but I think is invaluable, is to print out text/variables at various places so you can see that your code is being executed as you think. You can print data or just information text (ie. "made it out of loop" or "got into 'x' function"). Be sure to delete these when you are done using them. Don't rely too much on them, but for a quick sanity check they can be useful. Many languages have testing suites and tooling for debugging that you may want to look into as well.
|
||||
* Remember that it is an iterative process and you will likely rewrite parts of applications or sometimes the whole thing. This is a normal part of working on a project, even for experienced developers.
|
||||
|
@ -225,11 +210,8 @@ There are lots of developers using public nix systems. If you are on one, it may
|
|||
|
||||
If you want, feel free to reach out to me: <sloum AT THE HOST rawtext.club>.
|
||||
|
||||
|
||||
## Wrapping Up
|
||||
|
||||
This started out as a writeup about creating the tools you use, and turned into more of a "how to get started coding". I know it is cursory at best, but hopefully has some information useful to someone. I know there are a lot of people out there that want to learn how to do these things and may feel overwhelmed by the sheer volume of information and all of the options. We are living in a time of plenty in many respects with regard to languages, libraries, frameworks, tutorials, opinions, etc. Though there is less variety now in the systems themselves (a shame).
|
||||
|
||||
The key thing is to try and have fun, but expect there to be some hurdles and roadblocks. I think programming appeals a lot to people who like to solve puzzles and ponder different ways of doing things. If this describes you, then you may enjoy programming. It can be a useful skill, but it can also just be a fun skill that could serve the same role as solving sudoku puzzles for someone, but with the added benefit of creating something cool or interesting. However you come to it, you may be starting down what could become a lifelong obsession. It has been for me (I started coding with BASIC as a kid in the late 80s).
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue