EloiStree / CodeAndQuestsEveryDay

Regular research on the Quest for developers.
http://codeandquests.page.link/discord
32 stars 3 forks source link

Unity Code Question: What is a clean code ? #384

Open EloiStree opened 4 years ago

EloiStree commented 4 years ago

image

If you are asking yourself this question:

This post is just a reminder of subjects that can be learn to improve your skills in writing "clean code". And it is just some clue based on my point of view.

Good learning to you. And may the code be with you.

BeauCode


For me clean code is not something that can't be "teach". It is something we practice by failing.... Failing a lot... And then failing more.

And at some points, you will be able to smell bad code and avoid it instinctively.

At that point only, you will be able to learn or to be taught how to write good code. Because you will be ready to listen and you will have fail enough to see what the walls to avoid are.

When you are going to be in this situation, you will be interested to read those books: image

image


image Just a remind for the young developer don't be affair to write shit.
You will always find dinosaur that have 20+ years of experience in coding.
That why they can write "Clean code". Don't try to compete, just have fun 😅.

Good luck.

EloiStree commented 4 years ago

Clean code

image
Watch a very good resume of it: https://youtu.be/HZJxjlvBbVA

Let's talk about it (Live Video)

Default Alt
https://youtu.be/RN40pTHyuQw?list=PLH1fn6y2samt0xfBGC26-1M3pzPImN3p2

Playlist with video about the subject

image
Watch the play list

image

Quote

EloiStree commented 4 years ago

Black box

A clean code is a code that is so good that people don't need to access it

Unity Editor tool

LOD of Unity example

If you use the LOD of Unity, you will observe that it is so well design and simple. That it can't but and is easy to understand. For this, no body will go in the code to check what is behind it except by curiosity or re-engineering.

EloiStree commented 4 years ago

Release workable asset and fix issue

Phone support problem example

One day a support phone had 10, then 100, then 1000 of call per day... And after weeks that the team did try to fixed the issue by hiring more and work on the workflow to filter the client problem. At the end someone propose to fix the problem... And since then, no call anymore.

Git production workflow

image Source

EloiStree commented 4 years ago

Pseudo code

Wiki: EN

With commentary

// Access Input Data
// Verify Input Data
// ComputerThe[Object]Position
// Apply Offset to the Input
// Flush And Close Created Object

With Methode

AccessInputData(...);
VerifyInputData(...);
ComputerThe[Object]Position(...);
ApplyOffsetToTheInput(...);
FlushAndCloseCreatedObject(...);
EloiStree commented 4 years ago

State Machine

image

On the store

Find some state machine tool:
https://assetstore.unity.com/?q=state%20machine&orderBy=5

Default Alt Tutorial on how to use Bolt and Play Maker

PlayMaker

PlayMaker

Bold

Bold Logo

Animator

Default Alt
https://youtu.be/lpekqN4_4xg

State pattern explain and demo

Default Alt
https://youtu.be/N12L5D78MAA?t=209

EloiStree commented 4 years ago

Artiste ?

To be trustful, I don't know what is the point of view of an artiste on a clean asset. Here are some clues. But in resume. Care of the asset and how it will be use by other.

EloiStree commented 4 years ago

Bad code one day, bad code forever

Legacy Code

Risky way to deal with it

The soft porn as protection for unfinished parts

The method is simple. Put some soft porn in the scene you are working in. It guaranty the scene to not be published without last checking from the team.

Less dangerous

Add "Weird Easter eggs" in full sight and some water mark ("InDevelopment") over textures

For the code part

Instead of hiding problem or try to corrected when you should not. Just send throw new System.NotImplemetedException("Don't publish without finish this code part"); Or send a DebugSound.PlayWindowXPSound();

Less dangerous

Add some Unit Test that are blocking in development and automatically removed in build versions: Asset.CheckSomething()

EloiStree commented 4 years ago

Random reminder

EloiStree commented 4 years ago

Design pattern

Don't fear them. you are doom to make the same mistake that your elders.

Tutorials and link on design pattern
image

You are already using it

You should know

image

More

You can find a draft check list here of some patterns to learn

EloiStree commented 4 years ago

image

Refactoring & Anti Pattern

image

EloiStree commented 4 years ago

Funny moment

In the old day. They were not debugger. And when coder were introduce to the concept. They did not understood the meaning of it. Because code should not be improvise or bad in the first place ! image image

Challenge: Still sometime the case with VR & Hololens

If you want to feel what they means by code should not be bad in the first place. Try to make a game in Unity without the editor and/or by waiting 10 minutes between each build... !
Or try to compile with Oculus Integreation or Hololens UWP Applicatoin 😅

EloiStree commented 4 years ago

TDD: Test drive development

image

Unity Test

Default Alt
https://youtu.be/GIJptHunxow


image

EloiStree commented 4 years ago

Code take time & The Geek Curve

image

"The art of computer science is too lose a huge amount of time to help other in winning countless small amount of time." (#Mom, Christine Louette)

EloiStree commented 4 years ago

Debug and scope code

For me a "clean code" is also a code that will allow you to scope in short amount of time where is a specific bug and correct it easily without have a fear of breaking every thing. image (PS: I love "event"... But they are the worst! Just because they don't have stack to follow form where they come)

Testers... Nice to have or required ?

PIANo TV

PIANo TV is a tester tool to not make lose the time to programmers by taking time to understand fully the bug you want to notify to the developers Play, Identify, Amplify, Notify... optionally test and verify.

Video game tester o_O ?

Default Alt
About the job: https://youtu.be/JIYTR_zZv_w?t=69

Default Alt
How to acces the job: https://youtu.be/ek9ZRPHRRtk

Be tester and be well payed ?

Look at: Cucumber, Selenium, TDD, BDD, Unity Test...
Default Alt
https://youtu.be/RbSlW8jZFe8

EloiStree commented 4 years ago

Bug is a damn excuse for lazy bad code

image

EloiStree commented 4 years ago

Bad code can kill people !

“Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live” ― John Woods

Hit keyboard face COME ON

Bad code kill countless companies !

Death project living in the corner One main reason of learning to write clean code is simple: Bad code kill companies !

EloiStree commented 4 years ago

Nomenclature ?

Fuck C#: Getter and Setter

> It is my point of view not the true< Try to understand this line without looking at the code: Utility.Orange.IsPress = true; vs Utility.orange.SetPress(4);

// I JUST SAID DON t LOOK THE CODE ;) 
public class Utility {
public Orange { get; set; };
}
public class Orange {
public bool IsPress { get; set; };
}

Fuck C#: var

var vehiculeFound = GetVehiculeFound();
//vs
VehiculeWithWhell  vehiculeFound = GetVehiculeFound();
// Don't be fucking lazy... Or go do some PHP / Javascript  🙄.
//PS: I know it is a bad example as GetVehiculeFound() should be more expressive in its intent.
// But I read this shit too much... to not notify it.
EloiStree commented 4 years ago

MVC

image FR - EN

MVC vs MVVC ?

Default Alt
https://youtu.be/qzTeyxIW_ow

Example

image image

EloiStree commented 4 years ago

Complexity of a code ?

Clean code and efficient code is not the same, but take in mind that it is important to most of us. Sort complexity

EloiStree commented 4 years ago

Unity Drag and drop philosphy

I love this one. But it is more hard that is seem To Do: Try to explain it in more detail.

Unity Package Manager 🙏

1. Avoid messy spaghetti code 2. Push developer to create asset reusable from project to project 3. Avoid people to mess around your code but let's them watch

Classic Unity Package

Every package should at least have this basic structure or something like this. It is not a rule but it helps your users to understand how to use your tool without documentation

Unity Forum post about folder structure

EloiStree commented 4 years ago

Unity Best practices and tips

EloiStree commented 4 years ago

Ergonomic Reminder (Hors sujet) (FR)

Download my tool: Remidner 10111518arbreFinalCritereErgonomie Critere d'évaluation d'ergonomie.pdf

EloiStree commented 4 years ago

UML

Class Diagram

Default Alt
https://www.youtube.com/watch?v=UI6lqHOVHic

image

User Case

Default Alt
https://youtu.be/zid-MVo7M-E image image

EloiStree commented 4 years ago

Two main underrated subjects to break your code

Lost yourself in small addition

Commit strip small code

Too much deathline in a raw

Negative cycle of rushing features and deathlines Cycle of the deathline

Planning

Long live to SCRUM on this one If you find yourself coding the weekend to fit a need on the application. The scope is to big and the planning not well setup. The accumulation of the work, the sleep depth and the rush will automatically lead to dirty code. Commit Stip

Scrum & Kanban

image

Default Alt
https://youtu.be/rIaz-l1Kf8w

EloiStree commented 4 years ago

Clean code is a gift you offer to yourself

image

EloiStree commented 4 years ago

Inheritance vs Composite

image Inheritance and Composition has same goal to assist in reusing tried and tested goal their choice brings different challenges. Composition provides better way to reuse code and same time protect the class you are reusing from any of its client Sometime though Inheritance is necessary, mainly when you are creating class from same family