How to read code

My biggest dream when changing jobs: to learn everything about the project myself. Not to ask a single question, but just spend a little time studying the materials.

I strive for it. And if there may not be ready materials on the project, then the code is always there. That's why I read the code.

I am not a developer. Sometimes I come to projects with programming languages ​​that I do not know at all. But it turned out that it is not difficult at all to understand the syntax of any language in a couple of days. Let's try it with PHP as an example, because it was PHP that I encountered for the first time quite recently.

Where to start

Does everyone know the difference between a framework, a library, and a programming language? I prefer to start exploring a code repository with the documentation of the framework it is written in. In my case, it is Laravel.

How to read documentation

  1. Start by reading the table of contents. You may find that you have already encountered similar entities in other frameworks.

    If there is not a single word in the table of contents that you recognize, don't worry. I'm sure you'll be able to figure it out after reading the pages themselves.

  2. Read the Introduction or Getting Started sections. These sections will give you a general idea of ​​the framework.

  3. If you have or already had more specific questions, do not be afraid to open the corresponding section and read it too. Knowledge is never superfluous.

The reading speed of an adult is about 200 words per minute. Even if it seems like there is a lot of text on the page, believe me, reading usually does not take more than 5-7 minutes.

It was interesting for me that in Leravel many actions happen through facades. I learned a lot about logging and testing in Laravel. I learned about the organization of folders in the repository.

Thanks to good naming on our project, I can now easily figure out what any file I'm in is responsible for. We've figured out the framework. What about PHP?

How to work with unknown syntax

What surprised me most in PHP were the arrows: => and ->. I had absolutely no idea how they worked.

Example of PHP code with arrows:

<?php

// 1. Arrow Functions (PHP 7.4+)

// Anonymous function using traditional syntax
$greet = function($name) {
    return "Hello, $name!";
};

echo $greet('World') . PHP_EOL; // Output: Hello, World!

// Anonymous function using arrow function syntax
$greetArrow = fn($name) => "Hello, $name!";

echo $greetArrow('World') . PHP_EOL; // Output: Hello, World!

// 2. Associative Arrays

// Creating an associative array using => operator
$user = [
    'name' => 'John Doe',
    'age' => 30,
    'city' => 'New York'
];

// Accessing values using the key
echo $user['name'] . PHP_EOL; // Output: John Doe

// 3. Class Properties with Arrow Function

class User {
    public $name;
    public $age;

    public function __construct($name, $age) {
        $this->name = $name;
        $this->age = $age;
    }

    // Method using arrow function for concise syntax
    public function getFullName(): string {
        return $this->name . ' (' . $this->age . ')';
    }
}

$user = new User('Jane Doe', 25);
echo $user->getFullName() . PHP_EOL; // Output: Jane Doe (25)

?>

I don't know who came up with this. But I had to use three sources of information to figure it out: Stack Overflow, the wonderful developer Tanya, and ChatGPT. The moment I realized that all three sources were saying the same thing, I knew I had it right.

How to use ChatGPT

You can ask ChatGPT any questions, like “What are those arrows in PHP?” But its simplest use is: if you give ChatGPT a piece of code, it will interpret it in as much detail as possible.

To interpret the code using ChatGPT:

  1. Enter the phrase: “Explain the code to me:”.

  2. Insert the code and wait for a response.

There you go, you have an explanation for the code. Just be careful, sometimes ChatGPT can lie somewhere.

How to use Google or Yandex

For some questions you don't even need ChatGPT, just google a bit and Stack Overflow might give you an answer about the same arrows, for example.

To find information about the difference between arrows in PHP:

  1. Enter your query: stackoverflow arrows PHP difference.

  2. Open the first page in the recommendations.

Done, you've found the page with information about arrows.

Conclusion

I am not calling on anyone to avoid colleagues and try to figure everything out on their own. It is also necessary to be able to work in a team.

I would just like to encourage you (and myself) with this article to sometimes spend a little more time on independent research. Independent research improves the quality of questions, and you yourself will learn something new that you may need later even if you don’t need it now.

Let's search on our own.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *