How Software Engineers Can Write Better Code

  Рет қаралды 30,746

ForrestKnight

ForrestKnight

Күн бұрын

Try out Shortform completely free and get a 20% discount if you upgrade shortform.com/forrest
There's a better way to write code, and that's by having your code meet 3 high-level goals. As a programmer, every time you write code you want to be asking yourself if this code meets those 3 goals. And in doing so, it’ll have you build a coder’s mindset so every time you pick up a coding task, you’re thinking like a programmer without even thinking about it.
🖥️ Dev Notes Newsletter: www.devnotesdaily.com/
0:00 Write Better Code
0:46 Write Code that Solves a Specific Problem
4:52 Code Example of How to Do It
5:16 Code Example of How NOT to Do It
6:06 Why It's Wrong
7:29 Shortform Sponsor
9:29 Write Code that's Easy to Read and Maintain
10:45 Code Example of Poorly Written Code
11:40 Code Example of Properly Written Code
14:35 Write Code that's Scalable and Extendable
18:03 The Coder's Mindset
20:08 I appreciate you!
------------------------
📓 Studious, Notion Template for Students: notionstudent.com
🐱‍🚀 GitHub: github.com/forrestknight
🐦 Twitter: / forrestpknight
💼 LinkedIn: / forrestpknight
📸 Instagram: / forrestpknight
📓 Learning Resources:
My Favorite Machine Learning Course: imp.i384100.net/YgYEBJ
Open Source Computer Science Degree: bit.ly/open-source-forrest
Python Open Source Computer Science Degree: bit.ly/python-open-source
Udacity to Learn Any Coding Skill: bit.ly/udacity-forrest
👨‍💻 My Coding Gear:
My NAS Server: amzn.to/3brqO7b
My Hard Drives: amzn.to/3aKetMi
My Main Monitor: amzn.to/3siQfPa
My Second Monitor: amzn.to/3keHT84
My Standing Desk: amzn.to/3boAcbC
My PC Build: bit.ly/my-coding-gear
My AI GPU: amzn.to/3uvmUmz

Пікірлер: 74
@fknight
@fknight 5 ай бұрын
I hope this video helps you out! I've included timestamps to help you navigate around the video. Also, Shortform sponsored a portion of today's video. They are offering a free trial and a 20% discount if you decide to upgrade. Try them out!👉 shortform.com/forrest PS - There are code examples throughout the video that show how to implement what I'm explaining. Hope they help!
@LogicEu
@LogicEu 5 ай бұрын
Choose simplicity over complexity every time you can
@ifstatementifstatement2704
@ifstatementifstatement2704 5 ай бұрын
Then you can't use OOP. Because layers of abstractions and classes all over the damn place calling each other, is the opposite of simplicity.
@kyriosity-at-github
@kyriosity-at-github 4 ай бұрын
Thank you for a great teaching, my guru !
@TheIllerX
@TheIllerX 5 ай бұрын
Finally some solid programming advice, explained by someone who really gets it and knows how to explain things. Not just someone repeating stuff they read.
@warspaniel
@warspaniel 3 ай бұрын
I had to laugh when you mentioned testing bubble sort with 3 things and then saying "Oh, that's great! I've solved my problem!" I had a similar problem with another developer on an actual project. Because he didn't want to bother to learn the library for a file-based database system, he decided to implement nested linear searches for a daily transaction extract. The structure of the data was a members table (unique members), an accounts table (a member could have 0 or more accounts), and then a transactions table (an account could have zero more transactions). The first data set we tested with had 21 members, each with one account and one transaction. The nested linear search worked fine for that. But, when it went to production, we were going to be dealing with 3000 members, 4500 accounts, and an ever-growing list of transactions. In less than 2 weeks, the process took more than 24 hours to run.
@theUnemployedProgrammer
@theUnemployedProgrammer 5 ай бұрын
Another great video! Thanks Forrest. You helped me get through college with some of your advice. Keep up the great work!
@koti1217
@koti1217 4 ай бұрын
Very good content, looking forward to more of this type!
@taserianAlephNull
@taserianAlephNull 4 ай бұрын
With the combo function you mentioned, I wish you'd gone into more detail about how one requirement (vowel counting) is asking a question about the state of its inputs, while the other (letter substitution) is manipulating that state. It leaves you with multiple questions like "What happens if the letter substitution involves a vowel?" and "How do I get the vowel count *after* the letter substitution?"
@BruceSailes
@BruceSailes 5 ай бұрын
Awesome video! Keep them coming
@KBoxx
@KBoxx 5 ай бұрын
Banger of a video from 30 seconds in.. instant like. I'm gaining a lot of ammo here for my upcoming meeting I have with the other devs in my company (that I've been at for 2 months) to split out code more.. we have controllers with thousands of lines of code in them at the moment that do about 5000 things, which is making my job of building out an API to integrate with other companies a nightmare to try to parse out logic here and there from existing functionalities. At least I'm getting to build out service classes exactly like I want to 🙂
@theUnemployedProgrammer
@theUnemployedProgrammer 5 ай бұрын
That sounds like a nightmare
@KBoxx
@KBoxx 5 ай бұрын
@@theUnemployedProgrammer it is definitely something. Let me not get started also on the “CMS” that is all database driven manually with scripts with one giant table where you can do anything and everything you want as the code drives the logic of the values retrieved…anything from what a button label should say to driving business logic for entities that should really be their own database table.. and also how all of that code exists in controller actions 😅 Pray for me
@fknight
@fknight 5 ай бұрын
"At least I'm getting to build out service classes exactly like I want to 🙂" Always finding the silver lining, aren't ya KBoxx lol. Yea that sounds like a nightmare. I'll be praying for you, no worries 😅
@beilog7489
@beilog7489 3 ай бұрын
you sound like one of my colleagues thats working on a similar project like yours haha
@zahkarii7933
@zahkarii7933 5 ай бұрын
Now just starting my coding journey, this was very helpful to watch so I can start to implement this from the start. As well just pausing at 17:55 gave me a good idea of how real lines of code look like for a product. Very organized and helped me just understand it a little.
@ifstatementifstatement2704
@ifstatementifstatement2704 5 ай бұрын
I've been programming for 26 years and there are many ways to organize your code, some more efficient than others. But at the end of the day, it all depends on if you are going to work in the software industry and the standard that the people in that industry prefer. Yes prefer. Because it is a preference although they will swear it's not. And the preference is readability in how the code is written and organised. If you want to save yourself a headache, use chatGPT to learn the industry standard way of programming. It's usally about using the object-oriented programming (OOP) paradigm and following principles (like SOLID) and patterns (singleton, factory, etc.) when programming. You are expected to never implement your own solutions but use frameworks that have a set way of implementing solutions. For example, whenever you find yourself writing a loop, than there is most certainly a library in the programming language you are using that has commands you can use to avoid having to use a loop. The industry would have you believe that it's better to do that when in reality the implementation of those commands use loops too, except they do additional processing that your custom loop would not have done, and therefore yours would have been more performant. But the industry prefers readability over performance and therefore would have everyone use a command to avoid using a loop. They also say that it minimizes the opportunity for errors in loops since the data will be processed in the same way for everyone. They also have a disdain for if statements and would rather create five layers of abstract classes to replace an if statement because it's supposedly more readable LOL than an if statement and more extendable (I'll give them that one; but how shit will the performance be when one if statement is replaced by multiple classes). So basically the industry would rather use the processing power of computers to make their life easier (although that's debatable) when programming software, rather than making it more performant for the client. If you're going to work in the industry, my advice is roll with their bullshit and don't even bother trying to discusss common sense with indoctrinated sheep.
@user-hp2tj3nw5z
@user-hp2tj3nw5z 5 ай бұрын
It was a great inspiration for the upcoming new year as a freshmen in college it really boosts me up - from India
@AbhayNayak
@AbhayNayak 5 ай бұрын
Great content really enjoyed it!! can you make a video on how to decide design patterns for python or if you've a set of rules while structuring all your classes and your code? I end up making so many classes and calling them everywhere, want to understand how you handle it, Thanks!
@sugaslate14
@sugaslate14 5 ай бұрын
This was great thank you! New sub!
@fknight
@fknight 5 ай бұрын
Awesome! Thank you!
@jensBendig
@jensBendig 4 ай бұрын
One key to simplicity, transparence and reliability is refactoring. If you see a complicated code, that operates already, refactor it by transforming to the use of well understood patterns.
@dflfd
@dflfd 2 ай бұрын
agreed. and refactoring is waay easier and results in less hair pulling with a test suite, so write one! :)
@jensBendig
@jensBendig 2 ай бұрын
I agree. Although I must say: In my latest projects, I have created a system of very clear bug detecting Error Reports. Those act like a permanent Testsuite and stay within the system, even after deployment. When I can do this, I often do not build a testsuite anymore.
@mrxkrip9523
@mrxkrip9523 4 ай бұрын
Thank you.. You vidio allow me to stay motivated and rethink many things
@henrischomacker6097
@henrischomacker6097 5 ай бұрын
Very good video! But I must say I mentioned a habit, especially with javascript and python devs, that they tend to use objects or modules wherever they can; because it's so easy to just call an objects function to return one value but writing a function for that. That may be convenient and even good for the project, but in a lot of cases, it takes double the time of compute! Let's take the first example of replacing all occurrences of one letter by another. - I really was too lazy now to test it but am pretty sure that the simple loop would be the fastest solution. - Please correct me if I'm wrong! - This is just an example. I know that functional programming seems like a habit of oldies, but it is not. - If you may replace an object/object call with a clearly written function without the use of oop and you do it every time it is applicable in your project, you'll gain a lot of speed!
@kell7689
@kell7689 5 ай бұрын
"thinking like a programmer without even thinking about it" -- I feel like I've finally reached this point and it is peaceful. Going to work and doing my job has become calmer and more productive now that I don't need to put much energy toward being conscious of how I code. It's nice.
@joeldegerman9621
@joeldegerman9621 5 ай бұрын
I think code should be easy to reason about, hence I like to use functional concepts in my code. Pure functions is on of the biggest thing, Immutability also. Mutating state can be hard to not do in some languages but then it is really important that functions does one and one thing only (no side-effects). I also like to use monads to compose functions. You can do so much with, wrap try catch logic behind it as an example. The underlying code can be more complex but using it is smooth as butter 😊
@matthewtimokhin9793
@matthewtimokhin9793 5 ай бұрын
Great vid!
@vladdobrinov6843
@vladdobrinov6843 5 ай бұрын
in term of efficiency FOR scalability first approach is best) it can be kind of messy at look, but simple loop faster than maps and regex))) *at least in javascript for simple checks) Like the concepts, really helpful!!!
@martinbakker7615
@martinbakker7615 5 ай бұрын
And #4 use gof design patterns. Use standard names and solutions.
@sendut
@sendut 5 ай бұрын
The moment the resources turns limited, the approach should change dramatically
@supremoluminary
@supremoluminary 3 ай бұрын
Map function adds complexity of your own code and own function rather than relying on built in functionality of regular expression replacement, which does the job more concisely.
@satyamraj2779
@satyamraj2779 5 ай бұрын
Thanks Jesus!!😊 By the way really love your videos.. You are a real one among these so called "KZbin Developers"..
@fknight
@fknight 5 ай бұрын
I appreciate that!
@alexiscoding
@alexiscoding 5 ай бұрын
In almost any project I just use MVVM (or as close as possible) because it’s like a habit at this point which allows me to not overthink about the structure and allows me to be more productive
@ifstatementifstatement2704
@ifstatementifstatement2704 5 ай бұрын
That is a good start for separation of concerns. Depending on the project and its features, you'll have to go beyond that though.
@ifstatementifstatement2704
@ifstatementifstatement2704 5 ай бұрын
No matter how you write code, some asshole on the team will find fault with it. There is only one thing that matters and it's that it works. Because if it doesn't work, then it won't matter how pretty your code looks or how scalable and extendable it is.
@roostermaind6413
@roostermaind6413 4 ай бұрын
7:00 You forgot to mention the fact doing both count and replacement on the string turns messy if you're replacing vowels with consonants or vice versa. Maybe if YOU wrote the code, you'll know in which order the operations are applied and have a good idea of what behaviour to expect... for like 2 days after you write it. But anyone else or even your future self will have no idea what to expect just going by the function's name and will have to go through the trouble of reading the code(and if they have any sense also splitting it into two function).
@alexaneals8194
@alexaneals8194 3 ай бұрын
Except in python. Loops are actually slower. I learned that when I started to use the language. I come from a C background so what I thought would be quicker was actually slower.
@edu_aqui
@edu_aqui 3 ай бұрын
4:54 Maybe I can find a video of yours, explaining lambda functions. I did not learn about it, yet.
@Lillu700
@Lillu700 4 ай бұрын
I think for the first example you got your own metaphroe wrong way around. The specific proplem in this case was convert characters and count vowels. So a specific solution purpose build for that would do them at the same time saving those precious CPU cycles and in more importantly in this case memory reads. Making a generic solution for both problems seems to me more like that multi tool, sure it can do both, but way slower. Yes coupling the tasks makes the code less flexible, but a different problem needs a different solution. Ofc this is just an example, but it seems so specific that making it a function at all seems like a mistake. Just inline at the problem site. Later if the same problem needs to be solved at another call site then pull it out into it's own function. More functions is more complexity to manage and if you actually need to know what the code does, it's much easier to read when the logic is sequential. I do aggree that one should make strong tools for specific purposes, but I suppose I dissagree about what in practise means.
@danialothman
@danialothman 5 ай бұрын
ngl, I was waiting for him to pull a jack hammer.
@sebastianb9460
@sebastianb9460 3 ай бұрын
What is the sense of creating class with one method...? It is GUI, yes? You cannot create it dynamically? It is example from Builder C++ - dynamically - ButtonArray[x] = new TButton(this);
@sitraash
@sitraash 3 ай бұрын
if the code is easy to understand and read, it ALREADY represents a maintain. “Scalable and extend” this depends DIRECTLY on 1 rule, on the problem we are solving. The rules are half harmful for a good coding. If a person constantly thinks about how to write code so that it can be scalable, then he is a bad programmer. Only a programmer who do programs for long-term support, such as big websites or banking apps, can think this way. However, there are a TON OF OTHER THINGS, like GAMES, that don't need to be type as scalable. So good rules are 1. Solve the problem. 2. Clear and easy to read. Thats all. Single responsibility actually REDUCES readability, you need to look furthe and further into the functions to understand what is responsible for what. You can AND SHOULD write functions that do a LOT of things in one, this makes them more readable.
@Trollleben
@Trollleben 3 ай бұрын
When I was an assistant superintendent during my construction days I don't know how many times I've had to tell people during orientation not to use a drill as a hammer, I mean it may work but eventually it's gonna blow up on you lmfao!
@AkPK369
@AkPK369 4 ай бұрын
Without hardware software works ?
@murtadha96
@murtadha96 5 ай бұрын
Wait a second... Is this The Primeagean with longer hair? Liking the new mustache btw
@abrahampurnomo1783
@abrahampurnomo1783 5 ай бұрын
couldn't agree more with this video, what confused me when working with engineers and usually people coming from STEM is simplicity of communication (which you implicitly point out in readability part). Why being so edgy and make everything hard to spell and hard to understand? On my side project, I simply changed the wordings of the documentation, renamed function, and add comments. The on-boarding process took faster and less new engineers asking trivial things.
@georgebelletty7861
@georgebelletty7861 3 ай бұрын
Comments are one of the most evil things I have found in life. Solid video ;)
@oyewumimarvellous
@oyewumimarvellous 5 ай бұрын
"Forrest Knight has been my mentor throughout my journey in Computer Science and Statistics during my time at university. I appreciate your advice, encouragement, time, and resources. ❤️"
@fknight
@fknight 5 ай бұрын
I do what I can. I'm just happy you've found value in it
@oyewumimarvellous
@oyewumimarvellous 5 ай бұрын
@@fknight "Wow, I can't believe you replied to my comment! This is my first time getting a response from a KZbinr of your caliber. Your content has been incredibly inspiring and informative for my journey in Computer Science and Statistics. Thanks a ton for taking the time to engage with your audience! 🙌"
@ashutosh_tiwari
@ashutosh_tiwari 5 ай бұрын
Hey there Thaughty2 here!
@danielbarnard8069
@danielbarnard8069 3 ай бұрын
Did anyone else get a little distracted waiting for the injury from those tools? 😅
@Wineblood
@Wineblood 5 ай бұрын
If the three things your code should do includes a bunch of "and"s, it's not just three things. So much in this video made me cringe: 1. You picked a map and lambda over "hello world".replace("l", "x"), just use the concise built in functionality. 2. That docstring was nasty, type hints give you most of that info without adding extra lines. I'm also not sure why you'd want to pass in constants instead of creating a default area constant. 3. Why complicate code with classes and inheritance? Going from 2 functions to 3 classes is worse in my opinion.
@fknight
@fknight 5 ай бұрын
You're so focused on the examples that you can't see the forest for the trees. You know why I made the bubble sort joke in the video? Because bubble sort is always taught to help people learn about sorting algorithms and data structures, but never used in a real-world application. And although the examples I used actually _are_ used in real-world applications, I used them explain the principles I laid out. 1. I chose map and lambda to demonstrate a more general approach to string manipulation. But also you're ignoring the fact that my approach can be adapted for more complex scenarios where replace wouldn't suffice, with more control and flexibility, which lends itself to the 3rd point made in the video of scalability and extendibility. 2. I clearly removed the docstring at the end saying it wasn't necessary because the code tells the full story. My mind blocked it out as I was reviewing the code so I didn't notice it until after. But again, I clearly stated we didn't need it lol. 3. The entire point of showing this code was to highlight the principles of scalability and extendibility, and OOP does just that in comparison to plain functions. Again, you're looking at the examples for what they are instead of what they could be. You'd have a lot more refactoring in your future as the project grows. Oh and to reference your first sentence... it _is_ 3 things if you can accomplish multiple things (hence, the "ands") with the same code contributing to a singular objective. This was fun. Got anything else for me? EDIT: I really do appreciate your input by the way. I'm clarifying this because in rereading my comment I came off a little brash. Comments like yours help me learn because they question my choices and require me to check back to see why I did something the way I did it. So again, really, this was fun! Hope you have a wonderful day☺
@camerongreen9328
@camerongreen9328 5 ай бұрын
I have C/C++ Devs defining vars in a macro... like NOOOOO its horrible.
@ipodtouch470
@ipodtouch470 5 ай бұрын
That’s how they taught me too define constants in school 😂
@itzhexen0
@itzhexen0 5 ай бұрын
"Programmers are idiots. They always want power and they always want to be able to say I did this." -L.N.
@nested9301
@nested9301 5 ай бұрын
dry kiss solid
@ipodtouch470
@ipodtouch470 5 ай бұрын
For me it’s dry, kiss, low coupling, and high cohesion
@aggi999
@aggi999 3 ай бұрын
Oh you just took the 3 things that have been hammered into all computer science graduates over and over again over the course of their studies
@vanessaadams3500
@vanessaadams3500 4 ай бұрын
How did you know that all of these books have been sitting on my shelf for literally...YEARS!!!🤣😂 How did you know this? You hacked my bookshelf. I am reporting this...🤣🤣😂...I have the evidence...you pointed right at me in your video...😂🤣😂
@hereallyfast
@hereallyfast 4 ай бұрын
You look like you work for Netflix
@programacion3694
@programacion3694 Ай бұрын
a
@michalskoula
@michalskoula 5 ай бұрын
I can't pay attention to what the man says. All I see is a mustache.
@BillDemos
@BillDemos 3 ай бұрын
Well, better engineers write in Delphi...
@mr_noodler
@mr_noodler Ай бұрын
Leatherman tools are so versatile but each tool on it sucks and is useless, and therefore is completely useless as a whole
@NotMarkKnopfler
@NotMarkKnopfler 4 ай бұрын
Forget scalable and extendable. Seriously. Forget it. Write the code to solve the problem you are working, and requirements. That's it. Do not dream up imaginary scenarios that may crop up in the future. Just write what you *need* and no more. Instead of wasting time trying to make your code expandable, spend that time making your code robust, and adequately documented.
@gishee18
@gishee18 3 ай бұрын
this guy's string replace code :skull: return "".join(replacement if c == to_replace else c for c in string) i have a feeling he doesn't know python and copied chatgpt code with documentation that is never mentioned. would explain why some random website is used instead of local python
@kyriosity-at-github
@kyriosity-at-github 4 ай бұрын
Better of better software engineers write no code, and the best - delete the code.
@BillDemos
@BillDemos 3 ай бұрын
That is what Microsoft would like to have you believe. Don't be a programmer - USER (like in Tron). Embrace the code.
How Much Software Engineers ACTUALLY Make
18:11
ForrestKnight
Рет қаралды 84 М.
Pray For Palestine 😢🇵🇸|
00:23
Ak Ultra
Рет қаралды 33 МЛН
格斗裁判暴力执法!#fighting #shorts
00:15
武林之巅
Рет қаралды 90 МЛН
Would you like a delicious big mooncake? #shorts#Mooncake #China #Chinesefood
00:30
I learned to code from scratch in 1 year. Here's how.
41:55
Thomas Frank
Рет қаралды 328 М.
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,3 МЛН
So, you want to be a programmer?
20:43
ForrestKnight
Рет қаралды 100 М.
What You Need to Know for Your Coding Career
16:31
ForrestKnight
Рет қаралды 379 М.
5 Signs of an Inexperienced Self-Taught Developer (and how to fix)
8:40
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Рет қаралды 959 М.
4 Data Structures You Need to Know
9:42
ForrestKnight
Рет қаралды 262 М.
What People Get Wrong About Deliberate Practice
9:21
Benjamin Keep, PhD, JD
Рет қаралды 325 М.
unlock the lowest levels of coding
7:05
Low Level Learning
Рет қаралды 222 М.
A Simpler Way to See Results
19:17
Logan Smith
Рет қаралды 94 М.
Pray For Palestine 😢🇵🇸|
00:23
Ak Ultra
Рет қаралды 33 МЛН