SIMPLE

The thought of being able to write code on your own

In this issue, I would like to write about thoughts that enable me to code on my own and what I keep in mind when writing code.

Steps to capture complex events

How to deal with abstract problems

Before coding, I think we first need to understand how to approach abstract problems.

They are very difficult to solve because they are elusive and fluffy.

However, abstract or complex problems cannot be solved by simply looking at the subject in a vague way.

Here's the point.

The key point here is to be aware that any difficult problem is almost always a mass of small, simple problems. This can be applied to both functional development and short problem solving.

Case problems are often used in the selection process for consulting firms. Case problems are about presenting a solution to a familiar abstract problem in a logical manner.

Like programming, case problems also test how well you can structure a very abstract problem into a concrete, logical problem.

If you understand the flow and tips of how to solve a case problem even once, you can apply them to a wide variety of problems, so I think this is a concept that engineers should also learn.

I am currently working for a foreign IT company, but I also received a job offer from a foreign consulting firm when I graduated.

Even though I did a lot of programming when I was a student, I was able to acquire the habit of thinking in a structured manner with a little practice.

This way of thinking is very useful not only in solving various day-to-day problems, but also in application development.

Develop structuring skills with case problems

Let's take an actual example and quickly solve a case problem.

This time, the subject is the problem of "increasing the sales of beer on Shinkansen trains.

How do you think about the solution when solving this problem?

People who do not usually view problems structurally will propose solutions out of the blue. For example, "lower the price of beer" or "put advertisements on the plane.

These are certainly some of the solutions, but by suddenly listing proposed solutions without structuring the problem, "even more effective measures are missed," or "the proposal was actually not very effective," etc., can happen by itself.

Let me give you an example of how to solve a case problem.

First of all, in case problems, it is necessary to set some assumptions by yourself before starting to work on the problem.

By setting preconditions, you can determine the end point to some extent in order to prevent divergence of discussions.

In this case, we will assume the following setup.

  • A-san, who is a part-time beer vendor, has requested
  • The section of the bullet train where beer is sold is from Tokyo to Osaka
  • Assume that there is no turnover of people between Tokyo and Osaka
  • Assume that the train is full of passengers

Once the assumptions have been made, this abstract problem of "increasing beer sales on bullet trains" can be transformed into something more concrete.

For example

Sales of beer in Shinkansen = "number of Shinkansen cars x unit price of beer x number of beer purchases per person x number of customers purchasing beer"

By breaking down what elements make up "sales" in this way, we can more clearly identify which items we should implement measures for.

Here, we will list items that Mr. A, a part-time worker, could devise in a realistic manner.

  • Number of Shinkansen cars -> Part-time workers do not have the authority to increase the number of cars
  • Unit price of beer -> The unit price of things is usually set to the lowest possible value
  • Number of beer purchases per person -> Few people drink beer until drunk on Shinkansen trains
  • Number of beer customers -> Can be increased with some ingenuity

From the items broken down as above, we pick up items that may have room for improvement, taking realism into account.

In this case, we will determine that we can take some approach to the item "number of customers who purchase.

Here, we will further break down what elements make up and influence the "number of customers.

Number of passengers purchased = "passenger turnover x number of times Mr. A makes a round trip on the bullet train x number of passengers per car x Mr. A's ability to serve customers."

Here again, we select items that may have room for improvement.

  • Passenger turnover → cannot be played with since the same people are assumed to be on board by the preconditions
  • Number of times Mr. A goes back and forth on the bullet train → could be improved
  • Number of passengers per car → assumed to be always full by the preconditions
  • Mr. A's customer service skills → could be improved with some ingenuity

At this point, the bottleneck issue finally came to mind.

We will consider measures to address these two issues: "the number of round-trips Mr. A takes on the Shinkansen" and "Mr. A's customer service skills.

Regarding the number of round-trip Shinkansen trips, we can increase the number of customers to 1.5 round-trips by slightly increasing the speed of travel from the current one round-trip between Tokyo and Osaka.

As for "Mr. A's customer service skills," you can take measures such as "asking a senior staff member with high sales for tips" to "acquiring know-how on customer service so that you can respond flexibly to a variety of customers.

Case problems do not have 100% correct answers. So it is no problem to go into it.

However, it is important that the abstract problem is structured and that reasonable measures are finally listed based on an analysis of the current situation structured with a logic that is acceptable to all to some extent.

Thoughts on writing code

We have seen above how to deal with abstract problems by using case problems as examples.

Even in problems such as application development or competition programming, the questions to be solved are initially abstract. In that sense, thinking about solving case problems and thinking about implementing functionality in a program have something in common.

For example, in the case of an application such as Twitter, the solution might be to "add a function that allows users to communicate with each other," or in the case of competitive programming, to "create the logic for something like a game of rock-paper-scissors.

To determine how to achieve this, we must first take a bird's-eye view of the entire project and consider what steps to take and what algorithms to use to accomplish the task.

It is impossible to code without knowing the overall map, so it is necessary to first put it into a logical framework that ensures no omissions.

When actually creating an arbitrary function in application development, it is a good idea to follow the flow below.

  1. Understand the concept of how what you want to achieve works
  2. Think about what kind of technology and logic can realize the concept
  3. Think about the flow of logic in natural language to actually operate the function
  4. Actually implement the flow you thought of above in a programming language

Only after these four steps can you start coding and developing functions.

Except for the most gifted engineers, it is necessary to understand the entire process and the logic behind each step before coding.

Let's take a closer look at each step of the process.

Understand the concept of how what you want to achieve works.

First, you need to have a solid understanding of how the entire application works.

To be honest, this phase is a process that anyone can understand, even if they are not an engineer.

Take Twitter, for example.

  • Create an account and register yourself
  • Write and send thoughts you want to express
  • Follow people you want to see tweeted regularly
  • Comment on other people's tweets

A simple way to give you the functionality of Twitter is to do the above.

Capture the big picture of what is being achieved by the application.

Think about what kind of technology and logic can be used to realize that concept.

Once you get to this stage, you are in the engineering-like process.

For example, in the case of the login function,

(1) "Prepare a form screen where users can enter information (e-mail address and password)" → (2) "Send the entered e-mail address to the server side" → (3) "Send the e-mail address from the server to the DB" → (4) "Return the password corresponding to the e-mail address sent from the DB to the server. (assuming the user exists)" → ⑤ "Verify whether the password received from the form and the password sent from the DB are equal or not.

In this way, the function description, which has been abstract for one step, is understood in more detail and how the function is to be realized.

If the understanding of this phase is unclear, you will get stuck in the next phase, so make sure you understand it well.

Think about the logic flow in natural language that actually makes the function work.

Once you understand the above process, this is where you get down to the coding and grammar level logic.

To simplify the example here, we will look at a "login function". A simple login function requires the following logic

(We will limit our discussion to the server side after receiving data from the front end)

  • Keep the password and mail address sent from the front end in variables
  • Throw a query using the mail address as a key and retrieve the password from the DB
  • Check if the password sent and the password retrieved from the DB are the same value using bool
  • If it is True, redirect to home, if it is False Returns an error

This time, we have simplified the process a little for the sake of explanation, but the image of this phase is as shown above and will be fleshed out to a more coding-ready level.

implement the flow you thought of above in a programming language

At this point, you can finally start writing code. Replace the logic expressed in natural language with code.

Frankly speaking, this process is not too difficult if the logic has been well created in the above process.

This is because, for the most part, it comes out as "what you want to achieve + its language.

Furthermore, the most important thing here is to gradually add small pieces of working code anyway.

If you write multiple lines of code at once without checking, you will always get stuck somewhere.

The reason why it is difficult to find the correct parts when copying and pasting code found on the Internet does not work is because you have not done the checking work from scratch.

Until you get used to this, write code line by line, and then add more lines of code, checking each line to see if it is behaving correctly.

summary

This time, we took a case problem and explained how to put abstract events into concrete logic.

I also explained how to apply such thinking to coding!

I am also an inexperienced engineer and my experience and knowledge are still very limited. This is just my personal opinion and certainly not the best way to go about it.

However, in the process of learning programming, I feel that I have become more or less able to write code on my own by being aware of what I have written in this article.

Compared to the time when I could not write code by myself at all, I feel that my skills have improved overwhelmingly.

If you are currently studying grammar by copying sutras or studying Progate, but feel that you are not yet able to code on your own, please try to be aware of the things I have introduced here.

macroro

Name: macroro
Career Background: * New graduate hire at a foreign-affiliated IT company * Software engineer at a startup * (Current) Freelancer Content Focus:
Primarily share articles about programming, English language learning, Japanese things and international topics.