5 Nooby Coding Mistakes You NEED To Avoid

  Рет қаралды 9,921

Tech With Tim

Tech With Tim

Күн бұрын

Пікірлер: 62
@TechWithTim
@TechWithTim Күн бұрын
👉 To try everything Brilliant has to offer for free for a full 30 days, visit brilliant.org/TechWithTim . You'll also get a 20% discount on a premium subscription.
@misbahsaleem3332
@misbahsaleem3332 Күн бұрын
Love from Pakistan ❤❤❤
@RileyMeta
@RileyMeta Күн бұрын
6:40 An alternative that you can leverage: match and case. It generates a look up table during run-time so it matches instead of checks.
@vcv6560
@vcv6560 Күн бұрын
As in a conversation I had with a manager of some years ago said: Supervisor. "I'm not going to tell you how to do it..." Managed. "Yeah, but you'll be the first to let me know if I'm doing it wrong." We worked well together....
@dakoderii4221
@dakoderii4221 Күн бұрын
"Do 1,000 things right and no one will remember. Do one thing wrong and no one will let you forget." - Drill Sergeant Phillips
@balloney2175
@balloney2175 Күн бұрын
Thanks, Tim for the advice... as always... you are my hero!
@andreadelcortona6230
@andreadelcortona6230 Күн бұрын
Great straightforward content I always learn something Thanks Tim!
@pycat141
@pycat141 13 сағат бұрын
It's nice to see these coding advices/tutorials again. Got a bit more used to that content format rather than to the "How to become ____" videos through all the years I've been learning from your channel.
@johnbennett1465
@johnbennett1465 Күн бұрын
While the first example fix is fine for a general case, it has a different problem. It uses an if statement to just return true/false. In this simple case, just return the boolean expression.
@scragar
@scragar Күн бұрын
I am also a fan of writing that sort of thing in reverse with early exits too. Writing if (! user.is_authenticated) return false; if (user.account_status != "active") return false; Just helps you keep less things in mind, eventually you wind up with a situation where multiple conditions combine and actually this page needs you to either allow anonymous submission or be logged in with permission or be an admin and if you do need to be logged in your account needs all the active stuff. Writing if (config.allow_anonymous_posting) return true; if (user.account_status != "active") return false; if (user.is_admin) return true; Etc just becomes a much nicer way to handle it than a single big boolean expression.
@johnanderson290
@johnanderson290 Күн бұрын
I would argue that the following code is a much better solution for Mistake #2. It showcases the use of the *range* function, the *filter* function, and *lambda* functions. def process_numbers(numbers): # store range once instead of repeatedly # recreating it while iterating over list proper_range = range(2, 100, 2); return filter(lambda n: n in proper_range, numbers); However, if the range is large, for example between 2 and 1000000, then we would want to avoid storing such a large list in memory, and instead manually apply the evenness and range checks, as shown in the code below. def process_numbers(numbers): return filter(lambda n: n % 2 == 0 && 0 < n < 1000000, numbers); Additionally, we could use *inner functions* to make the code perhaps even more readable, as shown below. def process_numbers(numbers): def is_even(num): return num % 2 == 0; def is_within_range(num): return 0 < num < 1000000; return filter(lambda n: is_even(n) && is_within_range(n), numbers);
@JosphatKangethe-yp1mh
@JosphatKangethe-yp1mh Күн бұрын
Hey Tim can you do a video discussing Devops roadmap
@StuartLoria
@StuartLoria Күн бұрын
Best practices is what I need, how the syntax works is what the docs are for, this video here is added value to go pro.
@Sadeem-o9y
@Sadeem-o9y 2 сағат бұрын
Hi Tim, I just found this interesting new topic of research on Machine Learning talking about how the new way of doing it in the future might likely be with liquid neural networks rather than static traditional ones. There were things like energy efficiency and learning new information during run-time (like how the human brain's neuroplasticity enables it to adjust to changes on the fly) that are supposed to make it mimic the human brain way more than traditional networks. So I thought you might be interested in this topic and potentially make a video about it if you think the topic's worth exploring! Also, love your videos :)
@alimihakeem841
@alimihakeem841 Күн бұрын
Tim, I love your approach in solving problem. Separating different components of program into functions. I gained alot with this your approach in one of your content. "Learn Python with one Project" ❤
@HtunWinSoe-h1w
@HtunWinSoe-h1w Күн бұрын
In 4-fixed file, should we write necessary functions for process in a separate file, and then import into the main file?Is it a conventional way to write code like this?I am beginner to this ?Really appreciate and love your work bro ❤
@Wutheheooooo
@Wutheheooooo Күн бұрын
Yes, write modular codes is good, only if you think it is, it'syour choice to decide. And yes, it is conventional to write like that, it is literally how it work in C.
@willyhorizont8672
@willyhorizont8672 21 сағат бұрын
YES, it looks clean. But naming variables and functions is hard :D
@niyondacrypticszealot1587
@niyondacrypticszealot1587 Күн бұрын
Thank you for this.
@johnbennett1465
@johnbennett1465 Күн бұрын
Good solution for the second example. But if you don't care about performance, there can be short clear alternatives. In this case using "if number in range(2, 100, 2):" is much clearer. Just make sure you never do this in code that might be called a lot.
@johnanderson290
@johnanderson290 Күн бұрын
I completely agree with the much shorter and clearer solution of using “in range(2, 100, 2)”. However, when needing to repeatedly make this check (in a loop), as in the video, you can easily avoid the performance hit by storing the return value of the “range” function call in a variable (for example named “result”), and then repeatedly executing “in result” (instead of “in range(2, 100, 2)”). Furthermore, the “filter” function can be used to iterate over the list of numbers and apply the range check, using a lambda function, to each number in the list. Applying the suggestions above result in much leaner and clearer code, as shown directly below. This solution is easier to read and understand, and also less error prone when making changes. def process_numbers(numbers): proper_range = range(2, 100, 2); return filter(lambda n: n in proper_range, numbers); However, if the range is much larger, say between 2 and 1,000,000, then of course it wouldn’t be appropriate to store such a large list in memory. Rather, the better solution would be to manually check for evenness, and for the range, as shown below. def process_numbers(numbers): return filter(lambda n: n % 2 == 0 && 0 < n < 1000000, numbers); You could even use inner functions to make the code perhaps more readable, as shown below. def process_numbers(numbers): def is_even(num): return num % 2 == 0; def is_within_range(num): return 0 < num < 1000000; return filter(lambda n: is_even(n) && is_within_range(n), numbers);
@johnbennett1465
@johnbennett1465 4 сағат бұрын
@@johnanderson290 some interesting points. But here are some things to consider. The range function returns an iter. If you want to pre-compute the reference, you need to convert it to a list. Comparing against all the values is expensive. That is why I pointed out that it was slow. My code will correctly return false on a non-numeric value. Several of your versions will blow up.
@kilianklaiber6367
@kilianklaiber6367 Күн бұрын
You could have also defined a function, which returns true, if the numbers is valid and else whatever you want it to say.
@kilianklaiber6367
@kilianklaiber6367 Күн бұрын
Nice job, I like that you readability over conciseness. Creating a dictionary is a great idea.
@nasccped
@nasccped Күн бұрын
In the first mistake, you can also use all() Python function. It tests if all conditions (inside an iterable) are true. Else, return false
@dfields9511
@dfields9511 Күн бұрын
I have seen some really bad code in my professional career Even comments that say We now call our recursive private constructor Neeto “gag” It was creating a n-ary tree from a list
@EyosiyasBelete-ge7fv
@EyosiyasBelete-ge7fv Күн бұрын
Who else loves coding
@TechWithTim
@TechWithTim Күн бұрын
Moi!
@RaadClub
@RaadClub Күн бұрын
Love coding but hate the fact that can land even an internship in my god damn country.
@CoaLearn
@CoaLearn Күн бұрын
I'm love from coding
@edd7297
@edd7297 21 сағат бұрын
Scripting…
@thelostyaksha
@thelostyaksha 17 сағат бұрын
No one. We're just torturing ourselves by watching these boring, long videos
@kapibara2440
@kapibara2440 Күн бұрын
Thank you for your tips Tim! They are all so useful in daily life 💪
@GeekRedux
@GeekRedux Күн бұрын
So what does continue actually continue? Because its use here is the opposite of my intuition. Like in this example, if it's true that it's not a number, the use of continue seems to me to mean that that was the desired result so the program should continue on to the next test. If it's out of range or is odd the program should continue on to appending the number. Does continue mean leave the function without appending, because that is the exact opposite of what I would expect that command to do.
@rootytuners
@rootytuners Күн бұрын
Continue means “continue with the looping process.” It ends the current iteration and proceeds to the next iteration of the loop.
@GeekRedux
@GeekRedux Күн бұрын
@@rootytuners Got it, thanks. Still not the best name lol
@graynanuuq
@graynanuuq Күн бұрын
Are functions within functions considered bad? In trying to avoid error 5, I frequently create a number of input validating/sanitizing steps which can border or fall into error 4, a large function that is difficult to quickly grok. Is creating subfunctions within a function to do the input sanity checking considered maintainable or should all the sanity checking be peer level functions? Some of the sanity checking functions are nearly universal and for those it makes sense to be peer level, but a good chunk end up relating only to one specific function.
@TechWithTim
@TechWithTim Күн бұрын
Nested functions are “okay” but you want to avoid doing it too often as it’s just harder to read the more nesting you have going on
@graynanuuq
@graynanuuq Күн бұрын
@@TechWithTim Thanks. I try to restrict it to one layer, so with code folding I can tell what the sanity checking steps are by the names before getting to the meat of the function itself.
@johnbennett1465
@johnbennett1465 Күн бұрын
For example five, passing a non-number should raise an error.
@StuartLoria
@StuartLoria Күн бұрын
The first point is what my team does not understand, they like complexity hard to read code with lots of implementation details.
@bn4910
@bn4910 Күн бұрын
new to coding but am eager to become a talented data scientist!! n = ALL
@AbdirahmanIsmail-h4w
@AbdirahmanIsmail-h4w 15 сағат бұрын
mr tim make me uderstand on how to apply coursesCareers and the payments plan after that is it guarantee that I will get the job immediately after completing the course and are u the one who will give me the job I need your response plz
@TechWithTim
@TechWithTim 15 сағат бұрын
No, no legitimate course can guarantee you a job. Of course we will do out best to prepare you and help you along the way but we cannot promise you will land a job.
@musonobari2560
@musonobari2560 Күн бұрын
The mega function is just crazy. Makes me feel like my IQ is 70 😝😜😜
@gregf9160
@gregf9160 Күн бұрын
The 'continue' option is _really great_ in simplifying and making code even more readable 👍
@anandhraj1952
@anandhraj1952 22 сағат бұрын
🤚❤❤❤
@misbahsaleem3332
@misbahsaleem3332 Күн бұрын
1st comment ❤❤❤
@misbahsaleem3332
@misbahsaleem3332 Күн бұрын
And from Pakistan ❤❤❤😊
@WHAT.IF_UZ
@WHAT.IF_UZ Күн бұрын
is there anything for the first viewers and commenters and likers
@sutofana
@sutofana 17 сағат бұрын
thank you tim 🫶🫶🫶🫶🫶
@WHAT.IF_UZ
@WHAT.IF_UZ Күн бұрын
is there anything for the first viewers and commenters and likers
@TechWithTim
@TechWithTim Күн бұрын
a heart
@WHAT.IF_UZ
@WHAT.IF_UZ Күн бұрын
@@TechWithTim what does that mean bruh
@TechWithTim
@TechWithTim Күн бұрын
@@WHAT.IF_UZ what do u want lol
@WHAT.IF_UZ
@WHAT.IF_UZ Күн бұрын
@@TechWithTim a free course for frontend and backend development?
@whoami-ty1kp
@whoami-ty1kp Күн бұрын
​@@WHAT.IF_UZyeah like you've survived world war by being the first viewer lmao.
4 Software Developer Roadmaps For 2024+
29:41
Tech With Tim
Рет қаралды 32 М.
Please Master These 10 Python Functions…
22:17
Tech With Tim
Рет қаралды 177 М.
This mother's baby is too unreliable.
00:13
FUNNY XIAOTING 666
Рет қаралды 34 МЛН
8 Data Structures Every Programmer Should Know
17:09
ForrestKnight
Рет қаралды 87 М.
Python 101: Learn the 5 Must-Know Concepts
20:00
Tech With Tim
Рет қаралды 1,2 МЛН
How To Practice Programming So You Actually Get Good
15:46
Tech With Tim
Рет қаралды 165 М.
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 718 М.
Running "Hello World!" in 10 FORBIDDEN Programming Languages
18:07
PLEASE Learn These 10 Advanced Python Features
42:28
Tech With Tim
Рет қаралды 37 М.
Structs in JS might change everything
22:38
Theo - t3․gg
Рет қаралды 41 М.
Compilers, How They Work, And Writing Them From Scratch
23:53
Adam McDaniel (kiwi)
Рет қаралды 194 М.
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 242 М.