- Published
My Mistake When Start Coding
- Authors
- Name
- Idhamsyah
- @Syahdham
3 min read
I may be one of the many students who feel that I chose the wrong major in college. The first semester met programming language courses, I immediately gave up because of confusion, not to mention courses related to another programming.
After graduating from college, I worked in a field far from programming until one or other reason I came back to the programming world that I wasn't good at the time.
Starting again with the programming world with minimal experience writing code, what I can think of is that the most important thing is that the application can run and haven't an error, so many technical and non-technical things are not my concern, like:
1. Inconsistent and unformatted in writing lines of code
A simple thing that is often overlooking is consistency in writing lines of code, including:
- Improper indentation
public function myFunction() {
for() {
if() {
}
}
}
- Do not name class, function, or variable according to the format, intent, and purpose. For those of you who use the PHP programming language, you can see the PSR (PHP Standard Recommendation) documentation to find out the writing format that PHP has set.
// Using variable names that do not represent their contents
$asek = 'September';
2. Writing a function is too long
Sometimes, writing a function doesn't feel like it's already reached 500 lines. The problem is that when I open that line of code again a few weeks or months later, I forget what the function is actually for because there's too much interaction.
It won't be easy to read when the function is too long because I have to scroll down. It turns out that I have to scroll up again because I forgot the contents of a variable due to the unclear naming of variables.
3. Repeat the line of code
When there is a process, I write each one where the process needs it, so when there is a change, I have to change it in many places, so it is not efficient, and it is a disaster if a line of code is missing. It would be better if the process is making into a function that many methods can use.
Still many things that I can not mention to you about my mistakes when I start to write a line of code, but don't worry. It's okay if you still write everything based on what you know. Over time you'll learn how to write easy-to-read lines of code, not repeating the same lines of code as I experienced.