@@anmaral-sharif1381 It's *already* defined. There's no need to define it with less precision when it's already defined in an include file with double precision. On Linux, there's also M_PIl, in case you're using (and can get) 128-bit floats.
That's what mediocre programmers do all the time - over engineering staff while fucking up simple things. I think the author left it for a reason there =)
Initially we had to comment everything, too. But commenting variables was only when it wasn't immediately obvious what they were gonna do. Also getters/setters would at most get 1 comment for the whole section like //getters and setters .. and then you would just put all the getters and setters grouped up below that. And we used real comments that described how a function was used. E.g. "takes 2 int parameters and returns a two-tuple of integers as a result". And those comments do have value if you're writing a library that others are gonna use. Because if the function names are obvious enough they don't need to read code but they can just look for the correct function in the documentation and know what parameter it uses and what the return value will be.
4 года назад+13
I'm from Slovenia, and when I was studying at university ( I finished last year ) I don't remember ever "needing" to comment your code. You just had to know what it does, if you used comments here and there to help you that was fine.
Same bro, This is exactly how I how I was taught to code at my university! Except we only had to comment explaining what our functions parameters were and what it returns.
@@AyushGupta-wn6zd I'll assume it's a honest question. Getters and setters are methods that allows you to respectively retrieve (get) or modify (set) the value of a private variable. ...perhaps that definition doesn't help you much either. So here's the longest version: In a lot of languages, there's something called "classes", basically, it's a blueprint you write for more complex objects (you can think of a class as an empty form with various kind of fields, and each object being a filled form; there are typically multiple objects of the same class). Classes also typically define functions that will operate on the data they contain (for instance, a "character sheet" class might define a function which, when executed, will roll attack damage depending on the strength and weapons filled in the character sheet; note the function is always the same for all objects of the same class, but the data it operates on changes for each object). Such functions are called "methods". Now, sometimes, you want to ensure that the object's data is consistent. For instance, you could have fields "Job" and "Deity" in your dnd character sheet, but it wouldn't make sense to write out "Job: Priest" and "Deity: None" because priests must always belong to some kind of church. So, most languages that define classes also allows the class' author (the programmer) to declare some fields "private". Declaring a field private forbids its use by anything outside the class, so basically, only the class' methods can use it. That way, if you declared the Job and Deity field private, you'd be forced to use one of the class' methods to update their value, and the class' author can make sure that the methods never allows "Job" to be set to "Priest" when "Deity" is set to "None". This is a rather naive example, but in practice, it's often important to hide implementation details that shouldn't matter to the class' user and needn't be tampered with (that's called "encapsulation"). It became common place to always declare all your variables private. However, sometimes, you still need to be able to read the value or change the value of one such variable, in which case, instead of not declaring that variable private, you'll write methods to do that for you (this can seem weird to encapsulate only to break encapsulation by defining accessors, and sometimes it is, but the key is that accessors need not be defined for everything, can do something slightly more complex than just reading/writing, and allow you to change the class' implementation details without changing its interface). Such methods are called "accessors", "mutators", or "getters" and "setters" (the latter two depends on whether the accessor is supposed to read or write to that variable).
I code in java. I recommend project lombok. They have annotations such as @Getter and @Setter which can auto-generate (you guessed it) getters and setters
First one wouldn't even pass a corporate code review. They'll tell you to do it like the second one. Second one will pass the corporate code review, but management will decide it takes too long. They'll outsource this task to India, hire a joint venture management specialist and his assistant and a secretary and a coordinator and an additional HR person. Then they'll realize how expensive everything is and fire you to save some money. Management will give itself bonuses for reducing costs.
@@novelnouvel Yeah, I kinda feel that way too. Because when you go to update your project code, you update the code and then you have to update the documentation too. Which can be very tedious and easily forgotten.
@@tomebundalevski1872 yep, code which is self-explanatory is the best but ofc, that doesn't work if you are on a size scale like an OS-kernel, but it still helps a lot also, don't comment what your function does (if you need to do that, you are either doing A) a tutorial or B) comment terrible code or C) it because your boss said so) instead explain why that function is needed for the program (and if you can't come up with one, you are more than likely to not even need it in the first place) additionally, your function is probably too long if it doesn't fit on your (normal, so 16:9 1080p) screen anymore
I didn't add all the doxygen crud either. I do have a github repo though, which has all the code associated with the videos: github.com/OneLoneCoder/videos
Enterprise-level??? HA!!!... where's the ShapeFactory.createCircle()??? or new ShapeBuilder().makeSquere().setSize(10).build()? or the AbstractSqure : Shape??? I'd say it's not enterprise enough...
And where is unit testing. Nooo can't be like that, how do you expect code coverage to be done? It's needed for continuous integration! Oh wait, you say this project is not XML configurable? Ugh, obviously project is not configurable enough. And ah. This is all good, but this code is really not reuseable, well, you see, there is no dependency injection used. So extract abstract classes from all your implementation classes. And by the way, is your code is thread-safe? What? Have you forgot about parallelism and scalability?..
@@bbugarschi Should be it's own component so It can be accessible to all projects. No interface 😥, no unit tests 😪? No test first (TDD) 😉 Inheritance 🤮 amateur 🤣
@@javidx9 Dare I point out that some things could also be constexpr as well and that the value of Pi is dupicated? Better make that a constant. Also - pow(i, 2.0) might not quite convey that we're squaring something nicely enough... better make a function with the name square, or overload the ^ operator for T to make it nicer.
@@londospark7813 Don't forget to declare a constant - sorry a constexpr function - to return the value 2.0 for the pow() function. Need to get rid of the magic numbers.
well, yeah, i mean the Builder alone would take a good hundred lines or so. we'd also want some results to be Persistent and Thread-safe so we'll need separate classes for that. and I think it would be useful for some classes to be updated when a class is done squaring, so we will be modifying these legacy classes to be able to "subscribe" to the IntegerSquarerImpl class when it is done.
One sees over-engineering in software all the time. Overly academic engineering, overly abstract engineering, overly layered designs, all that. In what other fields of engineering do we see over-engineering? Electronics may sometimes look complicated to outsiders and beginners, but I can't say I've ever seen over-engineered electronics, not in real life. Maybe in over-priced gimmicky high-end audio, gold cables and all that fluff. Mechanical? Architectural? Costs keep things pretty well constrained to practical. Anything "over" is for extra strength, extra capacity, extra longevity, or for spacecraft to survive extreme conditions. What is special about software that so many pathologies of creation and implementation beset the industry?
A line of code is cheap and all the extra fluff is eaten by the compiler/linker anyway. If the resulting hex is small enough and fast enough it passes. (I wouldn't be surprised if both versions of the program output the same hex.)
@@LudwigvanBeethoven2 there is also an element of software developers being expected to be "agile" in the sense that they should be able to do arbitrary changes to the program they are requested to work with, and any change should be doable within days or at most a few weeks of a request! A good lead programmer will prevent that stuff from happening to his department of course. If specs were clear from the beginning in software, which they often aren't, then it would be easier to deal with. Premature optimization and generalization, as well as unclear end-goal, seems to be the cause of a good deal of bad code.
yeah, I definitely went through a phase of over-engineering code when I was right out of college. Another thing we coders always do is when you learn a new thing, you inevitably start inserting that new thing anywhere you can.
I had to maintain some internal tool written in Go by someone who was learning Go as he was writing the tool. He was a huge fan of select-case operator (using it incorrectly in places that didn't require it) and of goto, for some inexplicable reason. Maintaining this code was a nightmare.
lol, its scary isnt it Marevixo? That's why I made it! I saw myself trying to write code to some arbitrary standard that was imposed simply by the "community", based on nothing other than opinion and myth...
Yeah, I'm working on some game in Godot Engine, now I see lines of comments of which purpose was to tidy up the mess, but these lines brought even more chaos...
Well it's an outline at best. Really you'd likely want to know more than just the perimeter and and area. Otherwise a 2 by 8 rectangle behaves exactly the same as a 4x4 square. And what if you want a circle with an inscribed square taken out of the middle. And it's possible to create shaped of finite area but infinite perimeter. At the very least a shape in a real and useful library would need to include a reference point, and a method to determine if any particular x,y offset is within the shape or not. Then you could start building real generic functions like draw, union, disjuction, scale, translate, and rotate.
Hold on, it doesn't look good enough, let's add some more words! *This video of javidx9 about over-engineering* should definitely and most of all become the greatest meme in history of internet.
Hey, I need to comment about my amount of likes and set an EDIT and P.S line! *This video of javidx9 about over-engineering* should definitely and most of all become the greatest meme in history of internet. EDIT: omfg, 3 likes? Thanks guys, can we get to 100 likes, please? :)))))) P.S: You should make a part 2 of this video, I liked it and it's amazing!
Hmmm, there's not enough memes in this comment, let me fix this. Last time I was this early... I was still over-engineering my own comment in my comment section like an idiot ( ͡° ͜ʖ ͡°) 360 no scope, get rekt, give a like if you want 1 million dollars and a reply to kiss your crush tonight. *This video of javidx9 about over-engineering* should definitely and most of all become the greatest meme in history of internet. EDIT: omfg, 3 likes? Thanks guys, can we get to 100 likes, please? :)))))) P.S: You should make a part 2 of this video, I liked it and it's amazing!
My company is transitioning to a new platform. I have to work with the vendor to reproduce our old system with the new framework. They write code exactly like you did in this video. All the things they wrote have memory issues, for the exact same reason. I keep telling them that simplicity is King. They keep lecturing me on how good their abstract structure is. They cannot fix the slow performance of their modules, I have to do it. This is stupidity, at it's finest. When their code doesn't work and other people fix it for them, they still argue. Unbelievable!
well, if your code will be in some lib. that can be used somewhere else for different purpose, this way is the best way to make them work properly but if you need them for only one purpose then is a big NO. if you know that your lib gonna work only on two types of data there is no point to use templates, if you don't have issues with different classes with the same name there is no need to packages like namespaces. as robert martin said if the code is clean it can be self explanatory so you don't need those comments, like: "what this class called slackUser is meant for? what are those methods called: getName, getAge, getNickName; are there for?" duh!? those are self explanatory. you should put comments if is there something compicated that your self has difficult to even remember the day after (big allarm to clean your code and make a better version) but they might help you. so some are ok, that much are not.
@@iM7SnaKe " if you don't have issues with different classes with the same name there is no need to packages like namespaces." You don't have the foggiest clue what you're talking about. You should _never_ write nontrivial code of any kind in the global namespace.
Well you forgot one important thing: to decouple the code. Usually I have to go across 8 or 12 layers of decorators, visitors, law of demeter, etc before reading a line that actually do something...
Now don't spew crap about decorators and visitors, there ARE places they have their place. however it's places not "Let's base our project on programming patterns ". Now it's all new and fad but in 5 years finding a dev to wrap their heads aroud it will be nightmare.
@@Yhushe This doesn't work with me because I don't understand what the code does in the first place I once written an algorithm to scale a buffer full of pixels I spent 5 hours just changing variables randomly until it start working here is the code while(x < 64*256) { Plot_Pixel_Fast(x%64+y, x/32%128/2*2/2+z, c[x/16/16%16][x/4%16]); x = x + 1; } the function takes three parameters x, y and color c is just the colors of pixels If you know how it works please tell me since I who made it doesn't know also x = 0;
I never care what others would think of my code, I always try to make my code as small as possible with comments that only I can understand so that when if I ever come back later I don't get lost
@@Dennis19901 public class Animal { public virtual void Walk() { Console.WriteLine("Animal Walking"); } } public class Human : Animal { public override void Walk() { Console.WriteLine("Walks in two legs"); } } public class Tiger : Animal { public override void Walk() { Console.WriteLine("Walks in four legs"); } } EDIT: written in C#
On a serious note, I sometimes struggle with considering for a long time if I coded something the "correct" way instead of just implementing the thing that i wanted. That's kind of due to the thousands of little advice bits you get from people online.
Excellent. Remind me 30 years of professional programming with "professional programmers", while I was climbing the ladder they were still discussing the use of templates or "programming rules". And the comments are as good as the video.
The code is not wrong, and it's certainly a parody video, some folk just take it too seriously, and despite their best intentions, actually make it more frustrating for others!
that code is right one if you need to reuse your lib. he makes fun but using that as an example cause in the first place that class is doing it job for it purpose, but sometimes there are people who thinks too big and start to over-engineer the code even if they are not gonna reuse it for diffent types.
@@javidx9 The code is wrong in the regard this functioning was never required, it's over-processing. Like building a truck for someone who just wants to go to work. Code shall only be extended like this in the very moment it's required. Otherwise it's waste, it serves no purpose. It isn't cleaner but shittier. Academia is about correction, not effectiveness. After spending so much time on it you have to unlearn plenty of things, specially in the regard you write.
@@HannibalLecter-w3r Do they? I just got out of a CS class where our projects were graded on efficiency, and one of the projects required us to do a lot of euclidean distance computations, particularly on larger test cases. Some people were posting on our class's piazza that their programs were going over time before they replaced their pow function calls
@@toebel using pow is the idiomatic way. Note that pow uses double(64 bit float) so even if exponent is constant and equals 2, we still need to cast float to double, multiple it by itself and cast to float. If you are working with float(32 bit), use powf insead, it will be zero cost.
I admit, I've been guilty of some of this during my University years. In my defense, a lot of the programming instructors seemed to consider two variables when giving out grades: 1) Are there bugs? 2) How many comments were written per line? Thanks for the wake-up call, though. Great video!
It's not done yet - nobody knows how the end user will want to handle multiplication and memory allocation?! Let's add some policies and allocators via templates. That's how C++ and Boost libraries were born out of C.
it needs to define an enum like SetterSanityCheckResult and using a custom object creator like myOverEngineeredShapesLibrary::SetterSanityCheckResultCreator(DefaultSetterSanityCheckResultCreatorConfiguration, ...)
@@JorenX Also, you can just try building with one, and if that doesn't work, build with the other. Depending on the build time, it can be faster than googling.
Thank you! I got rejected for a code test for not putting comments on all my functions (this is in C#). This video validates I did the right thing and not over-engineer my code, especially for a code test!
@@javidx9 yeah i've got some project like that, and the teacher at university said: well to pass this course you need to reach at least 90% of code coverage. and i was like: damn 40% of those methods are just getters and setters, i don't need to test them i know for sure what the result gonna be, duh.
If you update, make sure to add in some mutexes or semaphores, you DO want it to support multi-threading don't you?? Oh and don't forget message ports for those who would rather work with it in an event driven way.
I still see lot of bugs. First of all if even setter you should validate is argument is >= 0.0. If it's not, then throw exception. So ofcourse you should also have your own exception class. Different class for every thrown exception. And try catch in every function that uses setter. Other people already mentioned that you haven't put PI in variable. You could just use M_PI from math.h, but if you want to be really profesional, then you should calculate it at start of application using Monte Carlo on max( 0.0, sqrt(1.0 - x*x) ). 2.0 * M_PI is TAU. Another constant to calculate on start using Monte Carlo. That kind of calculation will look really beautiful in your CV. Another unproffesion thing that I notice is that you have no Unit tests at all. This is so unproffesionall. You should make unit tests for every single method that you have created. Just to be sure that you haven't made any mistake. It also helps with planing, and reading and understanding you code. Another inapropiate thing is that it's all in one file. For every class you should have 2 separate files: *.h and *.cpp. All shape classes in one project, and main function in separate project. Then you should compile shapes in to shapes.dll or shapes.so, and import it in project with main function. Offcorse once that done, you will need to make sure that it will work on every possible OS. It's good that you have put comments, but non of them is compatible with javadoc. You need to make comets that later can be used for generating documentation. There is lot of javadoc commands that can be used to controll how documentation will be generated. And since not everybody know javadoc, you should put normal comment above every javadoc comment, and explain what that javadoc command do, everytime you use it. Also everybody know that mathematical operations are much faster on GPU, not CPU. So you should use Cuda if available, if not then use OpenCL, and if that is also not available, then use CPU, but try to use advance of multithreating. If it's not availble, then go back to standard single threated CPU calculation.
False. Setting a negative size is a valid action -- it will just mirror the shape in one axis. And if it's a symmetrical shape, a negative size will yield the same result as a positive one. Validate your user's inputs, but correct them if they can be corrected and don't be a school teacher to your users. If you didn't get the input from your user but instead something like a sensor, you would have needed to condition it anyway.
For cube or rectangle fine, we can correct negative length. But what should we do if we are working with tirangle defined by length of 2 sides and angle between them, and one of sides is negative ? Lets say 2.3, -1.8, 30*. On one hand we can just calculate abs, and get 2.3, 1.8, 30*. But on the other hand if we are going to mirror axe it should become: 2.3, 1.8, 150*. Thats totaly different triangle. So personaly I would always consider negative length as invalid input, but I see that other people may have different view on it, and it's fine. Should we validate is input valid or not, is different think. And it depend on what kind of project are working on, and what part of code. If you write a code for computer game that will be called 60 times per second for every vertex of every object on the scene, then go a head and skip error checking. But if you are writing medical software that is going to calculate drug doses once every 10min, and you get as input pacient height -5m, then please please throw an exception on every configuration. And make sure that while catching it, there will be email send to hospital IT, sms send to nurce, and print big red text on a screen. And then continue with default dose, or dose from 10min agao, or some good aproximation what it should be. And if you are writing software that will be runned only once, on your own machine, and it's job is to sort pictures of cats on your hard disk, and after that you will delete whole project, then again, go ahead and skip error checking. Just test it before running it on real photos. And to be clear, my previous comment was irony. I fully agree with point that this video is making. All my points are valid in certain cases, but usually they are over engineering. And over engineering is bad. And code like this is usually writen by people who do programming only for money. People who hate programing. They learned programing at univercity, and next they got some jobs as programmers, only because that was best paid job they found. And they don't even have PC at home. And if you ask person like that why they write code that way, they will tell you "becuase that wise book say so" (paper book). And book is writen by some 60y old prof who have never writen code other than example for students. Book writen using typewriter.
Brilliant video hahah ! I love how you emphasized the evolution of the programmer from "it works, now it's better, now it's getting crazy". I could recognize myself on a few "faults" x) . The line between over-engineered code and properly-engineered code can be a lit bit blurry sometimes. Because eg. the code might, maybe, someday, be used by someone, somewhere, who would eventually desperately need to use the code using doubles, and not using templates would make that impossible ..
And now add architectural over-engineering on top: 1. Make it micro-service and expose functionality via Rest API 2. Package it into Docker container that can run on container orchestration system like Kubernetes 3. Set up continuous delivery pipeline 4. Make sure your micro-service has multiple instances and set up load balancer to ensure high availability.
Good code shouldn't need a lot of comments. In just about every case when I see a comment it was due to a missed opportunity to create a function with a good name or name their variables better.
@@Baekstrom That strongly depends on the language and the proficiency of everyone who needs to understand the code. My main language is Matlab, and if other people see my code, they will probably be bad at it. So I don't just need to use good variable and function names, I also need to comment my code. If I'm pushing the language to its limits I'll be writing about 1 line of comment for every 2 lines of code. Simpler functions and algorithms might not need code at all, even for that audience.
*"TEMPLATES"* - that one hit me right in my 2nd year of college *"Getters and setters for every single field!"* - that one must've hit my college professors
"Getters and setters for every field" - Thank you, thank you, and thank you! I want to scream into the wind atop a nearby mountain peak for a whole year now for this very reason
The problem is that there is always something programmers want to change. We just draw a line in the sand and say that it will be in the next model or next upgrade. If you don't you'll never get anything finished :-(
I am glad I viewed this video as, I must confess, I tend to over engineer my work. Simultaneously, I found this video quite entertaining! Thank you for sharing this.
As a fan of C I feel this way when I see you use C++, but I both feel we can agree is is much worse with higher lever stuff then we might have to deal with.
Every time I see a namespace, I cringe Every time I see angled brackets (outisde of include or html), I cringe... Imagine using objects, at all... I'd be hopeless at C++ get::me_out::ofThisHell::PleaseThankYou
This is so funny! Seen this lots in my career, lots of big egos trying to show everyone they are 'smarter' than everyone else and therefore 'better' than everyone else. The insecure path of a narcissist. Great video!
Oh man I love this. I think the same. People make things so big so overengineered "just in case" or if "someone who doesn't know about programming looks at the code he can understand it that way".
You also need to overload operator, and add final and override in as many places as possible. The this pointer should be explicit in case someone doesn't know where the variable comes from. Also, you didn't specify that the angles of a rectangle were 90 degrees and that it is two pairs of sides are equal. So it's really a parallelogram at best, and at worst, some random quadrilateral. Also, cRectangle shouldn't derive from cShape, there should be cPolygon, cQuadrilateral, cConvexQuadrilateral and cParallelogram in between.
// if anybody reads this, add the line "// was here" and commit *6 years later* Still unchanged. Prof: "Add comments or you won't get full marks." Most popular comment: "// Boy, that's a hard problem" and similar stuff Found in ASM code: "nop ; unintended" Found in a constructor: /* First the universe was created. That was universally seen as a bad start, so we created this mess instead. */ One coder had a variable dwTIME in every single program, and never used it. His all-time fave song: "Dancing with tears in my eyes" Another had his ex's number as a random seed.
Bah Avon! Why bother deleting pointers?? Computers have loads of memory these days! ;-) C++ garbage collects doesn't it? Yeah, I think it does because modern languages do that these days. Anyway this code will be someone else's problem next week, I'm sure they'll remember to fix it because I'll leave a comment somewhere, and when I update the repo, I'll add the message "needs a fix". Job done! Syntax check passed, ship it!
I've been working on a coding project the last few days, and no joke, last night I looked at it and went "jesus, why've I plastered so many comments on this?" and tidied it up. I was then really anxious that it was hard to understand, but I left it as is. This video gave me the confidence to leave it as is
As all of my code is for me I tend to over comment. It could be a very long time between coding sessions for me so knowing exactly what the code is, how it works, and why it's there in extreme detail helps me.
@@DukeDudeston Yep. I just had to use one (a bit more complicated) script that I wrote three years ago and I found a bug from it. Thanks to my over commenting I was able to instantly figure out what was wrong.
My experience is that erring on the side of over-comment is always better. You will thank yourself 6 months later. Skipping comment is fast, but figuring out what 1000 lines does isn't. In the worst case, you will think hundreds of lines are redundent, but only to find out they fixed a bug after they are deleted.
I haven't seen your code so I don't want to judge too quickly, but maybe your variable and function names aren't clear enough? Maybe you don't split your code into enough separate functions, something like that?
Hold on, you forgot to: 1. Have a design review - so we'll be able to demonstrate how smart we are, and make you code something that nobody would want to touch, including you. 2. Open an epic + tasks + sub tasks in jira and keep changing the statuses as you "progress" with the feature. 3. Let us do a code review before you push, so we can demonstrate how smart we are (again) and make you rewrite your code over and over again. At least for two and a half years... the time it took google to recommend this video to me.
C'mon now, be honest... have you never been "that guy"? Hated on by your peers, because they considered themselves "leet", and above all reproach... just because you hadn't mastered, some arbitrary method/skill that, "duh, everybody should know"?
this video perfectly describes what my uni expected of me. one of the first bigger projects i've ever written were about 600 lines of code, 300 lines of comments and i didn't pass the first time it was tested because I DID NOT COMMENT ENOUGH so after i was done with what was done in this video i had 600 lines of code and 750 lines of comments and then i passed the course. i didnt change the code or anything and trust me, it wasnt overcomplicated since as a student i didnt have much idea about how to make it this complicated in the first place... though the "flaw" i had was that i didnt use enough libraries and wrote too much code they said
not that I wasn't already laughing, but when you pasted the licence, I cracked up! so true, all of it. And I must admit that I over comented in the past. A clever boss will say It was prior to leave a project :D. Love your content!
Out of curiousity, do you work on any libraries that other developers may use? Not talking about the sample/utility stuff I've seen you upload to Github. I can definitely say I've been guilty of actually over-engineering, spending days thinking and researching the "fastest/best" solution to something that isn't even clearly needing it yet. On the flip-side, I've worked with FAR FAR FAR more under-engineered garbage, unmaintainable code, than over-engineered code. In a professional setting, I'd much prefer to work with the over-engineered code. I know that I've considered code "over engineered" in the past, only to then find out it was my own knowledge gap that made me feel that way. Sometimes we think someone is being fancy, when its simply that they are doing something we just don't understand. Put it this way, as someone who's been programming professionally for almost 20 years, I've never complained that someone overdid something. But at almost every job/client, I've wanted to quit because I've inherited a pile of "lets just get this working" code, that hardly anybody gets paid to go back and cleanup/fix later.
Cannot agree more with you. While over-engineered code might not be optimal, it's still acceptable. Under-engineered "lazy" code is just unusable garbage.
It kinda depends. If you work on code that is only to be used for one use case in one program (and not a library or something), then making it as simple as possible is much better than using 1000's of unnecessary design patterns and whatnot, because, in the end, we spend much more time reading and trying to understand some code than actually writing it. It makes sense to try and minimize the amount of time it takes to understand something at the possible cost of having to refactor it slightly in the future. Plus, if a piece of code can only do the one thing it is actually supposed to do, it is much easier to understand what it is actually used for in the program. (E.g. if it only works with doubles and doesn't use templates, then we know that it's never being used to work with integers.) If you're working on a library then make sure it looks the way you'd expect a library to look like (with proper documentation and all), because, well, that's what it is. You can no longer speak of "over-engineering" when the problem you're trying to solve expects you to do what you are doing.
@@ThePC007 The number of times I've heard someone say: "just going to get this out the door, so I don't care about design", only to then eat those words 6-12 months later is astounding. I've trained many junior developers over the years that consistently do this, and they end up having to get paid to rewrite/refactor trash code down the line. Its very rare for projects to just be "sample" code. Most people write code that they need to maintain long term, either for personal projects, or far more likely, for professional work. Your boss will NOT want to pay you to rewrite or perform major refactors on code you've already been paid to write. If you're ok with going back to a messy pile of code 6 months later to spend hours (on your own dime) figuring it out and refactoring it, feel free to waste your time. The only people who don't care about the quality are people who don't expect other to have to look at their code, which is almost always a mistake. "Plus, if a piece of code can only do the one thing it is actually supposed to do, it is much easier to understand what it is actually used for in the program." Why are you assuming it actually does what it needs to do properly, and is easier to understand? Those two almost always fall flat if that code isn't well put together. That's exactly why people talk about design and maintainability together. You can't even test your code properly in cases like that. Also, don't assume that design means using 1000 design patterns, that is not a real argument, nobody said to overuse design patterns. Design patterns have their place, and may or may not be needed right off the bat. All this being said, its very fair to just write code without worrying about anything if you're trying to get an algorithm working or create some proof of concept. The issue is that people subscribe to this "meh, whatever" mentality and end up pushing code like that much further into a project because they refuse to actually clean it up/design it early on. That is what I take issue with, because it happens all the time. As a consultant I'm constantly picking up code from other developers who had this shit mentality and sometimes drives me nuts.
@@NickEnchev You've probably misunderstood my comment in the most epic way possible. When I was talking about making the code "as simple as possible", I have actually meant just that, to make the code simple. I have no idea how that is supposed to mean that the code is supposed to be messy, which is the exact opposite of that I said. My comment was literally about making the code simple and therefore easier to maintain, and you are pretending that I said the opposite. I don't get it.
If you don't over-engineer, I can always find that little missing detail to put down your work. If you do everyrthing "right" I can still say "overkill". You lose... FATALITY.
i realy love your video's and this video show a very importen point maney developers do wrong, as you say "don't over-engineer your code" i see many new developers do this, and my expriens tell me, its coming with many years of developering after you have done a lots of mistakes, i really hope your video help a lots out there, i really love you videos :)
I think I’ve watched this video 1~2 years ago, but I realized I was over-engineering my code just few months ago. Since then, I am doing this now: No matter what it will become, write it in the simplest way possible first.
All that refactoring... and he still didn't turn PI into a constant.
Cus he doesnt get the point.
M_PI is in an include file for a reason. I've defined several other constants in include files, often using bc to get them to 20 digits.
He could define it as a macro:
#define PI 3.1415
instead of using const..
@@anmaral-sharif1381 It's *already* defined. There's no need to define it with less precision when it's already defined in an include file with double precision. On Linux, there's also M_PIl, in case you're using (and can get) 128-bit floats.
That's what mediocre programmers do all the time - over engineering staff while fucking up simple things. I think the author left it for a reason there =)
I love a quote from a book: "Code can be so complex that there are no obvious bugs or so simple that there are obviously no bugs"
Nice one!
A quote by Tony Hoare :)
oh i like that one
name of the book pls
@@caioffsantos it is a quote from an article in the ACM magazine that I think I read cited in the book called "Clean Code"
I'm not even joking, this is really close to how I was taught programming in uni. You'd lose marks if every line wasn't commented.
Initially we had to comment everything, too. But commenting variables was only when it wasn't immediately obvious what they were gonna do. Also getters/setters would at most get 1 comment for the whole section like //getters and setters .. and then you would just put all the getters and setters grouped up below that.
And we used real comments that described how a function was used. E.g. "takes 2 int parameters and returns a two-tuple of integers as a result". And those comments do have value if you're writing a library that others are gonna use. Because if the function names are obvious enough they don't need to read code but they can just look for the correct function in the documentation and know what parameter it uses and what the return value will be.
I'm from Slovenia, and when I was studying at university ( I finished last year ) I don't remember ever "needing" to comment your code. You just had to know what it does, if you used comments here and there to help you that was fine.
In corporate world, if you have to comment so much that means your code is not self explanatory and therefore bad.
Same bro, This is exactly how I how I was taught to code at my university! Except we only had to comment explaining what our functions parameters were and what it returns.
Very true😅😅
"Getters and setters for every single field!"
You just invented Java!
What are getters and setters?
@@AyushGupta-wn6zd I'll assume it's a honest question.
Getters and setters are methods that allows you to respectively retrieve (get) or modify (set) the value of a private variable.
...perhaps that definition doesn't help you much either. So here's the longest version:
In a lot of languages, there's something called "classes", basically, it's a blueprint you write for more complex objects (you can think of a class as an empty form with various kind of fields, and each object being a filled form; there are typically multiple objects of the same class). Classes also typically define functions that will operate on the data they contain (for instance, a "character sheet" class might define a function which, when executed, will roll attack damage depending on the strength and weapons filled in the character sheet; note the function is always the same for all objects of the same class, but the data it operates on changes for each object). Such functions are called "methods".
Now, sometimes, you want to ensure that the object's data is consistent. For instance, you could have fields "Job" and "Deity" in your dnd character sheet, but it wouldn't make sense to write out "Job: Priest" and "Deity: None" because priests must always belong to some kind of church. So, most languages that define classes also allows the class' author (the programmer) to declare some fields "private". Declaring a field private forbids its use by anything outside the class, so basically, only the class' methods can use it. That way, if you declared the Job and Deity field private, you'd be forced to use one of the class' methods to update their value, and the class' author can make sure that the methods never allows "Job" to be set to "Priest" when "Deity" is set to "None".
This is a rather naive example, but in practice, it's often important to hide implementation details that shouldn't matter to the class' user and needn't be tampered with (that's called "encapsulation"). It became common place to always declare all your variables private. However, sometimes, you still need to be able to read the value or change the value of one such variable, in which case, instead of not declaring that variable private, you'll write methods to do that for you (this can seem weird to encapsulate only to break encapsulation by defining accessors, and sometimes it is, but the key is that accessors need not be defined for everything, can do something slightly more complex than just reading/writing, and allow you to change the class' implementation details without changing its interface). Such methods are called "accessors", "mutators", or "getters" and "setters" (the latter two depends on whether the accessor is supposed to read or write to that variable).
It's true. I often feel compelled to make getters and setters for most fields/attributes.
I code in java. I recommend project lombok. They have annotations such as @Getter and @Setter which can auto-generate (you guessed it) getters and setters
@@ThomasBomb45 Most Java IDE's also have the option to auto-generate getters and setters for you.
This is getting played out our next dev team meeting!
First one wouldn't even pass a corporate code review. They'll tell you to do it like the second one.
Second one will pass the corporate code review, but management will decide it takes too long. They'll outsource this task to India, hire a joint venture management specialist and his assistant and a secretary and a coordinator and an additional HR person. Then they'll realize how expensive everything is and fire you to save some money. Management will give itself bonuses for reducing costs.
AHAHAHAH
Ooohhh, so that's why opensource software is so much leaner than closed source.
Everyone should start with writing a program that replaces the need for Management.
@@ChrisKeddy Got you covered, fam.
while (true){
if(profits < 0){
Employees.GetRandom().Fire();
StartCoroutine(new MotivationSpeech());
}
else{
var amount = profits * 2;
Self.IncreaseBonusPayment(amount);
}
}
Well put.
"I wonder if everyone will understand what this boolean means. I mean, it could be true or false."
HAHAHAHAHAHHAAHHAHAHAHAHAHHAAH
But did he ever consider that someone might not understand what the nullptr points too. I mean, it could point to nothing or not point to anything.
OH! I love THIS!!! xD
but what if it is both?! :O *MIND BLOWN AWAY* EQUAL ... ==
If it is an int, it could go to 11.
nooo but he needs factoriees. integerFactoryy
"It's the best code ever!"
*Compilation error*
it's me i guess
Not just any compilation error. The good ol' stone age SEGFAULT.
make your own compiler
The best code ever, it compiles but it doesn't works lol
Need to download MSIX package only 8gb and Microsoft booster classes for Google and bing live testing also bootcamp
Junior: hard-code it.
Senior: hard-code it.
Mid-level: let me do all that because I've just learned it, feels good!
Senior will do the other thing once it's needed. Medior will do it out of the gate without knowing whether it will ever be needed.
Junior can't.
2:52 I laughed out loud when you pasted the entire text of the GNU GPL in there
When I was in high school, I always did this before I turned in my assignments. I'm pretty sure it irritated my teacher
LOC-4-LYFE
This is the most important thing I have learned in 17 years of professional coding. keep it as simple as possible as complexity will appear by itself.
Mess will appear by itself, surely xD At least that's what I learned in 20 years of amateur programming, but then I'm an amateur...
"complexity will appear by itself", truer words have never been spoken...
@Chris Russell thousands of thousands line of codes with no documentation is the best code ever
@@novelnouvel Yeah, I kinda feel that way too. Because when you go to update your project code, you update the code and then you have to update the documentation too. Which can be very tedious and easily forgotten.
@@tomebundalevski1872 yep, code which is self-explanatory is the best
but ofc, that doesn't work if you are on a size scale like an OS-kernel, but it still helps a lot
also, don't comment what your function does (if you need to do that, you are either doing A) a tutorial or B) comment terrible code or C) it because your boss said so) instead explain why that function is needed for the program (and if you can't come up with one, you are more than likely to not even need it in the first place)
additionally, your function is probably too long if it doesn't fit on your (normal, so 16:9 1080p) screen anymore
“Know when to stop.”
And here I am wanting to know when to start.
Ah man I feel you
Broooooooo. 😫
@@suza3199 Same... i try to start since years. 😃
The best time after yesterday is today ;)
Now.
Truly enterprise-level. Where's the github repo?
I didn't add all the doxygen crud either. I do have a github repo though, which has all the code associated with the videos: github.com/OneLoneCoder/videos
XD
Enterprise-level??? HA!!!... where's the ShapeFactory.createCircle()??? or new ShapeBuilder().makeSquere().setSize(10).build()? or the AbstractSqure : Shape???
I'd say it's not enterprise enough...
And where is unit testing. Nooo can't be like that, how do you expect code coverage to be done? It's needed for continuous integration!
Oh wait, you say this project is not XML configurable? Ugh, obviously project is not configurable enough.
And ah. This is all good, but this code is really not reuseable, well, you see, there is no dependency injection used. So extract abstract classes from all your implementation classes.
And by the way, is your code is thread-safe? What? Have you forgot about parallelism and scalability?..
@@bbugarschi Should be it's own component so It can be accessible to all projects. No interface 😥, no unit tests 😪? No test first (TDD) 😉 Inheritance 🤮 amateur 🤣
You've imported 2 things in that code: where's your dependancy manager?!
Yeah, what if universe physics changes and you'll need another rectangle implementation?
@@PetrPss Well, what if you want this to work in non-Euclidean geometries? That is a thing.
@@Airblader Non-Euclidean geometry rectangle class should be chosen explicitly, not injected. Because it's different type (kind) of object.
@@Airblader I don't know if I want to take into account other dimensions that I might not even use.... (Phillip J Fry)
@@PetrPss LMAO
I liked you included both "cmath" and "math.h" because on of them must be the correct one :)
😂
duuudee!!!!youdidnt const the getters!!!!!!!!!! angerY
lol, looks like i need an update to this with all the suggestions!
@@javidx9 please do that haha
@@javidx9 Dare I point out that some things could also be constexpr as well and that the value of Pi is dupicated? Better make that a constant. Also - pow(i, 2.0) might not quite convey that we're squaring something nicely enough... better make a function with the name square, or overload the ^ operator for T to make it nicer.
NOEXCEPT!!! AAAAAAAArgh!
@@londospark7813 Don't forget to declare a constant - sorry a constexpr function - to return the value 2.0 for the pow() function. Need to get rid of the magic numbers.
#include , #include //I'm not sure which one so let's be safe
brilliant idea
bruh wrong planet
Lol
I dont get this one. cmath is for c++, and math.h is for c, huh?
@@5cover I think cmath is complex number math (so Euler's formula and stuff). That's how it is in python at least
+hebrewname ummm no. Don’t be answering questions on a beginners programming youtube if you don’t know the answers!!
1000 lines of code just isn’t sufficient enough to square an integer.
Math
well, yeah, i mean the Builder alone would take a good hundred lines or so.
we'd also want some results to be Persistent and Thread-safe so we'll need separate classes for that.
and I think it would be useful for some classes to be updated when a class is done squaring, so we will be modifying these legacy classes to be able to "subscribe" to the IntegerSquarerImpl class when it is done.
@Богдан Кондратов stack it
Mathf.sqrt(int);
One sees over-engineering in software all the time. Overly academic engineering, overly abstract engineering, overly layered designs, all that. In what other fields of engineering do we see over-engineering? Electronics may sometimes look complicated to outsiders and beginners, but I can't say I've ever seen over-engineered electronics, not in real life. Maybe in over-priced gimmicky high-end audio, gold cables and all that fluff. Mechanical? Architectural? Costs keep things pretty well constrained to practical. Anything "over" is for extra strength, extra capacity, extra longevity, or for spacecraft to survive extreme conditions. What is special about software that so many pathologies of creation and implementation beset the industry?
A line of code is cheap and all the extra fluff is eaten by the compiler/linker anyway. If the resulting hex is small enough and fast enough it passes.
(I wouldn't be surprised if both versions of the program output the same hex.)
It comes from the mind and not the physical world
I think because developers don't consider time as the important cost. They waste time and when dead line is near they actually write some good stuff!
@@LudwigvanBeethoven2 there is also an element of software developers being expected to be "agile" in the sense that they should be able to do arbitrary changes to the program they are requested to work with, and any change should be doable within days or at most a few weeks of a request!
A good lead programmer will prevent that stuff from happening to his department of course.
If specs were clear from the beginning in software, which they often aren't, then it would be easier to deal with. Premature optimization and generalization, as well as unclear end-goal, seems to be the cause of a good deal of bad code.
I do electronics and to be honest often "under-engienieering" is a problem. :D
yeah, I definitely went through a phase of over-engineering code when I was right out of college. Another thing we coders always do is when you learn a new thing, you inevitably start inserting that new thing anywhere you can.
I had to maintain some internal tool written in Go by someone who was learning Go as he was writing the tool. He was a huge fan of select-case operator (using it incorrectly in places that didn't require it) and of goto, for some inexplicable reason. Maintaining this code was a nightmare.
good thing about this is that you'll let this memorize
Oh shit... I just saw myself in this vid. Thank for bringing me back on the ground
lol, its scary isnt it Marevixo? That's why I made it! I saw myself trying to write code to some arbitrary standard that was imposed simply by the "community", based on nothing other than opinion and myth...
Yeah, I'm working on some game in Godot Engine, now I see lines of comments of which purpose was to tidy up the mess, but these lines brought even more chaos...
huh? I try to make a functional language out of everything I see! Don't care if it's C++ or Rust or anything xD
Uni basically forces you to write code comments like that 😂
@@w花b what kinda help?
lmao "It works for all 2D shapes, but I've only implemented rectangles and circles."
Well it's an outline at best. Really you'd likely want to know more than just the perimeter and and area. Otherwise a 2 by 8 rectangle behaves exactly the same as a 4x4 square. And what if you want a circle with an inscribed square taken out of the middle.
And it's possible to create shaped of finite area but infinite perimeter.
At the very least a shape in a real and useful library would need to include a reference point, and a method to determine if any particular x,y offset is within the shape or not.
Then you could start building real generic functions like draw, union, disjuction, scale, translate, and rotate.
But what about 3D shapes? And 4D shapes? Hell what about nD shapes?! What if …
@@WorBlux Not to discuss your other points but
2x8 Perimeter: 8 + 8 + 2 + 2 = 20
4x4 Perimeterer: 4 + 4 + 4 + 4 = 16
Polygons! concave and convex :D
I'm dying
This should become a meme
Wait! I forgot bold characters!
*This* should become a meme.
Hold on, it doesn't look good enough, let's add some more words!
*This video of javidx9 about over-engineering* should definitely and most of all become the greatest meme in history of internet.
Hey, I need to comment about my amount of likes and set an EDIT and P.S line!
*This video of javidx9 about over-engineering* should definitely and most of all become the greatest meme in history of internet.
EDIT: omfg, 3 likes? Thanks guys, can we get to 100 likes, please? :))))))
P.S: You should make a part 2 of this video, I liked it and it's amazing!
Hmmm, there's not enough memes in this comment, let me fix this.
Last time I was this early...
I was still over-engineering my own comment in my comment section like an idiot ( ͡° ͜ʖ ͡°) 360 no scope, get rekt, give a like if you want 1 million dollars and a reply to kiss your crush tonight.
*This video of javidx9 about over-engineering* should definitely and most of all become the greatest meme in history of internet.
EDIT: omfg, 3 likes? Thanks guys, can we get to 100 likes, please? :))))))
P.S: You should make a part 2 of this video, I liked it and it's amazing!
you have created the most clever comment i have ever seen my guy
Encryption - "Nah!! Too old fashioned"
Over-engineering - "Yeah!! This will save my code from theft. "
This is the story of my life. Neurotic perfectionism makes me a comparatively bad programmer
My company is transitioning to a new platform. I have to work with the vendor to reproduce our old system with the new framework. They write code exactly like you did in this video. All the things they wrote have memory issues, for the exact same reason. I keep telling them that simplicity is King. They keep lecturing me on how good their abstract structure is. They cannot fix the slow performance of their modules, I have to do it. This is stupidity, at it's finest. When their code doesn't work and other people fix it for them, they still argue. Unbelievable!
It still surprises me when people think this video is a mockery. Almost everywhere I have worked with "pro" code has been like this :D
:D yep that's true simplicity is everything
well, if your code will be in some lib. that can be used somewhere else for different purpose, this way is the best way to make them work properly but if you need them for only one purpose then is a big NO. if you know that your lib gonna work only on two types of data there is no point to use templates, if you don't have issues with different classes with the same name there is no need to packages like namespaces. as robert martin said if the code is clean it can be self explanatory so you don't need those comments, like: "what this class called slackUser is meant for? what are those methods called: getName, getAge, getNickName; are there for?" duh!? those are self explanatory. you should put comments if is there something compicated that your self has difficult to even remember the day after (big allarm to clean your code and make a better version) but they might help you. so some are ok, that much are not.
a memory limitation will lead them to optimization. :)))))
@@iM7SnaKe " if you don't have issues with different classes with the same name there is no need to packages like namespaces."
You don't have the foggiest clue what you're talking about. You should _never_ write nontrivial code of any kind in the global namespace.
Well you forgot one important thing: to decouple the code. Usually I have to go across 8 or 12 layers of decorators, visitors, law of demeter, etc before reading a line that actually do something...
What's that you say? Law of dementia?
Especially in libraries
Did he multithread the code? What if you could call multiple getters from different threads at the same time!
Ohh My God!
Now don't spew crap about decorators and visitors, there ARE places they have their place. however it's places not "Let's base our project on programming patterns ". Now it's all new and fad but in 5 years finding a dev to wrap their heads aroud it will be nightmare.
"now I need a license, so I'll grab one from the internet" *literal wall of text ensues* "that's excellent" LMAOOO
and it's the GPL-3, a meme on its own.
@@LordOfTheBing yo, dont hate on gpl3 my dude
@@LordOfTheBing gnu vult
oi m8 u got a loisence for that code?
"What if future developers don't understand this?" (Says while he is the only developer who will be using that code ever)
Then you come to your code after a long while and you're like "What did this thing do again?"
Not that I'm talking by experience...
@@Yhushe This doesn't work with me because I don't understand what the code does in the first place
I once written an algorithm to scale a buffer full of pixels I spent 5 hours just changing variables randomly until it start working
here is the code
while(x < 64*256)
{
Plot_Pixel_Fast(x%64+y, x/32%128/2*2/2+z, c[x/16/16%16][x/4%16]);
x = x + 1;
}
the function takes three parameters x, y and color
c is just the colors of pixels
If you know how it works please tell me since I who made it doesn't know
also x = 0;
I never care what others would think of my code, I always try to make my code as small as possible with comments that only I can understand so that when if I ever come back later I don't get lost
@@Mugistan I am just interested to understand the code. So will you tell me, what the z variable is.🙂
@@jonayedmohiuddin538 I'd want to help you but I really have no idea how it worked
I couldn't understand polymorphism for 2 years until I watched this, and it's not even the point of the video
same lmao
polymorphism, in short, is like animals are walking but in different ways.
*Example:*
*Tiger:* walks in four legs
*Human:* walks in two legs
@@shootme4472 Well, this is a bad example...
@@Dennis19901 How? can you explain why?
@@Dennis19901
public class Animal
{
public virtual void Walk()
{
Console.WriteLine("Animal Walking");
}
}
public class Human : Animal
{
public override void Walk()
{
Console.WriteLine("Walks in two legs");
}
}
public class Tiger : Animal
{
public override void Walk()
{
Console.WriteLine("Walks in four legs");
}
}
EDIT: written in C#
Not enough operator overloading!! Should at least override the equality operator to see if two shapes are the same.
This but unironically in python
And Java
Having to use Java for some stuff (specifically Minecraft modding), kill me. Especially since it doesn't have operator overloading.
I hate having some vector library in java but not being able to add them together with the + symbol
@@MagicGonads could use Kotlin instead, it has (limited) operator overloading.
On a serious note, I sometimes struggle with considering for a long time if I coded something the "correct" way instead of just implementing the thing that i wanted. That's kind of due to the thousands of little advice bits you get from people online.
I had this same issue for a very long time.
You got me with the GPL license
a 3:00 i'm seeing the best code i've ever seen. so well documented i could scroll through it for hours and not get a thing done.
Excellent. Remind me 30 years of professional programming with "professional programmers", while I was climbing the ladder they were still discussing the use of templates or "programming rules". And the comments are as good as the video.
This video is golden! Sadly, this is exactly what we got taught at my university. That's probably why you sometimes see this kind of code
The code is not wrong, and it's certainly a parody video, some folk just take it too seriously, and despite their best intentions, actually make it more frustrating for others!
that code is right one if you need to reuse your lib. he makes fun but using that as an example cause in the first place that class is doing it job for it purpose, but sometimes there are people who thinks too big and start to over-engineer the code even if they are not gonna reuse it for diffent types.
@@javidx9 The code is wrong in the regard this functioning was never required, it's over-processing. Like building a truck for someone who just wants to go to work.
Code shall only be extended like this in the very moment it's required. Otherwise it's waste, it serves no purpose. It isn't cleaner but shittier.
Academia is about correction, not effectiveness. After spending so much time on it you have to unlearn plenty of things, specially in the regard you write.
But university was just teaching you most of these so that you can use them when you need to. Not that you should use them always
2:22 "I'm not sure which, lets be safe." LMFAOOOOOOOOOO THATS ACTUALLY GOOD HAHAHA
Not to mention that pow(x,2) is signifigantly slower than x * x lol
yeah because pow(x,2) is incorrect lol
@@toebel compilers will optimize this.
@@HannibalLecter-w3r Do they? I just got out of a CS class where our projects were graded on efficiency, and one of the projects required us to do a lot of euclidean distance computations, particularly on larger test cases. Some people were posting on our class's piazza that their programs were going over time before they replaced their pow function calls
@@toebel using pow is the idiomatic way. Note that pow uses double(64 bit float) so even if exponent is constant and equals 2, we still need to cast float to double, multiple it by itself and cast to float. If you are working with float(32 bit), use powf insead, it will be zero cost.
"I've added a virtual destructor now because vs always seems to add one, butu I'm unsure what it does" LOL
Isn't this actually pretty important, though? stackoverflow.com/questions/461203/when-to-use-virtual-destructors
@@timothyLucasJaeger yeah ofc, but it's fun because I think everyone has had that thought in their life :)
I come back to this every few months to regain some sanity. Thank you
I admit, I've been guilty of some of this during my University years. In my defense, a lot of the programming instructors seemed to consider two variables when giving out grades:
1) Are there bugs?
2) How many comments were written per line?
Thanks for the wake-up call, though. Great video!
It's not done yet - nobody knows how the end user will want to handle multiplication and memory allocation?! Let's add some policies and allocators via templates. That's how C++ and Boost libraries were born out of C.
lol, that's the spirit!
And factories because who knows how user will need to make objects
This is what happens when your boss watch you code.
... and when you get judged on your 'performance output' by lines of code witten per week instead of actual functions implemented.
YOU HAVEN'T USE AN ENUM INSTEAD OF BOOL! Dude, you've made my day! Thank you very much!
it needs to define an enum like SetterSanityCheckResult and using a custom object creator like myOverEngineeredShapesLibrary::SetterSanityCheckResultCreator(DefaultSetterSanityCheckResultCreatorConfiguration, ...)
"I don't know which one, let's be safe"
The amount of times I did that.
cppreference pages are everywhere? Google it lol, takes 10 sec
@@JorenX Also, you can just try building with one, and if that doesn't work, build with the other. Depending on the build time, it can be faster than googling.
Or you can just man whichever function you're trying to include and it will tell you in what file it is :)
Thank you! I got rejected for a code test for not putting comments on all my functions (this is in C#). This video validates I did the right thing and not over-engineer my code, especially for a code test!
I love how you turned into John Romero at the end of the video.
So true! I've already implemented templates, but I didn't add namespace and licience yet. Way to improve my project Thank you for this brilliant idea!
You know when it's done when you look like John Romero. :3
lol Tricore
I thought he looked like Richard Stallman...
lmao
Exactly Keanu Reaves!
*lights cigarette*
"Was it good for you too?"
I didn't know how much I needed to hear this, I was laughing loudly full of shame and sudden self awareness. Thank you very much.
Don't forget the Unit Tests! XD
Unit tests for every getter and setter individually!
@@javidx9 yeah i've got some project like that, and the teacher at university said: well to pass this course you need to reach at least 90% of code coverage. and i was like: damn 40% of those methods are just getters and setters, i don't need to test them i know for sure what the result gonna be, duh.
@@iM7SnaKe what the hell is "code coverage"?
@@anonanon3066 google it
@@iM7SnaKe That my be an indication that it's time to refactor your code.
It's not done! There is shape factory?
I'll have to update this soon!
If you update, make sure to add in some mutexes or semaphores, you DO want it to support multi-threading don't you?? Oh and don't forget message ports for those who would rather work with it in an event driven way.
Yeah this lacks shape factories and repositories with unnecessary single-implementation interfaces.
@@Cybeonix hahaha
don't forget the ShapeFactoryBuilder and ShapeFactoryBuilderFactory
I still see lot of bugs.
First of all if even setter you should validate is argument is >= 0.0.
If it's not, then throw exception. So ofcourse you should also have your own exception class. Different class for every thrown exception. And try catch in every function that uses setter.
Other people already mentioned that you haven't put PI in variable. You could just use M_PI from math.h, but if you want to be really profesional, then you should calculate it at start of application using Monte Carlo on max( 0.0, sqrt(1.0 - x*x) ).
2.0 * M_PI is TAU. Another constant to calculate on start using Monte Carlo.
That kind of calculation will look really beautiful in your CV.
Another unproffesion thing that I notice is that you have no Unit tests at all. This is so unproffesionall.
You should make unit tests for every single method that you have created. Just to be sure that you haven't made any mistake. It also helps with planing, and reading and understanding you code.
Another inapropiate thing is that it's all in one file. For every class you should have 2 separate files: *.h and *.cpp. All shape classes in one project, and main function in separate project. Then you should compile shapes in to shapes.dll or shapes.so, and import it in project with main function.
Offcorse once that done, you will need to make sure that it will work on every possible OS.
It's good that you have put comments, but non of them is compatible with javadoc. You need to make comets that later can be used for generating documentation.
There is lot of javadoc commands that can be used to controll how documentation will be generated. And since not everybody know javadoc, you should put normal comment above every javadoc comment, and explain what that javadoc command do, everytime you use it.
Also everybody know that mathematical operations are much faster on GPU, not CPU. So you should use Cuda if available, if not then use OpenCL, and if that is also not available, then use CPU, but try to use advance of multithreating. If it's not availble, then go back to standard single threated CPU calculation.
Stfu
awake lol
This guy code reviews
False. Setting a negative size is a valid action -- it will just mirror the shape in one axis. And if it's a symmetrical shape, a negative size will yield the same result as a positive one.
Validate your user's inputs, but correct them if they can be corrected and don't be a school teacher to your users. If you didn't get the input from your user but instead something like a sensor, you would have needed to condition it anyway.
For cube or rectangle fine, we can correct negative length.
But what should we do if we are working with tirangle defined by length of 2 sides and angle between them, and one of sides is negative ?
Lets say 2.3, -1.8, 30*.
On one hand we can just calculate abs, and get 2.3, 1.8, 30*.
But on the other hand if we are going to mirror axe it should become: 2.3, 1.8, 150*.
Thats totaly different triangle.
So personaly I would always consider negative length as invalid input, but I see that other people may have different view on it, and it's fine.
Should we validate is input valid or not, is different think.
And it depend on what kind of project are working on, and what part of code.
If you write a code for computer game that will be called 60 times per second for every vertex of every object on the scene, then go a head and skip error checking.
But if you are writing medical software that is going to calculate drug doses once every 10min, and you get as input pacient height -5m, then please please throw an exception on every configuration. And make sure that while catching it, there will be email send to hospital IT, sms send to nurce, and print big red text on a screen. And then continue with default dose, or dose from 10min agao, or some good aproximation what it should be.
And if you are writing software that will be runned only once, on your own machine, and it's job is to sort pictures of cats on your hard disk, and after that you will delete whole project, then again, go ahead and skip error checking. Just test it before running it on real photos.
And to be clear, my previous comment was irony.
I fully agree with point that this video is making.
All my points are valid in certain cases, but usually they are over engineering.
And over engineering is bad.
And code like this is usually writen by people who do programming only for money. People who hate programing.
They learned programing at univercity, and next they got some jobs as programmers, only because that was best paid job they found.
And they don't even have PC at home.
And if you ask person like that why they write code that way, they will tell you "becuase that wise book say so" (paper book).
And book is writen by some 60y old prof who have never writen code other than example for students. Book writen using typewriter.
Brilliant video hahah ! I love how you emphasized the evolution of the programmer from "it works, now it's better, now it's getting crazy". I could recognize myself on a few "faults" x) .
The line between over-engineered code and properly-engineered code can be a lit bit blurry sometimes. Because eg. the code might, maybe, someday, be used by someone, somewhere, who would eventually desperately need to use the code using doubles, and not using templates would make that impossible ..
2:49 "it works for all 2d shapes, but I've only implemented rectangles and circles"
HAHAHA YESS
And now add architectural over-engineering on top:
1. Make it micro-service and expose functionality via Rest API
2. Package it into Docker container that can run on container orchestration system like Kubernetes
3. Set up continuous delivery pipeline
4. Make sure your micro-service has multiple instances and set up load balancer to ensure high availability.
Yes and abstract away the microservices with othe rmicroservices, I have actually seen this happen
I laughed so hard, it is too much :D ruclips.net/video/jKolJFvqniQ/видео.html
:) :D
Needs more AbstractShapeFactoryConfigurationFactory
/* !< Putting this class in to comply with arbitrary coding style standard IEC-123456-789 as per company requirement. */
If you don't comment your code they can't fire you...as simple as that ;)
they can, but that'll be the next guy's job, till they quit or get fired.
Good code shouldn't need a lot of comments. In just about every case when I see a comment it was due to a missed opportunity to create a function with a good name or name their variables better.
If your code needs a lot of comments to be understandable then you should be fired.
@@Baekstrom That strongly depends on the language and the proficiency of everyone who needs to understand the code. My main language is Matlab, and if other people see my code, they will probably be bad at it. So I don't just need to use good variable and function names, I also need to comment my code. If I'm pushing the language to its limits I'll be writing about 1 line of comment for every 2 lines of code. Simpler functions and algorithms might not need code at all, even for that audience.
Code is also in English, why do you need to comment ?
*"TEMPLATES"* - that one hit me right in my 2nd year of college
*"Getters and setters for every single field!"* - that one must've hit my college professors
Am currently in my second year of college, can confirm I've spent an inordinate amount of time making things with templates for no reason.
"Getters and setters for every field" - Thank you, thank you, and thank you! I want to scream into the wind atop a nearby mountain peak for a whole year now for this very reason
"I know! templates!" *whacking away at the keyboard*
LMAO
Thumbnail looks like Keanu Reeves techaes programming
Knock, knock, Neo.
Keanu Teeches
You're breathtaking.
@@NST-games no u
*teaches
We called it creeping elegance.
This is a phrase I like, and will take to work :D
The problem is that there is always something programmers want to change. We just draw a line in the sand and say that it will be in the next model or next upgrade. If you don't you'll never get anything finished :-(
I am glad I viewed this video as, I must confess, I tend to over engineer my work. Simultaneously, I found this video quite entertaining! Thank you for sharing this.
"This code doesn't show how good I can be as a programmer"... I have seen job security empires start like this
As a fan of C I feel this way when I see you use C++, but I both feel we can agree is is much worse with higher lever stuff then we might have to deal with.
Every time I see a namespace, I cringe
Every time I see angled brackets (outisde of include or html), I cringe...
Imagine using objects, at all...
I'd be hopeless at C++
get::me_out::ofThisHell::PleaseThankYou
This looks exactly what I work with except all the comments because we have a *huge* google doc for that
Why is this recommend to me during quarantine, 3 years after the video was released 😂
so this is what Gilfoyle ends up doing during the quarantine after the Pied Piper fallout
The code that is the RUclips algorithm will forever be a mystery.
This is so funny! Seen this lots in my career, lots of big egos trying to show everyone they are 'smarter' than everyone else and therefore 'better' than everyone else. The insecure path of a narcissist. Great video!
Oh man I love this. I think the same. People make things so big so overengineered "just in case" or if "someone who doesn't know about programming looks at the code he can understand it that way".
You also need to overload operator, and add final and override in as many places as possible. The this pointer should be explicit in case someone doesn't know where the variable comes from. Also, you didn't specify that the angles of a rectangle were 90 degrees and that it is two pairs of sides are equal. So it's really a parallelogram at best, and at worst, some random quadrilateral.
Also, cRectangle shouldn't derive from cShape, there should be cPolygon, cQuadrilateral, cConvexQuadrilateral and cParallelogram in between.
LOL
I remember being mad at some code I had to edit and then it turned out I wrote it! I prefer amazing code that I didn't recognize that I wrote.
my largest comment was shrek ascii art in a function called meatspin();
You are a true nerd. I find that slightly sympathetic. No homo, though.
My brethren, I once hid the entirety of the Navy Seal Copypasta inside a random class' file.
// if anybody reads this, add the line "// was here" and commit
*6 years later*
Still unchanged.
Prof: "Add comments or you won't get full marks."
Most popular comment: "// Boy, that's a hard problem" and similar stuff
Found in ASM code: "nop ; unintended"
Found in a constructor:
/* First the universe was created.
That was universally seen as a bad start,
so we created this mess instead. */
One coder had a variable dwTIME in every single program, and never used it.
His all-time fave song: "Dancing with tears in my eyes"
Another had his ex's number as a random seed.
I feel personally attacked as a developer. Great video. Liked!
An eye-opener right when I needed it.
Probably one of my favourite videos on RUclips 😄
funny cause that's what you typically get on open source github repos
I think at the end you should delete the pointer. ;-)
Bah Avon! Why bother deleting pointers?? Computers have loads of memory these days! ;-) C++ garbage collects doesn't it? Yeah, I think it does because modern languages do that these days. Anyway this code will be someone else's problem next week, I'm sure they'll remember to fix it because I'll leave a comment somewhere, and when I update the repo, I'll add the message "needs a fix". Job done! Syntax check passed, ship it!
@@Ultr4noob should have been unique_ptr
And alloc memory for `shapes` array.
oh, my bad, it's ok.
I love how toward the end he kind of started looking like Gilfoyle from Silicon Valley. great video
i honnestly just love this guy. My man your simply amazing no other words. LOVE FROM THE UK
I've been working on a coding project the last few days, and no joke, last night I looked at it and went "jesus, why've I plastered so many comments on this?" and tidied it up. I was then really anxious that it was hard to understand, but I left it as is. This video gave me the confidence to leave it as is
Hey man, I need to over-comment because I will forget within 20 seconds of writing it.
Over-commenting is still less bad than under-commenting buggy code that doesn't use descriptive variable names.
As all of my code is for me I tend to over comment. It could be a very long time between coding sessions for me so knowing exactly what the code is, how it works, and why it's there in extreme detail helps me.
@@DukeDudeston Yep. I just had to use one (a bit more complicated) script that I wrote three years ago and I found a bug from it. Thanks to my over commenting I was able to instantly figure out what was wrong.
My experience is that erring on the side of over-comment is always better. You will thank yourself 6 months later. Skipping comment is fast, but figuring out what 1000 lines does isn't. In the worst case, you will think hundreds of lines are redundent, but only to find out they fixed a bug after they are deleted.
I haven't seen your code so I don't want to judge too quickly, but maybe your variable and function names aren't clear enough? Maybe you don't split your code into enough separate functions, something like that?
You have NO IDEA how some profs stress on useless functions u ll use once in a lifetime here in uni...
I think maybe this is why I retired.
Love everything about this. And the taste in music most of all.
"Sometimes I have to work with other people's code!", A death sentence, truly
Hold on, you forgot to:
1. Have a design review - so we'll be able to demonstrate how smart we are, and make you code something that nobody would want to touch, including you.
2. Open an epic + tasks + sub tasks in jira and keep changing the statuses as you "progress" with the feature.
3. Let us do a code review before you push, so we can demonstrate how smart we are (again) and make you rewrite your code over and over again. At least for two and a half years... the time it took google to recommend this video to me.
The short term for these three things is called "job security".
If someone asked me to write it like that I'd be like "Yeah F*** that!". Probably the most important rule of programming, keep it simple stupid :D.
C'mon now, be honest... have you never been "that guy"? Hated on by your peers, because they considered themselves "leet", and above all reproach... just because you hadn't mastered, some arbitrary method/skill that, "duh, everybody should know"?
this video perfectly describes what my uni expected of me. one of the first bigger projects i've ever written were about 600 lines of code, 300 lines of comments and i didn't pass the first time it was tested because I DID NOT COMMENT ENOUGH so after i was done with what was done in this video i had 600 lines of code and 750 lines of comments and then i passed the course. i didnt change the code or anything and trust me, it wasnt overcomplicated since as a student i didnt have much idea about how to make it this complicated in the first place... though the "flaw" i had was that i didnt use enough libraries and wrote too much code they said
not that I wasn't already laughing, but when you pasted the licence, I cracked up! so true, all of it. And I must admit that I over comented in the past. A clever boss will say It was prior to leave a project :D. Love your content!
Out of curiousity, do you work on any libraries that other developers may use? Not talking about the sample/utility stuff I've seen you upload to Github. I can definitely say I've been guilty of actually over-engineering, spending days thinking and researching the "fastest/best" solution to something that isn't even clearly needing it yet. On the flip-side, I've worked with FAR FAR FAR more under-engineered garbage, unmaintainable code, than over-engineered code. In a professional setting, I'd much prefer to work with the over-engineered code. I know that I've considered code "over engineered" in the past, only to then find out it was my own knowledge gap that made me feel that way. Sometimes we think someone is being fancy, when its simply that they are doing something we just don't understand. Put it this way, as someone who's been programming professionally for almost 20 years, I've never complained that someone overdid something. But at almost every job/client, I've wanted to quit because I've inherited a pile of "lets just get this working" code, that hardly anybody gets paid to go back and cleanup/fix later.
This times a million.
Cannot agree more with you. While over-engineered code might not be optimal, it's still acceptable. Under-engineered "lazy" code is just unusable garbage.
It kinda depends. If you work on code that is only to be used for one use case in one program (and not a library or something), then making it as simple as possible is much better than using 1000's of unnecessary design patterns and whatnot, because, in the end, we spend much more time reading and trying to understand some code than actually writing it. It makes sense to try and minimize the amount of time it takes to understand something at the possible cost of having to refactor it slightly in the future.
Plus, if a piece of code can only do the one thing it is actually supposed to do, it is much easier to understand what it is actually used for in the program. (E.g. if it only works with doubles and doesn't use templates, then we know that it's never being used to work with integers.)
If you're working on a library then make sure it looks the way you'd expect a library to look like (with proper documentation and all), because, well, that's what it is. You can no longer speak of "over-engineering" when the problem you're trying to solve expects you to do what you are doing.
@@ThePC007 The number of times I've heard someone say: "just going to get this out the door, so I don't care about design", only to then eat those words 6-12 months later is astounding. I've trained many junior developers over the years that consistently do this, and they end up having to get paid to rewrite/refactor trash code down the line. Its very rare for projects to just be "sample" code. Most people write code that they need to maintain long term, either for personal projects, or far more likely, for professional work. Your boss will NOT want to pay you to rewrite or perform major refactors on code you've already been paid to write. If you're ok with going back to a messy pile of code 6 months later to spend hours (on your own dime) figuring it out and refactoring it, feel free to waste your time. The only people who don't care about the quality are people who don't expect other to have to look at their code, which is almost always a mistake.
"Plus, if a piece of code can only do the one thing it is actually supposed to do, it is much easier to understand what it is actually used for in the program." Why are you assuming it actually does what it needs to do properly, and is easier to understand? Those two almost always fall flat if that code isn't well put together. That's exactly why people talk about design and maintainability together. You can't even test your code properly in cases like that. Also, don't assume that design means using 1000 design patterns, that is not a real argument, nobody said to overuse design patterns. Design patterns have their place, and may or may not be needed right off the bat.
All this being said, its very fair to just write code without worrying about anything if you're trying to get an algorithm working or create some proof of concept. The issue is that people subscribe to this "meh, whatever" mentality and end up pushing code like that much further into a project because they refuse to actually clean it up/design it early on. That is what I take issue with, because it happens all the time. As a consultant I'm constantly picking up code from other developers who had this shit mentality and sometimes drives me nuts.
@@NickEnchev You've probably misunderstood my comment in the most epic way possible.
When I was talking about making the code "as simple as possible", I have actually meant just that, to make the code simple. I have no idea how that is supposed to mean that the code is supposed to be messy, which is the exact opposite of that I said.
My comment was literally about making the code simple and therefore easier to maintain, and you are pretending that I said the opposite. I don't get it.
- Documentation should be in Doxygen !
- M_PI !!
- RUclips comments can't be formatted in markdown !!!?
Love it :-) BTW you forgot to implement RTTI hehe
David: "Getter and setters for every single field!"
Every ORM in the world: *sweating*
I like your setup. Small, compact, distraction free.
This is what people do on Stack Overflow and programming forums when they call themselves trying to help someone. LoL
*One year later* Wtf did I wrote here ??, Where do I initialize this variable ?, How this function cannot be called by the others ?
Soooo mee
What's SEG_FAULT?
If you don't over-engineer, I can always find that little missing detail to put down your work. If you do everyrthing "right" I can still say "overkill". You lose... FATALITY.
i realy love your video's and this video show a very importen point maney developers do wrong, as you say "don't over-engineer your code" i see many new developers do this, and my expriens tell me, its coming with many years of developering after you have done a lots of mistakes, i really hope your video help a lots out there, i really love you videos :)
I think I’ve watched this video 1~2 years ago, but I realized I was over-engineering my code just few months ago.
Since then, I am doing this now: No matter what it will become, write it in the simplest way possible first.