How To Increase the Quality of Your Code

  Рет қаралды 14,035

Engineer Man

Engineer Man

Күн бұрын

In this video we'll talk about some simple ways to increase the quality of your code to help in the short and long term.
0:00 - Intro
0:12 - Think Before You Write
1:14 - Use Helpful Comments
2:17 - Stick to a Standard
3:04 - Code Clearly
3:31 - Introduce Automated Testing
4:57 - Limited Heavily Abstracted/Tightly Coupled Code
Hope you enjoyed the video!
Join my Discord server and come say hi:
/ discord
Check out some code on my GitHub:
github.com/realtux
github.com/engineer-man/youtube
Other Social:
/ engineerman
/ _engineerman
www.flaticon.com/free-icons/a... Arcade game icons created by Freepik - Flaticon

Пікірлер: 52
@tobias-edwards
@tobias-edwards Жыл бұрын
"Limit abstracted code... avoid OOP" - great advice! Most open-source repos build abstractions upon abstractions making it very hard to understand and contribute. The repos that stick to the vanilla implementation and sacrifice a little DRY are the best
@EngineerMan
@EngineerMan Жыл бұрын
Completely agree. Some duplication in exchange for huge increases in reality is always a solid trade-off.
@benhetland576
@benhetland576 Жыл бұрын
The abstractions often help achieve encapsulation. Encapsulation facilitates decoupling. That is not to say it's hard to write tightly coupled code in OOP -- it certainly is done way too often -- but that is what it provides that it seems FP tends to make harder. Either way each may be the most suitable choice depending on each specific application or problem domain.
@tobias-edwards
@tobias-edwards Жыл бұрын
​@@oppenheimer11 Let's say you are using a new framework called Framey. Framey is really cool and it offers a special class called Basey that the documentation shows you how to use: class MyClass extends Framey.Basey {} Sweet, simple, right? Now new people who have never seen your code before can immediately understand that MyClass uses Framey's Basey class - just like the documentation! A week later, you're using Basey in 2 classes and they share a function called hi to print "hi": class MyClass1 extends Framey.Basey { hi() { console.log("hi"); } class MyClass2 extends Framey.Basey { hi() { console.log("hi"); } } You wanna be DRY so you create a new class that implements hi. Your code soon becomes: class MyBasey extends Framey.Basey { hi() { console.log("hi"); } class MyClass1 extends MyBasey {} class MyClass2 extends MyBasey {} This is nice, right? For such a trivial example, maybe. But let's imagine a real-world scenario where this is happening on a more complex scale, and MyBasey extends from another class MyBasey2 which extends Framey.Basey. All of a sudden, if I'm a new dev and I wanna understand what MyClass1 is, I first see it extends MyBasey - WTF IS MyBasey? I see MyBasey extends MyBasey2 - WTF is MyBasey2? It's unnecessary layers of abstraction that makes it harder to understand that you're just using Framey's Basey class with a few extra features. Note my example is also using inheritance which can lead to all kinds of extra problems e.g. what if MyClass1 extends MyBasey but shouldn't have a hi method at all? tldr; code redundancy isn't always that bad if it improves understandability. As Kent C Dodds says, instead of DRY (Don't Repeat Yourself), consider WET (Write Everythign Twice) and AHA (Avoid Hasty Abstractions). You can find his blog post online where he does a better job of explaining this than me.
@KenHolm
@KenHolm Жыл бұрын
Excellent advice. Comments++, Standards++ Digging this format. 👍 from me.
@donbraga4863
@donbraga4863 Жыл бұрын
I like to start coding (prototyping) and then refactoring it.
@machineability
@machineability Жыл бұрын
Nice overview, as always, you get to right to the points. Now, maybe it would be nice to see some specific examples in follow-on videos
@anonym_dan
@anonym_dan Жыл бұрын
On the subject of not using some principles in favor of code quality, I have a topic suggestion for another video: different architectures and the way they affect our project quality, maintenance, scalability. This video is great though, thanks very much for advice!
@darkly77
@darkly77 10 ай бұрын
Best advice I ever got for comments is: Don't describe WHAT you're doing, describe WHY
@iamthebiker
@iamthebiker Жыл бұрын
I don't understand what you mean by avoiding OOP? What do you do instead? Function programming? Or is there another way? I'm a somewhat new C# developer and I guess I don't understand how to not do OOP. I would be interested in a video on this, or more information. Thank you
@HorridModz
@HorridModz Жыл бұрын
If you're really new to programming and you only know c#, the best way to learn other methods of programming is to learn other languages like python or c++.
@iamthebiker
@iamthebiker Жыл бұрын
I guess I'm wondering how you structure your code if you aren't using objects. Just a bunch of files with functions? Are you still using classes? If you have a class (let's say an animal class) how do you re-use the code without OOP?
@anonymousOrangutan
@anonymousOrangutan Жыл бұрын
he means that if you were to do a UML diagram of your software, it wouldnt be a giant complex network of subclasses and interfaces, but instead a collection of independent classes
@iamthebiker
@iamthebiker Жыл бұрын
Ok, that makes sense I think. So mostly he is saying to try to eliminate inheritance? That would make sense to me...but is that all? Are object variables / instance variables ok?
@EngineerMan
@EngineerMan Жыл бұрын
What Maxime said. Avoiding OOP doesn't necessarily mean avoiding classes, it just means avoiding the overly complex web of madness that comes with tightly coupling classes together.
@thingsiplay
@thingsiplay Жыл бұрын
The language and environment of the language can help in producing higher quality code too (but not guarantee it). Rust is such a good example in my opinion. The language itself and the tooling is what I refer to as gold standard.
@fabioteixeira868
@fabioteixeira868 Жыл бұрын
On the topic of good code comments, I recently stumbled upon Knuth's Literate Programing idea, and got really tempted to try it out. I can see it playing really well with automation scripts or tests (very linear, procedural), but I'm not sure if it would fit in a mutli-source and header file library, for example... The modern approach seams to be writing code inside code blocks in a Markdown file, with documentation surrounding it (plain Markdown text) and it is all executed by an external tool or script (like "lit").
@benhetland576
@benhetland576 Жыл бұрын
IIRC Knuth used terms and tools with names like "web" for this :-) and it predates the world-wide one by many many years :-)
@lebdesmath2510
@lebdesmath2510 Жыл бұрын
thanks for this knowledge
@Edgarspiffy
@Edgarspiffy Жыл бұрын
What font do you use on your videos?
@ZwartCode
@ZwartCode Жыл бұрын
Kind of against not using object oriented by default. I think it fixes the untestable issues by using interfaces before implementing.
@thingsiplay
@thingsiplay Жыл бұрын
This can be done without OOP too. Rust is a good example.
@phanipavan6809
@phanipavan6809 Жыл бұрын
To increase the quality of your code, copy high quality code. The overall quality will increase. /s
@thingsiplay
@thingsiplay Жыл бұрын
Also don't forget to paste the code you just copied. This will definitely make the code better you just copied before. /s
@benhetland576
@benhetland576 Жыл бұрын
@@thingsiplay I kinda have come to the nearly opposite philosophy over the years. Assuming any and all source code generally contains some x percentage of bugs, for some value of x significantly higher than 0, then if I delete some sections of code I also remove some bugs. The more code I delete, the more bugs I eliminate. This rule of thumb is particularly suitable for code bases that have been maintained for a couple of years or more.
@thingsiplay
@thingsiplay Жыл бұрын
@@benhetland576 I was just playing with a joke, because everyone is talking about copying code. But they forget to paste it, otherwise it just remains in the clipboard. But for your case, I can see why less code can have less bugs. On the other hand, less code can handle less cases and therefore has more bugs. Eliminating code has higher chance of eliminating bugs than features probably, depending on the language and complexity of the program.
@rosshoyt2030
@rosshoyt2030 Жыл бұрын
Most of these suggestions apply perfectly to the code the previous developer wrote at my job.. 😫 good video tho
@AntonioDellaRovere
@AntonioDellaRovere Жыл бұрын
Totally agree. Furthermore, I would at least lint the code and try to reduce lint warnings with every commit.
@Frumpbeard
@Frumpbeard Жыл бұрын
Some open source projects actually automatically do a lint check and will display on a pull request if it failed.
@HardcoreTech-wg9bm
@HardcoreTech-wg9bm Жыл бұрын
hey bro, I really want you to know I am impressed with your "UDP Peer-To-Peer Messaging With Python" video, by the way I really wannna know how can I apply peer to peer file transferring accourding to the same theory, the "UDP hole punching theory", appreciate in advance 😀
@rhidlor8577
@rhidlor8577 Жыл бұрын
yes coach
@Simon-lk6ky
@Simon-lk6ky Жыл бұрын
think of your pipelines as pipes and recognize when you should fit two pipes together for upgradability instead of making one giant long pipe
@acidhauss7018
@acidhauss7018 Жыл бұрын
I know this isn't really related to code (and more to deployment, and helping PM's/QA/testers) but screenshots are really helpful. Get a good screenshot tool like Lightshot and use them a lot to communicate over Teams/Slack etc - a pictures worth 1000 words.
@Frumpbeard
@Frumpbeard Жыл бұрын
Compared to the likes of Python and Javascript, most programming languages are self-documenting. I use and abuse type hints whenever possible in Python, because that's how you can simply use a '.' to show a list of all the object's functions and their parameters.
@ZacKoch
@ZacKoch Жыл бұрын
prod comment in real life # we never really use the aes_dei - it's just added to appease . we don't store it in our systems
@sourandbitter3062
@sourandbitter3062 Жыл бұрын
TIL you can use bitwise operators on JavaScript arrays... why
@EngineerMan
@EngineerMan Жыл бұрын
To be clever lol.
@zeocamo
@zeocamo Жыл бұрын
in the past 25+ years i been coding, i have done it all, OOP, FP, no comments and lots of comments. i found that you need to think about the lifetime of the software you are making, OOP is really good for the projects that you need a lot of diagrams for and you DONT need to change after it is made, so about 0.0001% of all software. most software you need to change over time and need to be bug "free", the best pattern i found for this is keep all the dirty code like API/DB/etc. in a ring/layer that is tested manually as it is the hardest to test. then put all your business logic in a ring/layer that is tested, write 3-5 tests for a function with this logic, the test help with documenting and defining a interface, this is good as you really easy jump the fence. and you can just keep the tests running as they dont touch the DB, and can be run in less then 3 secs. the problem with unit testing that you need to mock stuff up, and you end up with 1000 lines of code just to test 1 property, and hours of work, not good.
@space_fun
@space_fun Жыл бұрын
Капитан очевидность
@fredsmith1970
@fredsmith1970 Жыл бұрын
Code should be written as though someone else will maintain it - even if that someone else is your future self. They will thank you for it.
@RodasAPCTV
@RodasAPCTV Жыл бұрын
Think before I type? I don't think so.
@SumanSedhai
@SumanSedhai Жыл бұрын
I wish the malware code writer see this video and make everything simple. 😂
@SC17CLUSTER
@SC17CLUSTER Жыл бұрын
Ok
@yummybunny7351
@yummybunny7351 Жыл бұрын
Maybe insted of comment, wrap chunks of code in functions\methods and give them good names?
@RoyRope
@RoyRope Жыл бұрын
Instead of focussing on readable comments you'd better write readable code first I think.
@aidanbyrne8267
@aidanbyrne8267 Жыл бұрын
I like the tips, but self documenting code is a far more important skill to learn, as code will change, the comments will not, you come back a year later and find that a function does something completely different, but nobody removed/changed the comment "just in case". And there's the old saying, "If a developer can't express themselves cleanly in code, they're unlikely to do so in comments" not saying the don't have their place, but they should be a last resort
@thingsiplay
@thingsiplay Жыл бұрын
I agree. Self documenting code is important, as much important as the comments and high level documentation. It just is not a replacement for the other stuff. If you have complex and unreadable code that requires comments to explain it, then it might be a good idea to simplify the code and make it more idiomatic. Often idiomatic code is easy to understand.
@tmhchacham
@tmhchacham Жыл бұрын
I disagree with coding standards. A project is a piece of art, and represents an approach to solving a problem. The code should be consistent unto itself, but following a standard makes no sense. Condensing code makes the overall code easier to read, because you get the high-level picture, faster, and can then zone in on the specific area with confidence. Code that uses many lines take a long time to get straight, and often hides details and gotchas. Code can be self-commenting if you use descriptive variable and routine names. Names can be very long, why not use them? My rule is, if i need a comment to explain it, i haven't named it correctly. Comments should be used to explain the _why_ not the _what_ , unless and algorithm or special case requires it.
@Alex-gj2uz
@Alex-gj2uz Жыл бұрын
To be honest I generally like your content but this video was kind of shallow contentwise. Most of the stuff you could read in schoolbooks. You barly toucht the surface. Im sorry
@TheKodeToad
@TheKodeToad Жыл бұрын
Ok
Difficult Programming Concepts Explained
11:13
Engineer Man
Рет қаралды 68 М.
What Linux Is and Isn't (Linux Zero to Hero 2022)
6:27
Engineer Man
Рет қаралды 16 М.
格斗裁判暴力执法!#fighting #shorts
00:15
武林之巅
Рет қаралды 82 МЛН
Joven bailarín noquea a ladrón de un golpe #nmas #shorts
00:17
Do you know how Redis Work? (5 min)
4:58
Backend Simplified
Рет қаралды 814
Engineer Breaks Down Hollywood Programming Scenes
11:02
Engineer Man
Рет қаралды 22 М.
How To Be a Better HTML/CSS Developer
8:05
Engineer Man
Рет қаралды 17 М.
I Switched to VS Code and It's Kinda OK
6:28
Engineer Man
Рет қаралды 22 М.
I Asked ChatGPT To Build Me a Website
12:24
Engineer Man
Рет қаралды 27 М.
Definitely Don't Use GitHub Copilot Now
5:59
Engineer Man
Рет қаралды 31 М.
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,3 МЛН
8 Design Patterns EVERY Developer Should Know
9:47
NeetCode
Рет қаралды 992 М.
Apple watch hidden camera
0:34
_vector_
Рет қаралды 50 МЛН
⌨️ Сколько всего у меня клавиатур? #обзор
0:41
Гранатка — про VR и девайсы
Рет қаралды 651 М.