How to create a program [ Beginner ]
CodeLongAndPros

Hello, I'm back! (If I ever left?)

I'm also going to use a naming convention now.
[Beginner] assumes only basic knowledge in the target language.
[Intermediate] assumes average level knowledge in the target language.
[Expert] assumes, well, expert level knowledge in the target language.

How to program (for beginners)

Sometimes you'll find yourself with something you want to do, but not know how to actually go about doing it.
(This tutorial is aimed at beginners)

So let's use the example of a program that checks if it's a palindrome.

We can break this down into a couple of steps:

  • Get the user input & clean the string
  • Reverse it and check if it's the same
  • Output the results

Get user input & clean the string.

We can break this down even further:

  • Get user input
  • Remove any non-alphanumeric chars.

So let's start our code:

You might be confused about what means.

''.join(list) makes a array of chars ['f', 'o', 'o'] into a string (returns "foo")

We then use a generator to get every char in the input if it is a letter or a number (remove anything not matching)

And we now sanitized our input.

Reverse the string & check if it's a palindrome

So now we have a clean string, so now we need to reverse it.
(To reverse a string we use str[::-1])
So we can store the reversed string into a var:

After this we compare to see if they are the same:

Output the results

So now we find ourselves on the last step, outputting it.

I'm just going to use a one-liner since that's the most efficent.

So now we have this:

And that's how you do a simple program.

But what if we want to do a big program?

So I've made a 'dot file manager', and these are the steps I took:

  • Make a database
    - Create it in the correct format
    - Add a default entry
  • Create an interface to the db
    - Create a class that contains functions to
    - Add an entry
    - Edit one
    - Delete one
  • Create a CLI for it
    - Add commands for all of the database operations above

Ok, that's it, folks.

After reading this, you should have, if even a basic idea, on how to tackle large programming projects.

You are viewing a single comment. View All
firefish

@CodeLongAndPros Also why do you need a discord bot for a file manager