First 250 days of software dev - Part 4

16 min read

Day 31

The best thing I learned today: While English sources are abundant, never look at Turkish sources first, and never look first at texts that the author has read from English sources and is likely to present from a narrow perspective. The first website and REST API and API examples that I haven't had a chance to take a good look at first, but will tomorrow morning (7 hours later): What is rest?.

The topic of the day was REST API. Initially I found a few resources but I didn't understand the reason for the existence of what I was researching because I was stuck on them and they took more time explaining the technical terms than the logic. Unfortunately, I think I was able to understand this by searching Stack Overflow again and accessing good resources. Lessons learned for the day:
  • REST is the foundation of the web's architectural principle.
  • It's one of the strangest but most fundamental things on the Web: The client (the browser, the requesting machine) can interact with the server (the responding machine) and the resources it hosts (owns or offers) without knowing anything about them beforehand. So there are two separate machines. They don't know each other, but they can do things with each other. How? If machines are nouns, we can form sentences using different verbs for each noun. So by using each machine with a verb, we can make it interact with the other machine with a verb that they have in common. What is our verb? Before we define the verb, one thing must be clear: both the server and the client must agree on the media being used, and they must use it. This is our initial condition. Since we are working on the web, our media in this case will be HTML.
  • The API takes the principles of REST and thus creates what we call a REST API. The client has nothing about the structure of the API. The server must provide whatever information is necessary for the client to interact with the web service. For example, let's look at the HTML form structure. The server specifies the location of the resource and the required fields. The browser does not know in advance where to deliver the information and what information to deliver. The information of the forms must be provided by the server.
  • What are these things we call in practice and what is the connection with HTTP? HTTP is built around resources and verbs. Verbs like GET, POST, PUT, DELETE are applied to resources according to the instructions provided by the server. For example, we have a user database provided by a web service. This service uses a hypermedia based on JSON (application/json+userdb). Client and server are programmed to understand this format. But neither of them knows anything about each other. For example, by making the request with GET we get a response in JSON format. In JSON we can find resources from a property called links. This is also called hypermedia controls. So we can manipulate the resources using different HTTP verbs. And the only thing we know on the client side is our media definition.
  • GET request should never be used to update information. Let's think about adding products to the cart. GET should be idempotent. There should be no difference between sending a request twice and sending it once. This means making the request cachable. Adding products to the cart is not idempotent (doing it twice adds a copy of the product to the cart twice). Therefore, a POST request should be used for this type of operation.
  • Another topic: Resources gain identity through URIs. There needs to be a generic way to find resources, to tell the client where they are. A URI provides that. The difference between a URI and a URL: every URL is a URI, but not every URI is a URL. Why? URI specifies the identity, URL specifies the location. So both URL and protocol are specified, like HTTPS.
Let's get to the point. Some reasons and things that define REST:
  • We need to use an architecture that can support high traffic volumes so that our server can process responses from different clients. Therefore, we don't want to tire (or bottleneck) our server by remembering information from previous requests. That's why we restrict each request-response pair between client and server by making them independent of each other. That is, the server doesn't have to remember the old request in order to respond to a new request. So we want our interaction to be stateless.
  • In order to further reduce the load on our server, caching is allowed to avoid redoing the calculations already done for the client. That is, a snapshot of the initial response provided to the client is taken. If the client makes the same request again, the snapshot is provided to the client instead of having to do the calculations again to create the initial response. However, since it is a snapshot, it has an expiry date, which the server provides. If the expire date has not passed and the response is updated, the client will not see the updates unless the catch in expires or the page is rendered again.
  • If we talk about layers: Each layer in our system interacts with its neighboring layer, so our client layer interacts with our server layer. But if we have another server layer that helps our main server layer to process a request, the client does not communicate directly with these layers. As said, everyone communicates with their neighbor. The server will forward the request as it should.
  • What was the API? Let's move away from the cliché that API is labor and look at the details: The use of one piece of software by another piece of software. The goal is to communicate between apps. Making the machine talk to the machine. Web API for example: whenever a request comes in, an app sends data to the client. API is not only in web development. Using a file system or http module is actually an example of API. As you said, the operating system, windows is a program. And this program allows us to use a piece of code (api) from within itself. And of course with authorization, authentication, etc. it prevents us from manipulating the main program from that piece of code and accessing unwanted places.
That's all for today. In general, I think I understand the logic.

Day 32

Today might be the day of my shortest report. We need to come up with a system that thinks about the relationship between the machines that talk and communicate with the HTTP protocol in a way that is most optimized for us and that suits our needs. Or at least we should create the algorithm for now. Since it was said to have 3 servers and one of them holds some information, I treated it like a database. The database server was like a repository where all our data was stored. Access to this repository should only be done by our servers, and the client should only be able to perform operations such as adding and removing files not on our database server, but on a separate server with the authorizations given to it. For this situation, I said that the operations should take place in a limited area where the authorizations are specific (just like how paypal, twitch, youtube, google provide us with apis when we write our web applications and we can do something within the limited area they give us). For example, the file listing process or file addition/deletion process should take place in this area according to this logic. I thought that these can be realized by using the methods (functions) provided on the database server.

Tomorrow I will revisit the question from a different point of view and first of all I will try to form the solution as you say. Many concepts have accumulated, in fact, I have formed snippets of ideas about many things, but I have some difficulty in forming the whole.

On this website I'm looking at the concepts (separately for frontend, backend, and other topics). I feel like I've learned something, but I still haven't learned things that I've heard dozens of times, and I'm looking forward to consolidating what I've learned and building a really unique algorithm of my own and creating something.

Day 33

I had a look at different topics today, but most of the day was on REST API. First of all, I did the task you gave me, and I think it's mostly correct, but I don't know how correct it is. And I don't know how to optimize it. After that task, I read a book written entirely on REST API. Yes, I also finished a book on the subject. I had a hard time working for a few days, but while reading the book, I thought it was actually simple things. And things that seemed very complicated 3 days ago now make more sense. I think I have a great understanding of the subject now.
I wanted to expand my horizons and limits by seeing some different algorithms after working hours. I built a machine learning (neural network) structure in the simplest way and looked at how to create and write an algorithm only with javascript. Since it's called machine learning, I wondered if we could apply machine learning topics here, since machines are involved in the server-client issue that we have been focusing on for 3-4 days. While topics such as chatbot, recommendation for web app can already be done with AI or similar ways, I thought what could happen in communication between servers and server-client. But I haven't found anything yet.

Day 35

I think today and yesterday were very soft. I always tried to add something when I was free. The tasks you gave today were also things that were generally done by reasoning and I think I was able to establish the general logic, even though I did not get a complete feedback from you.

I can explain the change in 1 month in the simplest way: 1 month ago I didn't know what an object was, I didn't know what a design pattern was, I didn't know why it was used, I didn't know JavaScript at all, I still don't understand when I learned CSS at a basic level. Now, writing something with JavaScript or reading things written in that language, finding and learning new algorithms, solving them, it's like a puzzle. You said today that there is a competition between you or something like that. Yes, sometimes there can be things like who sent the answer fast, who finished fast, who understood fast. But I try to isolate myself from everyday life, other people, other people's salaries, other people's thoughts, male-female relationships, friendships and whatever. The reason? My motivation, I mean, I made up my mind to learn this job a few months ago and I seriously feel that it has turned into a passion or a hobby. Or there is no such thing and I may be shaking my head. But no, I really enjoy it and the last thing I want is for this beautiful thing to be spoiled. So if I compare myself to people, I won't be happy, my motivation will drop. I get stressed. That's why it's best to be interested in what I do, not in people. I think it is a very, very big chance to earn my bread and do what I love. That's why I'm happy and I show it a little too much, but I don't think I can help it.

One last thing, there was a very simple example of the algorithm in the book you sent. I wrote a nice option to that simple example, which is also only 10 lines (keeping the number of loops much shorter than the example in the book). And even that simplest thing made me very happy. Yes, this may have occupied a place in your brain unnecessarily. I apologize (:

That's all for today.

Day 35

Today was all about CSS. It was all repetition and practice. Did I learn anything new? I didn't learn anything new, but I remembered the parts I had forgotten. After working hours, I only examined carousel examples. Yes, a normal ordered carousel can be made only with javascript and CSS, but I realized that it is very difficult to make a draggable carousel with the mouse. Although I spent a few hours, it didn't work. I looked at examples on the internet. SCSS, React.Js, Angular Js have been done in many different ways, but I couldn't find a way with simple level CSS and Javascript. Obviously there were ways and examples, but it was quite complicated. That's all for today.

Day 36

I think the example we did yesterday was a bit too problematic. But of course it was finished somehow. The example you gave today looked very nice with the flex structure. Considering the structure of the page in terms of responsiveness, the use of flexes worked very well. I finished the page, but I hadn't done the carousel parts. I found a very nice w3school example about the first carousel. I will examine it and try to do something similar on our page tomorrow. Did I learn anything new? I learned some things in terms of practicality, but I didn't learn a brand new algorithm or something that opened my horizons today. But it was a good day in terms of work.

Day 37

I was satisfied with the site design we made today related to CSS. Especially the carousel took some effort. It was not a simple copy-paste. I understood where and why you used what and why. There was also the carousel part. Of course, there are issues such as the most optimized solution and responsive design. I think he was also good at responsiveness. I think this is the first time I'm praising something I've done myself, so I'll skip here.
I did some research about variable scopes in PHP and JavaScript (we learned this, but I looked up the differences again). I wrote small examples on top of it, so that I could understand what the meaning of what I wrote was. It's not really a homework assignment, it's more of a way to explain something to myself and to keep what I've done as a repository.
In summary, the day's learnings and practices: CSS (especially carousel work, and other edits), scope in PHP.

Day 38

Today I researched, learned or tried to learn a lot of PHP related stuff in "w3school" and I was thankful. And the best thing of the day was that feeling of thankfulness. After more than 1 month of working with JavaScript, I realized while looking at the PHP content that I've actually learned something. I was surprised how fast the topics in PHP can be understood. Of course it's not deep, but in general it's much faster to understand the concept and the content. That's why I thanked everyone who contributed to the production today. The story you told with the symbolism of the torch illuminating the dark forest is of course true, but my torch still gives very, very weak light. So thank you very much for lighting my way again with the big torch. While I was studying PHP today, I actually felt like I was studying JavaScript, because the basic structures (coding, programming, scripting, whatever you call it) overlapped in many places. But I was especially surprised today: I felt like there were millions of functions in PHP. It really seemed like there was a built-in function for every topic. While I was reading those functions and their functions, I was wondering how the algorithm of this function was built and written. It was similar to how I felt when I was looking at your example for DOM manipulation in JQuery. I also realized something today when I was studying PHP. We had actually done many examples of object-class in JavaScript and I couldn't make sense of their general concept at the time. Even though I understood a little bit why we did it, I never thought that the general name of this was OOP (or the building block of OOP). I realized it today while reading about OOP in PHP, of course. The readability of such a long paragraph is of course very low, but I would like to add one more thing: When I learn something, when I try to understand the concept, when I learn about other people's solutions to problems and concepts in web development, my hunger is not satisfied and I want to look at it again after a little rest. This is very strange for me. Yes, I loved math and physics in high school, yes I used to study a lot, but the only time I remember having this craving was when I was learning what trigonometry was. I am very happy to have the same childish and pure desire again after so many years. Thank you very much again from the bottom of my heart. I hope we will not let you down in return for your labor and investment, and we will learn a lot too. We can raise the machine (computer, web server, client, whatever you call it) language to the level of "native speaker". I mean, it is very difficult, but why not, right? In short, we become much more "useful" in the company we work for. Yes, I realize that I've spread a little too much positivity (and maybe empty words), but if I didn't write what I felt inside, it would stay inside me, it wouldn't be very nice.

The quote of the day comes from Steve Jobs:

“Stay hungry, stay foolish”.
May our hunger and determination to learn always continue.

Day 39

If you hadn't done the JavaScript part of today's example, I still think I could have done it. But it would have taken a little more time because I couldn't get the recursive part down. Since what I felt was missing was the logic of the work rather than a programming language, I studied recursive function examples and algorithms after work. I tried to write the easy ones myself. For the medium difficulty ones (trade-offs*speed-time*feasibility) I tried to understand the direct authors' point of view on the solutions. I tried to understand the order in which different answers to a problem are constructed.

For example, I came across a question about how many different ways a person can climb a staircase with "n" number of steps by taking one or two steps. Basically, the solution was similar to the algorithm to find the "nth" Fibonacci number by how many calculations. Although I understood the recursive solutions (keeping an array in memory and preventing doing the same calculation over and over again and the other one was with the simplest recursion method called brute force algorithm, which takes time and tires the CPU), I didn't understand something in the dynamic programming method. If I looked at it for a while, it would be understandable, but I couldn't focus on it much with the tiredness of the day. I reached the sample algorithms from: Javascript Algorithms

If you say, "So what did you do today, Buğra? Tell me what you did during your shift", first of all, I set up the example you gave in the morning. I determined what I needed to do. While I was getting ready to do it, you showed me how to write it in JavaScript. After that, I tried again, but it didn't work. Honestly, it was so much fun to play with the code that I lost a bit of time because I was always doing other things, figuring out what does what, what to do with what, what to do with what, etc. When you then printed the JavaScript code again, it was very easy to return it to PHP. The only problem is that I don't know PHP very well, so I had to look up new concepts one by one. But I think that's normal too. The most beautiful thing I feel today is that we can have a direct client side output with code written in PHP. The ugliest thing I feel today is the question of how we can debug in PHP. With Node.js it was much easier to see when there was an error in JavaScript code, where it happened or why it happened. But here (also because we're new) it's not easy to see.
We have done a lot so far (relatively). I am sure we can learn this too.
1 month ago, I was memorizing a little bit more like this method will work, but now I think the more I study, the more problems and solutions I see, the more I reach, the more I will be exposed to it and the better it will be learned. Just like a foreign language. So my only goal is to be exposed to this language, this universe as much as possible.

Day 40

Most of the day was spent researching PHP related topics. I tried to learn how the structures we learned in JavaScript work in PHP. Since it was mostly reading, I may stumble a bit while practicing, but it gave me familiarity.

At W3Schools, I have read a lot about PHP, tried to understand it, and tried to write it myself when necessary. In particular, I can say that I did a study by looking at the counterparts (if any) in PHP of what we have encountered so far in JavaScript. I couldn't ask you anything because I didn't have many questions in my mind. I was able to ask google and find the parts that were stuck. In JavaScript, most things were built on objects. I couldn't figure out which data structure is more dominant in PHP, but I was surprised by the abundance of functions (although in JavaScript they are also considered as objects, I don't know how it is in PHP). I found it interesting that the object structure, which we learned before as an instance of a class and an associative array, was created in two ways. I wondered if only associative array could be done, but I answer my own question by saying that it is not possible to write something unnecessary for a program that has been running for years (the answer is probably related to the need to create the object-class relationship). Today, for example, I saw two methods like "__constructor(), __destructor()" created in the class. At first I thought it was very similar to getter setter logic, but it turns out that "__constructor" is the same as "constructor" in JavaScript. The most surprising thing for me today was to encounter "access modifiers" such as "public, private, protected" which I had never encountered in JavaScript. Since it was the first time I encountered these terms, I tried to understand them well. I think I grasped them quickly because they were simple. Just like in JavaScript, there was a static method here. I also encountered "classes and methods" such as namespace, iterables, trait, interface, abstract. Since I haven't solved any examples on these, I assume that they will be erased from my memory immediately. So I may need to look at them in a little more detail.

Actually, I really wanted to explain everything I learned and write it down here, but since I was looking at so many things today, it would have taken pages if I tried to write it down. Instead, it made more sense to try to solve the examples as I came across them, use them and write about them.