First 250 days of software dev - Part 12

13 min read

Day 111

Today, logging in and forgot my password are completed. A random and temporary code is generated and sent to the user who has forgotten his/her password via the method of his/her choice (email or sms), just like the activation code. The user who comes to the system with the link to which this code is connected is directed to change his password, but I haven't reached that stage yet (This will also be discussed in the section of the operations that the user can do on his own information. Most probably by using the get method from the incoming link and maybe with the help of regex, the existing code can be retrieved, its correctness can be questioned and then the necessary actions can be taken). Only random code generation, sending, saving to the database, etc. were completed today in the forgot password section.

Afterwards, while preparing to make the front end of the input and registration parts, we wondered again what MVC was and wondered if a system similar to it could be created. It seemed like it could be done with code that was copy and paste and whose logic was not yet comprehended. Obviously, it was tried but it could not be done in a short time (not very short actually) because it had a very fragmented structure and since this was not the main problem at the moment, it was later abandoned (Even though it was abandoned, there were parts that were learned or coded in the mind on the most basic basis: Controller=> It contains get and post methods and user actions that want to enter issues related to the model. Model=> Database relationships, the part that contains the main logic of the system, the part we are actually interested in right now. View=> Html and the part that represents the frontend part shown to the relevant user). The main problem is to solve the system of our website as much as possible, to establish the relationships and connections between entities (software entities).

Tomorrow the classes related to the database will be edited. Problematic parts will be fixed. After completion, login and registration will be finalized (getting information from the user with get and post, keeping the user session with session, and editing a simple frontend used in an old task). It is estimated to be finished tomorrow. If it is finished, the wireframe of the class diagram will be started to be created, which will allow the user to update and see their own information.

Day 112

I thought I would continue coding today. But I couldn't get my head around the class being an object. I honestly thought I understood the last way it was explained (that enlightenment, that feeling of sparking in the brain), but as I dived deeper and deeper, I couldn't get out of it. "Nevertheless, if I write down what I have learned, what I have seen and my notes, at least a document that is a reference for me will be created." Let's get to the main topics without further ado: What is a class? What is an object? What is a reference?

Let's go through the metaphor of a house:

  • Class
    A class is a blueprint for a house. Many houses can be built using this design.
  • Object
    Every house built (instantiate) is an object, also known as an instance.
  • Reference
    Every house has an address. If you want to tell someone where a house is, you give them a card with the address written on it. This card is a reference to that object.
  • Dereferencing
    If you want to visit home, you look at the address written on the card. That's dereferencing.
Note: An address is where the object lives in memory. A reference is a variable that points to this address
<?php
class EvSinifi{
    public function construct(){}
    public function doSomething(){
        echo "hi there, i'm bora :)
 <br>";
    }
}
$evim = new EvSinifi();  //1
caller($evim);  //2
$evim->doSomething();  //4
 
function caller(EvSinifi $digerEvim){
    $digerEvim = new EvSinifi(); //3
}
Let's take a line-by-line look at what happens in this code snippet:
  1. "new EvSinifi()" says that, using the EvSinifi design, a reference to the house is returned. You can copy this reference to the variable $home. You ask a contractor to build a house. He builds it. He tells you the address of the house. You write it down.
  2. You give this address to a method (caller).
  3. Here we have the reference "HomeClass $digerHome". There is a pass-by-value here. $digerHome inside caller is a copy of the reference $home. you gave caller your own card with the address of the house. what does caller do with this card? He asks for a new house to be built and writes the address of the new house on the card you gave him. Note that the caller cannot now reach the first house (the one built in phase 1). But that house does not change or disappear just because another house is written on the address card he has.

To summarize:

  1. Ask the contractor to build a house. Let him build it. He gives us an address. Save this address in the variable $home (write it on a card)
  2. We call caller. Before doing this, we copy the address in $home to a new card that we give to caller. caller calls this card $otherhome.
  3. caller asks the builder for a new house. He builds it, gives him the address of the new house. caller copies this address onto the card we give him.
  4. We go back to the first stage. We look at the original, unchanged card. We go to the house on the card and we do something there.

A different perspective and a different example:

Let us imagine a television (object) and a remote control (reference). We are connected to the television with the remote control. If we want to turn down the volume, change the channel, we first manipulate the reference. It in turn modifies the object. When you move around the room you still control the object with the reference. You move around with the reference with you, but not the TV. Also, the reference can be on its own without the TV. Just because you have a reference does not mean that there is an object to which it is attached.

Let's take an example from Java:

**String s;
No object is being created here, just a reference. If you try to send a message to "s" at this point, you will get an error because "s" is not bound to anything (there is no television). A safer practice is to always initialize a reference when you create it:
**String s = "asdf";
But this is a special Java method. Normally a more general type is used to initialize objects. When you create a reference, you need to bind a new object to it. This is usually done with the "new" operator. Here you say "make me a new one of these objects":
**String s = new String("asdf");

The above examples are actually based entirely on the relationship between object and class in Java. Now let's look at how it is in PHP: Looking at the PHP Manual as the main source, we can see that object and class have the same distinction as in Java. PHP Manual- OOP Reference


Well, does this distinction exist in every language? This is where it is complicated because every language has a different concept as far as I understand. I read that in Objective-C every class is an object, every class is an object. But since these classes are objects, they have to derive from a different class and this class is called metaclass. Just like an object is the expression of an ordinary instance, a metaclass is the expression of a class object (I didn't know anything about it, but since I said it by referring to those who do, I included plenty of tenses).

In Smalltalk, classes, numbers, strings, even the program itself are objects.

I'm a bit confused, but I think the rails will fall into place.

Day 113

Pass by reference and pass by value were given a day. The issue was clearly understood. Although there were many questions and answers, the clearest answer was the simplest answer. And when you delve deeper into that answer, you end up with the same answer. It was as if he was saying, "I was looking for a cure for my troubles, but my troubles were a cure for me; to become a human being, what is needed is wisdom."
$a = $b = deger; 
where variable a is not equal to variable b. It holds the value that variable b holds. This is better understood by looking at the Pointer topic. variables a and b are at different addresses. The only connection between them is that variable a has copied the value that variable b has to itself.
$a = &$b = deger;
here, a and b can be thought of as the same thing. It is like calling a person Tayyip or Recep. The same person is called. Things can still get confusing as we go deeper, but in the most general sense, the issue of payy by value and pass by reference is clearly understood.
One thing that was heartwarming when it was understood today was that the objects themselves are not assigned to the object variable as a result of being created with new, but only the identifier that will find the location of the object is assigned to the variable. It was one of the most confusing issues for me.
Today I mostly studied C++ code on these topics (pointers, references, dynamic memory allocation).

I have to add: That site has given me the most horizon-expanding information of the day (of course you know about it, but that's what it did for me). Pointer Reference


The last two days have been focused on the theory, even though it is not on the agenda. Tomorrow it will be back on the agenda. The mission will continue from where it left off.

Day 114

The first thing today was the database connection and the class arrangement related to the questions. The query methods will be called using a different class. That can be fixed quickly.

Then the codes written for registration and login were combined with the front end. There is a little bit left in the input part, but it is almost finished.

Tomorrow, after quickly completing the deficiencies, we will move on to coding the class diagram created for viewing and updating user information. In addition to what was done today, there were things that were not done but were wondered about:
  • I was assuming that I had sent the code required for account activation by email (an assumption that indicated "sent" as a return in the relevant function output), and I was continuing operations with that assumption. I wanted to try the mail() function. I tried it (by providing the necessary configurations in php.ini and a related file). But I encountered the mail SMTP server error many times and couldn't find a solution. The error is probably caused by the TLS-SSL port. But since I couldn't solve it, and also because more modern methods of sending mail are preferred, I stopped trying. I haven't tried any other method.
  • The second problem of the day was how to get the client ip. Yes, I saw that I could get it using $_SERVER['REMOTE_ADDR']. which I think is the best way. But, How to get the client ip address in php reading that comment, I questioned a bit too much whether there is a security vulnerability.

Day 115

The work we have done before allows me to reach much faster results on those issues. I think this is a very positive thing. At the moment, login, registration, database issues seem to be completely finished. I have coded the IP address protection part, but since I will do the user preferences part tomorrow, it will also be affected from there (in case the user wants protection, I will take the parameter that will come and put it instead of the parameter I put temporarily), so I can say that there is a small nuance left to complete that part.

I think I know what I am doing, what I need to do. I think I understand the relationships between the classes to some extent and I can play with them like a puppet artist (at least at my level). In design patterns, I try to use not what I know, but what I think is the best approach to solve the problem in line with the need. I am hungry to do better, to write cleaner, to fit the concepts better, to get to a level where I can understand the system on my own. I am glad I am. The road is long, but the journey continues.

Day 116

Not a lot of noteworthy code was written today. It was more of a day where I tried to think about what I could do and how I could do it. Towards the end of the day, I didn't feel productive, so I changed the topic and looked at the algorithm book for the last 1 hour. In general, it was a calm day. It was just a bit unproductive because I was looking at a different class diagram and it was realized that it was not constructed very well to put it into code. But I will recover.

Day 117

The part about updating the user's information was looked at today. It got a bit confusing. This is why: it was thought that the user class would be more directive and would not contain detailed logic. But the _set() and _get() magic methods of this class were entered into operations that were not thought to be done in the user class. Therefore, how to get out of the business without much confusion and how to make a good design was thought and tried to be created today. The record entry part was done in a much more systematic way than here. Today, it was felt that it would cause a bit of urbanization. Either the slums will be demolished or they will not be allowed to be built. It is thought that tomorrow the general structure will be revealed even more.

Day 118

Today was the most interesting of 118 days. First of all, I realized that the class diagram I created about updating user information is not very valid while I was working today. I am going out of the concept I created in my head and this is challenging me. I tried to overcome these problems for most of the day, but since I felt my work inefficient and floundered in the same place, I did some reading on related topics afterwards. Tomorrow I will try to move forward with vigor.

Why was today the most interesting day? Yes, maybe I shouldn't think about such things in my professional life, but I was a little obsessed at the end of the day. I thought the person who was crying was innocent. For the last hour, my mind was on that subject, even though I distracted myself. I was upset. But then, when he told me the real reason for his dismissal, I laughed at my own naivety again. I thought I was a bit smart, but it was not a case of "I thought we were the marginal ones". Those who left really did it themselves and found it. I will continue to work and strive to improve myself.

Day 119

Today, most of the day was spent watching your code live, witnessing the code writing and understanding it. I also think I understand it. After work, the strict type issue in php was discussed. The following article came to my mind at that moment, but I couldn't express it fully: Why is processing a sorted array faster than processing an unsorted array

I looked again at what you meant here. There was a train analogy in the answers. That's why today's topic brought branch prediction to my mind, although it's not very relevant. I won't go into details because I don't know much about it, but I will research and learn it later because I was curious.

A Nietzsche quote to mark the meaning and importance of the day:

“Verily, I have often laughed at the weaklings, who think themselves good because they have crippled paws!”

Day 120

Today I was thinking about using namespaces, writing classes in a separate file and accessing them that way, using autoloader, how the directory structure should be, the existence of some standards in PHP created by people who write frameworks.

First of all, since I had experienced the problems caused by the lack of namespace many times before (the same class names overlapping and the program producing undesirable results), I had already looked at its use and knew why it was used. So there was no problem there. What I encountered for the first time today was the autoloader itself. I learned what autoloader is, how it works, and then I needed to understand how the directory structure of the files should be. There was no single truth about this on the internet. Everyone had different approaches to directory structure. There was no single formula, but there were some solutions that were generally preferred: My main source for this was this article: On structuring php projects.


I could separate files-classes according to their archetype (like behavior, for example, files that behave as controllers) or I could separate these files according to their feature (called feature, for example, collecting files containing concrete classes related to the product in one place). The author talked a lot about the benefits of grouping directories according to feature. For example, when a developer looks at the directory, they can quickly get an idea of what the application is doing. It is actually much more organized code generation. One of the main details in the code we wrote (or rather you wrote) was also in this article: "Separate general purpose code and domain code". It was mentioned to separate core and classes. Lava could come to us from the core of the earth. But we couldn't go down to the core. The sun would warm us, give us life. But we didn't add anything to the sun, the sun didn't need us (who knows?). In the same way, the files in the core folder have no dependency on the classes folder where the domain classes are located. But there is the opposite dependency.

If I mention something out of the day, yesterday I noticed a few problems when I accessed the site from my computer, which of course you know, but I just saw it: there was an error in the sizing of the photos in the carousel because of the smaller screen size of the computer. If you canceled the calc() operation on the parts where there was an error, it would fix it. But only for those screen sizes. Today I was curious and downloaded firefox. On the home page I saw something different this time: Some of the boxes (divs) with categories on the carousel had different sizes (related to flex, but I don't know why there is a difference in chrome and firefox yet).