Start your programming journey with a Smartphone.

Start your programming journey with a Smartphone.

ยท

5 min read

I'm a Freshman as I'm writing this blog and a lot of my colleagues don't own a Laptop and neither did I own a laptop for half of the Semester. I have seen people struggle to write code with crappy apps on their phones and I didn't like how some apps would ask for a lot of money for some basic programming experience. So the solution that I came up with feels almost native and has better coding experience, but it does involve some learning curve.

The tool we're going to talk about in this article is Termux, It is a free app made to teach a lot about the command line aka the terminal interface and Linux. This guide will teach you how to install Termux and set it up for the first time.

You'll also learn some basic terminal commands and we'll also write basic hello world programs in both Python and C++ and I'll also teach you how to execute these programs with their interpreters and compilers.

Who Should Follow this Blog??

  1. People who can't afford a Laptop
  2. Those who just want to see if programming is right for them
  3. Beginner's who want to get their hands dirty
  4. Passionate individuals
  5. People who want Linux like experience on their smartphone
  6. Parents who want to force their children to learn Programming

Setting up Termux

Step - 1. โฌ‡๏ธ Downloading Termux

Although Termux is available on Playstore. I recommend downloading it from F-Droid.org as the Playstore version is way behind the one present on F-Droid.

Click Here To Download

Step - 2. ๐Ÿ”ƒ Updating all the default packages

sudo apt update && sudo apt upgrade -y

Step - 3. โž• Add Additional keys for navigation

mkdir $HOME/.termux/ ;echo "extra-keys = [['ESC','/','-','HOME','UP','END','PGUP'],['TAB','CTRL','ALT','LEFT','DOWN','RIGHT','PGDN']]" >> $HOME/.termux/termux.properties && termux-reload-settings && sleep 1 && logout

This will close the app so reopen once done.

Step - 4. ๐Ÿ Installing Python

pkg install python

Enter "Y" if asked.

Step - 5. ๐Ÿง‘โ€๐Ÿ’ป Install clang to compile C / C++ Code.

apt install clang

Before getting any further let's get familiar with "The Terminal"

Ignore everything after the # sign

  • clear # clear everything on the screen

  • cd folder_name # to enter a folder

  • cd .. # to go back one folder

  • ls # to list everything inside the folder

  • touch # to create a new file

  • nano file_name # to edit your file

  • rm file_name # to delete a file

  • rm -rf file_name or folder_name # to force delete a file or folder

Writing your first code in python

Step - 1. Creating a python file.

As most of you might know Python files end with the extension '.py' So let's create our first python file in termux using the below command we'll name our file "main"

touch main.py

Step - 2. Opening our file with an Editor

I'll be using nano as the editor of my choice but you might choose something else like vim, but you may never exit vim. So let us stick with nano for the time being.

nano main.py

A window like this will open on your screen

20220715_011348.jpg

You may write your First Program here. For tutorial's sake let's just print hello world to the terminal.

Step - 3. Write your Program.

I'll be writing the most simple code of all time. Printing Hello World

print('Hello World')

Step - 4. Saving the file.

Saving files with nano is a little Tricky. So bare with me.

click CTRL X then Y and ENTER

Step - 5. Executing the code.

Executing the code that we wrote is very simple. Just paste the following command in the terminal.

python3 main.py

Step - 6. Admiring the output.

Screenshot_20220714-221056_Termux.png

Congratulations you just became the best python programmer in the World.

Now let's shift over to C / C++

Step - 1. Creating our C / C++ file.

For C File, As the C file end with .c let's create a file named main.c

touch main.c

For C++ File, As the C++ file end with .cpp let's create a file named main.cpp

touch main.cpp

Step - 2. Let's write our Code

I'll be writing a simple hello world program in C++ you can do similar in C.

Opening the File.

nano main.cpp

Writing the Hello world program.

#include <iostream>
using namespace std;

int main() {
    cout<<"Hello World"<<endl;
    return 0;
}

Follow Step 4 of the python tutorial to save the file

Step - 3. Executing out code

For C++ files

To Compile

c++ main.cpp

A new a.out file should be created which you can view using the ls command

To Run the code

./a.out

For C Files

To Compile

clang main.c

A new a.out file should be created which you can view using the ls command

To Run the code

./a.out

Conclusion

You can run the most famous programming languages these days like C, C++, and Python using native compilers and interpreters on your phone itself. You don't need any fancy Laptop or Gaming setup to learn an essential skill like programming.

Resources

Finishing off I would recommend you to get familiar with BASH, and git and Learn Python and C++ in-depth, All from your Smartphone.

Learn Basics of Git

Learn the Command Line aka Terminal

I also recommend you watch CS50

Good Luck with your coding journey ahead ;)

ย