Lær det grundlæggende i en god udvikler-tankegang på 15 minutter

“Vanskeligt at foretage selv små ændringer”

"Bryde funktionaliteten af ​​softwaren ved at foretage ændringer"

“Introduktion til en ny fejl ved at rette en anden”

“Implementering af kode, der er unødvendig”

“Næsten umuligt at tilføje en ny funktion på grund af kompliceret kode”

“Det produkt, der aldrig sendes”

"Kaste kode væk og omskrive den fra bunden"

Er alle ovenstående udsagn kendte?

Hvert minut siger (eller tænker) en udvikler fra enhver del af verden nogen af ​​ovenstående udsagn og ønsker at græde. Hvorfor?

Dette er almindelige problemer, som udviklere taler meget ofte om. Disse historier opleves i hvert udviklingsteam.

Der er mange små faktorer, der langsomt og gradvis skader en udviklers projekter. De er ikke umiddelbart ødelæggende. De fleste af dem gør kun langvarig skade. Noget, du ikke kan se skaden i et år eller mere. Så når nogen foreslår dem, lyder de ofte harmløse.

Selv når du begynder at implementere dem, kan de virke fine. Men efterhånden som tiden går - og især når flere og flere af disse stabler op - bliver kompleksiteten mere tydelig og vokser, indtil du er endnu et offer for den stadig så almindelige rædselhistorie.

For at undgå at være et af ofrene skal du omfavne de grundlæggende love i softwaren. Du bør udvikle en tankegang, som enhver udvikler skal have. Denne tankegang hjælper dig med at træffe bedre beslutninger i din daglige programmeringsrejse. Du kan holde din software så enkel som muligt. Du kan beskytte det mod at være et uhåndterbart og komplekst system.

Her er de nøglepunkter, som hver udvikler skal mestre.

1. Opfattelse af formålet med software

Først og fremmest skal du forstå formålet med softwaren. Der er faktisk et enkelt formål med al software: At hjælpe mennesker .

Husk: Formålet med softwaren er ikke at vise, hvor intelligent du er. - Max Kanat-Alexander, kode enkelhed

Udviklere, der ikke kan forestille sig formålet med softwaren, skriver dårlig software. Hvad er dårlig software? Et komplekst system, der ikke hjælper folk så meget.

Når du tager beslutninger om software, skal du guide dig selv ved altid at huske dette: Hvordan kan vi hjælpe? Du kan endda prioritere funktionsanmodninger på denne måde.

2. Målene for softwaredesign

Hver programmør er designer.

Når software er svært at oprette eller ændre, bruger udviklere det meste af deres tid på at få tingene til at “bare fungere” og mindre tid på at hjælpe brugerne. Designet af software sigter mod at få udviklere til at arbejde så let som muligt, så de kan fokusere på det der betyder noget. Du opretter software, der vil hjælpe brugerne, og din software vil fortsætte med at hjælpe dem i lang tid.

Men hvis du designer et dårligt system, vil din softwares levetid være kort.

Dette bringer os til det vigtigste mål med softwaredesignet:

At designe systemer, der kan oprettes og vedligeholdes så let som muligt af deres udviklere, så de kan være - og fortsætte med at være - så nyttige som muligt. - Max Kanat-Alexander, kode enkelhed

Så der er to nøglepunkter her: Dit design skal være let for dig og nyttigt for andre.

3. (Mis) forståelse

Udviklere, der ikke fuldt ud forstår deres arbejde, har tendens til at udvikle komplekse systemer. Det kan blive en ond cirkel: misforståelse fører til kompleksitet, hvilket fører til yderligere misforståelse osv.

Faktisk er en af ​​de bedste måder at forbedre dine designfærdigheder på at være sikker på at du fuldt ud forstår de systemer og værktøjer, du arbejder med.

Forståelse er nøgleforskellen mellem en dårlig udvikler og en god udvikler. - Max Kanat-Alexander, kode enkelhed

Dårlige udviklere forstår ikke, hvad de laver, og gode udviklere gør. Det er virkelig så simpelt.

4. Enkelhed

Enkelhed er den ultimative raffinement. - Leonardo Da Vinci

Programmering er handlingen med at reducere kompleksitet til enkelhed. En “dårlig udvikler” er bare nogen, der ikke reducerer kompleksiteten. En “god udvikler” gør alt, hvad der står i deres magt for at gøre koden så enkel som muligt for andre programmører.

En god udvikler skaber ting, der er lette at forstå, så det er virkelig nemt at ryste alle bugs ud.

Nu er udviklere generelt intelligente mennesker, og ingen af ​​dem kan lide at blive behandlet som om de er idioter. Ironisk nok fører dette dem nogle gange til at skabe ting, der er lidt komplicerede. De tænker grundlæggende sådan:

Åh, andre udviklere vil forstå alt, hvad jeg har gjort her. Jeg skulle skrive en smart kode, der er vanskelig at forstå, så de kan tænke, at jeg er meget smart.

En fejl forårsaget af en forkert tankegang - ikke nødvendigvis på grund af manglende programmeringsevner. De fleste af programmeringsfejlene sker på grund af denne mentalitet.

At vise, at du er smart, hjælper dem ikke.

Udviklere, der er nye med din kode, ved ikke noget om det; de er nødt til at lære.

Så du skal stille dette spørgsmål: ” Vil jeg have folk til at forstå dette og være lykkelige, eller vil jeg have dem til at være forvirrede og frustrerede?

Sandheden er, at hvis andre udviklere, der læser din kode let kan forstå det, betyder det, at du gør det godt.

Kompleksitet har intet at gøre med intelligens, det gør enkelhed. - Larry Bossidy

Spørgsmålet er: "Hvor enkel skal du være?"

Her er dit svar: Dumt, dumt simpelt.

5. Kompleksitet

Styring af kompleksitet er essensen af ​​computerprogrammering. - Brian Kernighan

The source of many software failures is complexity. You start out with a simple project that can be completed in one month. Then you add complexity, and the task will take up to three months. Then you start to add features that fulfill some other purpose. Things get very complex because you expand your software purpose for no reason. The tasks will take six months.

But that is not the end.

Then you take each piece of the feature and make it even more complex, and the task will take nine months. Then you start to introduce many new bugs because of the complexity in your code. Naturally, you start fixing them all without thinking how these fixes will affect other parts. At the end, when even small changes become hard. When bug fixes start to introduce new bugs, you will come to one of the most popular programming horror stories: Rewriting code from scratch.

So, how did you become a victim of this horror story? Nah, who cares. It’s better to ask: How could you avoid being a victim?

Well, it is simple. First, you will exactly know your software purpose and its definition. Second, you will be as simple as possible in every piece of code you write. Third, when a new feature or change request comes to the discussion table, you will evaluate them based on your software purpose and question them.

As a developer, your first behavior should be resistance to (unnecessary) change. This will prevent you from adding unnecessary codes into your software. When you are convinced that this change is a need, then you can implement it.

There are many factors that will increase complexity but those are the most popular ones. Aside from everything, there is only one rule that you should follow:

Your main purpose is to control complexity, not to create it.

6. Maintenance

Maintenance is one of the most important things in software development. Unfortunately, developers usually ignore how important it is. Quick coding and fast shipping look more important than code maintenance. This is the point where they make a mistake — ignorance of future code maintenance.

There will always be some implementation of changes. Not only you have to implement them, but you also have to maintain them over time. As a developer, thinking about future maintenance of changes is one of your main responsibilities.

Alle ændringer kræver vedligeholdelse. Enkelhed og kompleksitet er de to vigtigste faktorer, der påvirker vedligeholdelse af kode. Den lette vedligeholdelse af ethvert stykke software er proportional med enkelheden i de enkelte stykker. Indsatsen for vedligeholdelse er proportional med kompleksiteten af ​​softwaren. Den ene regel, du skal følge om vedligeholdelse, er: Det er vigtigere at reducere vedligeholdelsesindsatsen end at reducere indsatsen for implementering. - Max Kanat-Alexander, kode enkelhed

7. Konsistens

Konsistens er en stor del af enkelhed. Hvis du gør noget på én måde ét sted, skal du gøre det sådan overalt. Hvis du f.eks. Navngiver en variabel thisIsVariable, skal alle dine variabler navngives på den måde (otherVariable, anAnotherVariable osv. Ikke other_variable). - Max Kanat-Alexander, kode enkelhed

Kode, der ikke er konsistent, bliver sværere at forstå. Fortsæt ikke med at tvinge udviklere til at genlære den måde, dit system fungerer på, hver gang de ser på et nyt stykke af det.

I enhver teamsport har de bedste hold konsistens og kemi. - Roger Staubach

8. Prioritering

Hvordan træffer du beslutninger om din software?

Når du står over for mange mulige retninger, hvordan beslutter du dig for, hvilken mulighed der er bedst? Hvad skal du fokusere på, og hvilke funktioner du skal implementere?

For at besvare disse spørgsmål er der tre vigtige faktorer, der hjælper dig med at træffe en bedre beslutning. Denne ligning forklares meget godt i bogen Code Simplicity:

  • Ønskeligheden ved en ændring (D): Hvor meget vil du have, at ændringen skal ske?
  • Værdien af ​​en ændring (V): Hvor meget værdi tilbyder ændringen? Hvor meget hjælper det dine brugere?
  • Den krævede indsats for at udføre ændringen (E): Hvor meget arbejde skal du gøre for at gennemføre denne ændring?

Ligningen er enkel: D = V / E

Ønskeligheden ved enhver ændring er direkte proportional med værdien af ​​ændringen og omvendt proportional med den indsats, der er forbundet med at foretage ændringen. - Kode enkelhed

Når du prioriterer dit arbejde, skal du følge denne regel:

The changes that will bring you a lot of value and require little effort are better than those that will bring little value and require a lot of effort.

9. Solving Problems

The first step is understanding. Know exactly what is being asked. Most hard problems are hard because you don’t understand them. Write down your problem and try to explain it to someone else.

If you can’t explain something in simple terms, you don’t understand it. — Richard Feynman

The second step is planning. Don’t take action. Sleep on it. Give your brain some time to analyze the problem and process the information but don’t spend too much time on planning.

Think before acting.

The third step is dividing. Don’t try to solve one big problem. When you look at the problem as a whole, it can scare you. Divide it into smaller tasks and solve each sub-problem one by one. Once you solve each sub-problem, you connect the dots.

10. Good enough is fine

“Perfect is the enemy of good.” — Voltaire

Whether creating a new project or adding a feature to existing system developers tend to plan everything out in detail from the beginning.

They want the first version to be perfect. They don’t focus on the problem they will solve and how their software will help people.

They start by thinking of every small detail they could think about. Then assumptions and predictions come along followed by “What if” sentences. They have to predict the future because they were now so captivated by the imagination of the project in their mind and their project has to be as perfect as they imagined it.

Actually, they are not aware of what’s waiting for them and how much it will cost them by chasing perfection.

Let me tell you what will happen:

  • You will be writing code that isn’t needed
  • You will increase complexity by adding unnecessary codes
  • You will be too generic
  • You will be missing deadlines
  • You will be dealing with many bugs caused by the complexity

Do you want this to happen? I guess no.

What you should instead?

Start small, improve it, then extend.

Det inkrementelle design skal være din guide. Sådan bruger du det til at designe en lommeregner:

  1. Planlæg et system, der kun tilføjer og intet andet.
  2. Implementere det.
  3. Forbedre det nu eksisterende systems design, så du også kan tilføje andre operationer.
  4. Planlæg subtraktion og gentag trin 2 og 3.
  5. Planlæg multiplikation, og gentag trin 2 og 3.
  6. Planlæg division og gentag trin 2 og 3.

11. Forudsigelser

”En forudsigelse er simpelthen en prognose om, at der vil ske noget i fremtiden. Det kunne være faktuelt og baseret på en slags objektive data, eller det kunne være baseret på en antagelse. ” Når de står over for det faktum, at deres kode vil ændre sig i fremtiden, forsøger nogle udviklere at løse problemet ved at designe en løsning, der er så generisk, at (de mener), at den vil rumme enhver mulig fremtidig situation. - Kode enkelhed

Being too generic involves a lot of code that isn’t needed.

You can’t predict the future, so no matter how generic your solution is, it will not be generic enough to satisfy the actual future requirements you will have. Most probably, this time will never come and the code you wrote to solve future problems will increase complexity, make it hard to change the pieces of code and eventually it will become a burden that may destroy your software.

Don’t predict to future. Be only as generic as you know you need to be right now.

12. Assumptions

What is the assumption?

“An assumption is something that you accept as true or suppose to be true, although you have no conclusive proof.”

One of the great killers of a software project is assumptions. Let’s see how an assumption can kill a software project.

En udvikler ved, at de er nødt til at udvikle et system til at gøre X. Derefter tror de, at systemet vil kræve, at de gør Y i fremtiden, og de implementerer også Y. De skriver tusinder af linier kode for at designe Y.

I fremtiden indser udvikleren, at de nuværende krav er helt anderledes end hvad de troede. Men nu har softwaren unødvendige koder, der gør det svært at smide, fordi alt er sammenflettet. Det tager måneder at omlægge koden, og nu tænker de at omskrive hele softwaren fra bunden, hvilket får dem til at miste måneder.

Følg denne enkle regel for at undgå at være et offer som denne udvikler:

Koden skal designes ud fra hvad du ved nu, ikke på hvad du tror vil ske i fremtiden. - Kode enkelhed

13. Stop med at genopfinde

If, for example, you invent your own garbage collector when a perfectly good one exists, you’re going to be spending a lot of time working on the garbage collector, when you could just be working on your software.

The only times it’s okay to reinvent the wheel is when any of the following are true:

  • You need something that doesn’t exist yet
  • All of the existing “wheels” are bad technologies or incapable of handling your needs
  • The existing “wheels” aren’t being properly maintained

Simple rule:

Don’t reinvent the wheel.

14. Resistance

As a developer, your first reaction to changing requests should be “NO’’.

Always resist adding more code, more features until you are convinced that they are required and there is a need to implement them. Because unnecessary changes will increase defects in your software.

How can you know that there is a need for them?

Go back and remember your software purpose. Then remember the simple equation in prioritizing section.

From: [email protected] (Russ Cox)Subject: Re: [9fans] design clairvoyance & the 9 way Date: Thu, 8 May 2003 04:05:31 GMT > What does tomorrow's unix look like? I'm confident that tomorrow's Unix will look like today's Unix, only cruftier. Russ

15. Automation

Don’t spend your time on repetitive tasks. Set them up and forget about them. They can work while you are sleeping. When you realize that you are doing something again and again, just remember this rule:

If you can automate it, automate it.

16. Code measurement

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

— Bill Gates

I see developers who measure their software quality based on code lines. They think that more code lines mean that they are doing a great job. The software contains hundreds of thousands of lines of code, which means the software they work on is so big.

The question that pops up here is: Is it really that big, or there is something wrong there?

The answer is that most probably there is something wrong with their design. Most of the simple solutions don’t require a lot of code. You can achieve simplicity with a little bunch of code and solve the problem.

I’m not saying that fewer lines of code is always better. While you want to avoid having less code, you can easily fall in a trap that will cause you to write clever code that is hard to understand for others. You should find a balance.

The optimum code is a small bunch of code that is easy to understand, easy to read.

17. Productivity

How do you measure your productivity?

By writing more lines of code or by throwing hundreds of lines of code away?!

Your main goal should be keeping your code base as small as possible. The question is not “How can I write more code?” rather it should be “How can I remove more code?”

“One of my most productive days was throwing away 1000 lines of code.” — Ken Thompson

18. Testing

When should you add logging and error handling to your project?

You should add logging in a very early stage. This will help you to find the problem easily and save your time.

I see many mistakes when it comes to testing code. Let me give you an example. There were two conditions, a simple if-else block. The developer gave input to the software which will enter inside the if block. They tested it and committed code to source control. Done!

But what about the else block? When the software was shipped to production, that caused a lot of errors. When you test your code, you must execute all new lines at least once and you should start to test parts before the whole.

When you have a bug, first you should reproduce it. You shouldn’t guess the source of the bug and apply fixes based on your assumption. Most probably, you will be wrong. You should see it with your own eyes before applying the fix.

You should be reliable. When other developers in your team see that you committed new code to source control, everyone should know that your code is tested, and works.

Untested code is the code that doesn’t work.

19. (Under)Estimation

Developers’ estimation sucks.

Usually, they underestimate things rather than overestimate them. They underestimate the time and effort required to develop a small amount of code or a feature. In the end, this underestimation leads to missing deadlines.

The solution: Break the big thing into smaller things. The smaller it is, the easier it is to estimate. You’re probably still going to get it wrong, but you’ll be a lot less wrong than if you estimated a big project.

Remember:

Everything takes longer than you think.

20. Running Away From Rewriting

I believe that when you embrace the fundamental principles of software development mentioned in that article, you won’t come to this point. However, if, somehow you make these mistakes and find yourself thinking about rewriting your code, here is the main thing that you should know:

Rewriting code is often a developer delusion, not the solution in most cases.

Why is it a delusion?

Well, because it’s harder to read code than to write it. This is why it is so hard to reuse code. This is why our subconscious mind whispers to us “Throw it away and start over” when we read another developer’s code.

There are many cases that you should consider to rewrite your code from scratch and you can read them here. But, here is simple advice for you:

Refactoring should be the first option.

21. Documentation and Commenting

One of the common misconceptions about commenting is that developers add comments that say what code is doing. This is wrong. That should be obvious from reading the code. If it’s not obvious, it means that it is not readable and it should be made simpler.

Når du ikke kan gøre koden enklere, skal du tilføje kommentaren for at forklare denne kompleksitet.

Det virkelige formål med kommentarer er at forklare "HVORFOR" du gjorde noget, ikke "HVAD" det kode gør. Hvis du ikke forklarer dette, kan andre programmører blive forvirrede, og når de går for at ændre din kode, kan de fjerne vigtige dele af den. - Kode enkelhed

Skriv en kommentar for at forklare “HVORFOR”, ikke for at forklare “HVAD”.

En anden ting er at dokumentere. Det er vigtigt at have dokumentation, der forklarer din softwares arkitektur og hvert modul og komponenter. Dette er nødvendigt for at se billedet på højt niveau af din software.

When a new developer joins your team, it will be easier for them to understand the software as a whole. When developers don’t have any clue about other parts of the software, they could easily make a mistake in their own part which can affect other parts also.

22. Picking Technologies (Tools, Libraries, etc.)

First things first, always remember this rule:

Don’t depend on external technologies.But when you have to do so, try to reduce your dependency on them as much as you can.

Why is that? Because they are another common source of complexity. They can kill your active development and make everything even harder.

When you are dependent so much on external technologies, you are not free. What if there is a major bug in that technology? You have to wait for the developers to fix that bug and if this technology is in the center of your project basically you are stuck, you can’t move forward. So that’s why it is so important to pick the right technologies for your project.

There are a few factors you should consider before you start using some technology:

  • Is there active development behind it?
  • Will it continue to be maintained?
  • How easy is it to switch away from?
  • What does the community say about it?

If you can find the right answer these questions, you can reduce the risk of picking the wrong technology.

23. Self-Development

Keep learning. Try out different programming languages and tools, read books on software development. They will give you another perspective. Every day small improvements will make a real difference in your knowledge and skills.

Be open-minded. Don’t be obsessive about one technology. Use the required technology to solve a specific problem. Don’t be in the unnecessary discussion like Microsoft vs Linux :)

Know that every specific problem has its own specific solution.

24. Don’t be a hero

A lot of times it’s better to be a quitter than a hero. As Jason Fried explains,

Lad os for eksempel sige, at du tror, ​​at en opgave kan udføres på to timer. Men fire timer inde i det, er du stadig kun en fjerdedel af den færdige måde. Det naturlige instinkt er at tænke, "Men jeg kan ikke give op nu, jeg har allerede brugt fire timer på dette!" Så du går i heltemodus. Du er fast besluttet på at få det til at fungere (og lidt flov over, at det ikke allerede fungerer). Du tager din kappe og lukker dig væk fra verden. - Jason Fried

Vær ikke besat. Ved, hvornår du skal holde op. Tøv ikke med at bede om hjælp.

25. Stil ikke spørgsmål ... Bed om hjælp

Når du har noget at implementere, og du ikke er sikker på løsningerne, så spørg ikke andre, hvordan man gør det ... i det mindste ikke med det samme. Prøv i stedet alt hvad du kan tænke dig. Dette er vigtigere jo mindre komfortabel du er med et koncept eller sprog.

When you can’t think of anything on your own, search! Find answers and try them out. Modify those answers, see if you can understand why they work, adapt them to your code.

…But always seek advice.

When you have tried everything, and preferably after you have a working solution, now is the best time to seek advice. Look to peers and senior developers to review your code.

I tried to explain the fundamentals of a good developer mindset in this article. I used some part from Code Simplicity book which has a big impact on my thinking process as a developer. When I read this book, there was a lot of moment that I reacted “ohh I did this mistake, I did that too.” I mentioned some important parts of the book and combine them with my experience.

I strongly recommend you to read Code Simplicity from Max Kanat-Alexander.

Tak for læsningen! Jeg håber, at denne guide hjalp dig!

Du kan læse flere af mine artikler på // huseyinpolatyuruk.com .