How To Increase the Quality of Your Code

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

Engineer Man

Engineer Man

Күн бұрын

Пікірлер: 52
@tobias-edwards
@tobias-edwards 2 жыл бұрын
"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 2 жыл бұрын
Completely agree. Some duplication in exchange for huge increases in reality is always a solid trade-off.
@benhetland576
@benhetland576 2 жыл бұрын
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 2 жыл бұрын
​@Valerio Turturici 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.
@darkly77
@darkly77 Жыл бұрын
Best advice I ever got for comments is: Don't describe WHAT you're doing, describe WHY
@KenHolm
@KenHolm 2 жыл бұрын
Excellent advice. Comments++, Standards++ Digging this format. 👍 from me.
@donbraga4863
@donbraga4863 2 жыл бұрын
I like to start coding (prototyping) and then refactoring it.
@iamthebiker
@iamthebiker 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
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 2 жыл бұрын
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.
@machineability
@machineability 2 жыл бұрын
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 2 жыл бұрын
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!
@thingsiplay
@thingsiplay 2 жыл бұрын
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.
@ZwCode
@ZwCode 2 жыл бұрын
Kind of against not using object oriented by default. I think it fixes the untestable issues by using interfaces before implementing.
@thingsiplay
@thingsiplay 2 жыл бұрын
This can be done without OOP too. Rust is a good example.
@Edgarspiffy
@Edgarspiffy 2 жыл бұрын
What font do you use on your videos?
@fabioteixeira868
@fabioteixeira868 2 жыл бұрын
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 2 жыл бұрын
IIRC Knuth used terms and tools with names like "web" for this :-) and it predates the world-wide one by many many years :-)
@Simon-lk6ky
@Simon-lk6ky 2 жыл бұрын
think of your pipelines as pipes and recognize when you should fit two pipes together for upgradability instead of making one giant long pipe
@lebdesmath2510
@lebdesmath2510 2 жыл бұрын
thanks for this knowledge
@phanipavan6809
@phanipavan6809 2 жыл бұрын
To increase the quality of your code, copy high quality code. The overall quality will increase. /s
@thingsiplay
@thingsiplay 2 жыл бұрын
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 2 жыл бұрын
@@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 2 жыл бұрын
@@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.
@AntonioDellaRovere
@AntonioDellaRovere 2 жыл бұрын
Totally agree. Furthermore, I would at least lint the code and try to reduce lint warnings with every commit.
@Frumpbeard
@Frumpbeard 2 жыл бұрын
Some open source projects actually automatically do a lint check and will display on a pull request if it failed.
@rhidlor8577
@rhidlor8577 2 жыл бұрын
yes coach
@acidhauss7018
@acidhauss7018 2 жыл бұрын
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.
@HardcoreTech-wg9bm
@HardcoreTech-wg9bm 2 жыл бұрын
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 😀
@rosshoyt2030
@rosshoyt2030 2 жыл бұрын
Most of these suggestions apply perfectly to the code the previous developer wrote at my job.. 😫 good video tho
@sourandbitter3062
@sourandbitter3062 2 жыл бұрын
TIL you can use bitwise operators on JavaScript arrays... why
@EngineerMan
@EngineerMan 2 жыл бұрын
To be clever lol.
@ZacKoch
@ZacKoch 2 жыл бұрын
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
@Frumpbeard
@Frumpbeard 2 жыл бұрын
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.
@zeocamo
@zeocamo 2 жыл бұрын
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.
@fredsmith1970
@fredsmith1970 2 жыл бұрын
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 2 жыл бұрын
Think before I type? I don't think so.
@SumanSedhai
@SumanSedhai 2 жыл бұрын
I wish the malware code writer see this video and make everything simple. 😂
@space_fun
@space_fun 2 жыл бұрын
Капитан очевидность
@aidanbyrne8267
@aidanbyrne8267 2 жыл бұрын
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 2 жыл бұрын
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.
@RoyRope
@RoyRope 2 жыл бұрын
Instead of focussing on readable comments you'd better write readable code first I think.
@SC17CLUSTER
@SC17CLUSTER 2 жыл бұрын
Ok
@yummybunny7351
@yummybunny7351 2 жыл бұрын
Maybe insted of comment, wrap chunks of code in functions\methods and give them good names?
@Alx-gj2uz
@Alx-gj2uz 2 жыл бұрын
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
@tmhchacham
@tmhchacham 2 жыл бұрын
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.
@TheKodeToad
@TheKodeToad 2 жыл бұрын
Ok
Difficult Programming Concepts Explained
11:13
Engineer Man
Рет қаралды 70 М.
Engineer Breaks Down Hollywood Programming Scenes
11:02
Engineer Man
Рет қаралды 22 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,7 МЛН
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,7 МЛН
13 Advanced (but useful) Git Techniques and Shortcuts
8:07
Fireship
Рет қаралды 942 М.
[0b00] Reversing 101 :: Hacking Closed-Source Firmware
24:40
How to improve code quality in your team - 5 tips to get started!
8:38
Git Good: Solo Development Use Cases
12:24
Engineer Man
Рет қаралды 31 М.
Using My Python Skills To Punish Credit Card Scammers
7:13
Engineer Man
Рет қаралды 4,9 МЛН
Git Good: Team Development
13:03
Engineer Man
Рет қаралды 15 М.
how NASA writes space-proof code
6:03
Low Level
Рет қаралды 2,4 МЛН
Think Fast, Talk Smart: Communication Techniques
58:20
Stanford Graduate School of Business
Рет қаралды 44 МЛН
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН