Clean Coders Hate What Happens to Your Code When You Use These Enterprise Programming Tricks

  Переглядів 913,122

NDC Conferences

NDC Conferences

День тому

Kevlin Henney
It is all to easy to dismiss problematic codebases on some nebulous idea of bad practice or bad programmers. Poor code, however, is rarely arbitrary and random in its structure or formulation.
Systems of code, well or poorly structured, emerge from systems of practice, whether effective or ineffective. To improve code quality, it makes more sense to pick apart the specific practices and see their interplay - the cause - than to simply focus on the code itself - the effect. This talk looks at how a handful of coding habits, design practices and assumptions can systematically balloon code and compound its accidental complexity.
NDC Conferences
ndc-london.com
ndcconferences.com

КОМЕНТАРІ: 1 700
@DoubleBob
@DoubleBob 6 років тому
Protip for beginners: If your supervisor has created this legacy code and you make it into something good, prepare for passive aggressive backlash.
@pdorism
@pdorism 6 років тому
FernestHall actually my boss let me rewrite the whole thing from scratch. To be fair we're not programmers.
@rmrbush
@rmrbush 6 років тому
If you're a "beginner" you might want to take the time to understand the code before making any decisions. It's not just learning the code either. When you come into a new organization, it's also learning the business rules, the culture, and software road map.
@monad_tcp
@monad_tcp 4 роки тому
I was a supervisor programmer and was like: please rewrite the crap I wrote 7 years ago
@ITech2005
@ITech2005 4 роки тому
@@rmrbush Bingo. There's usually a reason for strange code being where it is. As a newcommer to the project, even as an experienced developer, you don't know the intent or situation that led to them putting it there. It could've been a work around for some weird and obscure bug that will bite you squarely in the arse. And of course the guy that wrote it is no longer around the explain the why.
@loam
@loam 4 роки тому
It depends. I have exactly that situation you described, but not because I turned legacy code into something good, it's because my lead's special features. He is previously country boy who worked remotely, then moved into city (Moscow) to work where I have occasion to work nowadays, because he had already too much made for that company and they couldn't get rid of him. I, as a middle developer, have much better potential, I speak English, I speak Russian without silly mistakes he make, etc, I learn fast, so I see now he envies me, and the strange passive aggressive moves he make (like country boy's trickery, which he probably thinks are smart tricks, but to me fairly obvious) are clear to me. At my previous job I had exactly opposite situation: less money, bad attitude from HR, but awesome colleagues and lead, and now, by contrast, I see how much awesome they were. For instance, Ivan, the guy who sat right in front of me, was really really good man, pure gold. He taught me a lot, he never been angry while explaining something to be, like a real good teacher; he always was glad to my success. And furthermore, he liked my pronunciation and when I kindly pointed out some mistakes he made in pronunciation of English words, he always understood that I wasn't trying to offend him, he gladly would take it into account and even pronounce the word or whatever it was that I mentioned several times in order to learn, to become better. Not to mention that he spoke Russian language clearly and there was no need for me to correct him, actually he also had that interests in languages that I have. Overall, really really good man, and I miss him. The guy like him is something rare, as I see now...
@ekszentrik
@ekszentrik 3 роки тому
"Stop trying to communicate and just communicate" is actually career-changing advice.
@cheaterman49
@cheaterman49 3 роки тому
Agreed!
@mfaizsyahmi
@mfaizsyahmi 2 роки тому
try not. do, or do not. there is no try.
@wontcreep
@wontcreep 2 роки тому
@@mfaizsyahmi you need to try in order to catch
@winmine0327
@winmine0327 2 роки тому
Advice the speaker should take. I kept waiting for him to finish his thoughts.
@dorklymorkly3290
@dorklymorkly3290 2 роки тому
"Stop trying to communicate and just communicate" means little out of context.
@NotMarkKnopfler
@NotMarkKnopfler Рік тому
Sometimes code isn't re-written because it's "bad". It gets re-written because somebody has a different opinion on what "good" and "bad" code is. You don't necessarily end up with "better" code. You end up with different code. Rewrite culture is definitely a thing.
@davidphillips7435
@davidphillips7435 Рік тому
I call this refactorbating. You do it to pleasure yourself and when it's all done nothing has been accomplished.
@formes2388
@formes2388 10 місяців тому
@@davidphillips7435 Actually - refactoring code, can be a good way to actually parse through the code and come to fully understand it. Better to be done on small bunches of code. And while yes, it takes awhile, consumes time, it is also an opertunity to understand. Refactoring code is also a good way to go through code that lacks good commenting and documentation, and create that documentation as you go - so that it's easier to understand going forward. So while doing it for the sake of refactoring the code is pointless - there are reasons to do it, and benefits to be had by doing it.
@QuantenMagier
@QuantenMagier 8 місяців тому
True and the worst part of this is the build system. Instead of using and improving the existing Autotools or CMake, every programming language and IDE started coding its own make system.. I remember a git repository with a fine Autotool build system, but some library was outdated and then someone submitted a merge request for a different build system that fixed nothing but his ego.
@homelessrobot
@homelessrobot 8 місяців тому
@@formes2388 unfortunately, it destroys everyone elses existing understanding of the code in the process if your refactoring goes into a shared space. And especially if there is consistent refactoring going on in that space. I am not really in disagreement with what you are saying, because you do address this with 'better to be done on small bunches of code'. I am just pointing out that the reason this is a good idea is because of a large negative consequence of refactoring. Several actually. So if you don't limit refactorings to a narrow scope, bad things happen.
@luckerooni1153
@luckerooni1153 6 місяців тому
@@formes2388 The one thing I hate the most about development and programming is no one can just accept that something is just not the right thing to do or is the right thing to do. Everything is so convoluted and everyone's ego is so massive they cannot accept defeat on even the smallest things. Changing other people's code just because you feel like it's wrong is just not beneficial in a team environment. You seem like you're trying to play with it in a personal environment. Neither you or OP are stating proper context so there is no right or wrong answer, but generally speaking, refactoring "just because" is just playing around at best and making people's work harder and more confusing at worst.
@ruixue6955
@ruixue6955 4 роки тому
7:50 bad code example 9:18 problem: 14:00 fizz buzz basic code 19:52 table lookup way 20:22 problem: havent got rid of the second check 21:05 answer in JS version 22:45 Cargo cult programming 32:33 is too many imports in your code a bad thing 33:38 avoid long imports by using wildcard 38:30 another aspect of Cargo cult programming 45:04 46:37 ConfigurationManager 47:43 Configuration is way better 47:48 ConditionChecker 48:40 Condition is way better
@kevinwilson1218
@kevinwilson1218 4 роки тому
Dont know if this existed when this talk was given but padStart would handle this initial bad code example
@herp_derpingson
@herp_derpingson 4 роки тому
The indentations are making me so uncomfortable
@youssef2366
@youssef2366 4 роки тому
@@herp_derpingson i like them
@nicholascarson5509
@nicholascarson5509 4 роки тому
@@youssef2366 found the python guy
@youssef2366
@youssef2366 3 роки тому
@@nicholascarson5509 I actually do use python lmao
@another-person-on-youtube
@another-person-on-youtube 3 роки тому
"There's a lot of developers who can't program." True. There's a lot of programmers who can't develop, too.
@ravens01
@ravens01 3 роки тому
Very true, two different skills, both necessary.
@charlestaylor9424
@charlestaylor9424 2 роки тому
I've met the odd programmer that can't program.
@charlestaylor9424
@charlestaylor9424 2 роки тому
Sadly the last time I met her she was teaching programming in a college.
@sukhmandersingh4306
@sukhmandersingh4306 2 роки тому
@@charlestaylor9424 you've met my teachers
@josephvictory9536
@josephvictory9536 Рік тому
sad programmer noises.
@bryanbisimotopinas345
@bryanbisimotopinas345 Рік тому
11:09 "Sometimes when you approach the problem from the wrong angle, you can really make it something of it" is so relatable.
@KallieExperiments
@KallieExperiments 3 роки тому
"All roads lead to stackoverflow". Yup
@kornbread5359
@kornbread5359 3 роки тому
LOL
@Joe11Blue
@Joe11Blue 3 роки тому
That's what virtualization and load balancing are for.
@independent4626
@independent4626 3 роки тому
😀
@Newtube_Channel
@Newtube_Channel 3 роки тому
No. SO encourages you to ask very specific questions. Perhaps that's in of itself is a lesson to be learnt.
@vinzer72frie
@vinzer72frie 3 роки тому
Not really that meme doesn't make sense most answers are either outdated or plain wrong
@MrHatoi
@MrHatoi 4 роки тому
Wildcard imports in Java would be nice if they didn't cram so much into every single package. Seriously, it feels like they just use the java.util package as a dumping ground for anything they didn't already have a package for; it holds pretty much every data structure in the entire language plus a few other arbitrary features like Currency and Date that have pretty much nothing to do with anything else. The other major issue is that wildcard imports erase the data of where each class you're using actually came from. This isn't an issue with the standard library, but it can get pretty bad with large codebases importing code from other packages in the same codebase. Without IDE indexing features it's basically impossible to figure out where any class in a file with wildcard imports came from, which isn't very nice generally.
@beeble2003
@beeble2003 2 роки тому
But that (navigating a large code base) is exactly what the IDE _is_ for!
@4rk
@4rk 2 роки тому
I was told that for a large code base with continuous integration, the savings in compile time of not using wildcard imports adds up quickly enough. Additionally accidentally adding a name that collides in some oft used package break compilation of some projects' wild card imports and requires broad scale manual fixes particularly in a monorepo.
@beeble2003
@beeble2003 2 роки тому
@@4rk Does it have any significant effect on compile time? Has anybody actually measured that? "import" is just a namespace thing -- it doesn't cause any extra compilation. I can imagine a tiny cost from the compiler having to check each package when a class is used, but that should be insignificant against the other things the compiler has to do, and a class that's importing many packages is probably trying to do too much anyway.
@trejkaz
@trejkaz 2 роки тому
I sort of have the same issue. It's relatively easy to spot someone importing a StringUtils class from the wrong package if you're not using wildcard imports. If you use wildcard imports, and I have to read your code, you are making me manually search through all the packages you import for every class you use, to figure out which ones come from which. Because I'm not fond of doing that, I find it's far easier to ban wildcard imports.
@4rk
@4rk 2 роки тому
@@beeble2003 it's been measured, but the document I saw measurements in is no longer accessible to me. To be fair Google had a unique project structure, build tool, distributed complier cluster, cached intermediary objects, deterministic binary output, source mono repo so large that most of it was network mounted with only a few of the subdirectories you're working on actually locally available and a file system in user space helping to map things for the ide. So ymmv.
@Technomancr
@Technomancr 2 роки тому
I disagree with the point on imports. The only time I ever look at imports is when I'm reading someone else's code, and in that case I want to know exactly what package a specific class is in. Using * imports would mean I have to guess which package it's coming from, or I would have to have the project loaded in a tool that can calculate dependencies for me.
@nullid1492
@nullid1492 8 місяців тому
My IDE shows alloc::collections::vec_deque if I hover over VecDeque so I know what package it is from without having to scroll to the top of the file and look through the imports.
@SomethingPuffin
@SomethingPuffin 8 місяців тому
Additionally in other languages, like for example Python, it is considered bad practice to just wildcard import everything
@Thatoneguy-o7805
@Thatoneguy-o7805 8 місяців тому
​@@SomethingPuffinbut that's exactly Kevin's point. WHY is it considered bad practice?
@nelsyeung
@nelsyeung 8 місяців тому
@@Thatoneguy-o7805 I don't know about other languages, but it's bad practice in Python because of its dynamic type nature. When there are name collisions, you literally won't know until runtime, unless the libraries you used have proper type hints and you use mypy before you run your program. E.g., if a library has `def foo(a): return a + "b"` where `a` is supposed to be a string, and another library has `def foo(a): return a + 1`, where `a` is supposed to be a `float`, then only at runtime, you'll get an exception. Even worse, if the latter library has `def foo(a): return int(a) + 1`, then your code runs fine and just gets the wrong result, which will likely be well hidden in real production code. Also, Python has a module system where you just do `import foo; foo.bar()`, so you know whatever function you are calling is from whichever library. This makes your code clear where each function is from, so you shouldn't be importing everything and making everything ambiguous. Because of this, devs are even encouraged to use the same name for functions in different libraries so it's consistent (e.g., `dump` and `load` are functions from many standard and third-party libraries), so collisions are likely to happen.
@anthonychurch1567
@anthonychurch1567 6 місяців тому
@@Thatoneguy-o7805 As he said if you have multiple packages imported and you use wildcard someone else can't tell what comes from where without going through the docs for everything imported to find it.
@cmbasnett
@cmbasnett 6 років тому
I worked at a company with a guy who committed almost every enterprise programming sin mentioned in this. He was absolutely obsessed with making wrappers and abstracting the most basic functionality into monolithic classes. If I every asked him why he was doing it, he would tell me that it is "good design".
@santiagomainetti9179
@santiagomainetti9179 4 роки тому
I've experienced these response to similar situations: "It's best practices", "SOP" and "I have 30 years of experience"
@milanstevic8424
@milanstevic8424 3 роки тому
that's not a problem. the real problem is that such people work really hard to embed themselves in the social hierarchies of such companies. I had more than one boss that was like this, coercing me to comply with the "standards". I had to quit the job every time.
@ClokworkGremlin
@ClokworkGremlin 3 роки тому
I worked at a company fresh out of my programming degree and the entire management and senior developer population were in love with a lot of these sins. I'm really glad I went rogue about 8 years ago and started doing whatever I wanted. A lot of it turned out to be exactly what he does here.
@milanstevic8424
@milanstevic8424 3 роки тому
@@ClokworkGremlin I am sincerely happy for you, because people mostly don't have a relevant point of comparison, when they get to work for a huge company fresh from the studies. They quickly learn to instead adapt semipolitically and carve their own economic and existential way through it, while the code and software engineering is literally a necessary evil used as a social trading commodity, something that becomes less and less important as the time goes by. In the end, that picture is the state of the world we live in, anything we do isn't actually the first order priority, and there is almost no responsibility involved (unless it ends up being a disaster, then a lynch mentality goes off), and this has become painfully apparent.
@godDIEmanLIVE
@godDIEmanLIVE 3 роки тому
​@@santiagomainetti9179 Means: I learned to write shitty code 30 years ago and I refused to learn anything since then. It's a shame and it really is the completely wrong mindset for this craft.
@Machtyn
@Machtyn 3 роки тому
Speaking of code commenting. In school, high school or college, it seems in the beginner programmer courses the teachers are quite adamant about adding comments. In high school, they just don't add comments and so the teacher pounds it into their head to document every line. In college, the comments may be sparse among the spaghetti code that gets turned in. The professor comes back with "add more comments," and docks points. I had dev experience when entering the beginner Java class at university and, of course, commented the necessary lines and it was a nice bit of code. The student aid came back with "add more comments." Oooh, boy... did they ask for it then!
@NovemberOrWhatever
@NovemberOrWhatever 2 роки тому
I've had that happen to me as well. Not coupled with them saying they didn't understand it, they just didn't feel like there were enough comments. It's 25 lines of code where large parts of the assignment involve print statements. I used reasonable variable names. That doesn't need comments
@webentwicklungmitrobinspan6935
@webentwicklungmitrobinspan6935 2 роки тому
dont get discouraged, i worked on clean code projects without comments other then very niche details and it worked well. i never had a issue of understanding the software written
@Sahuagin
@Sahuagin 2 роки тому
yes, in university they don't want to read your code they want to read your comments.
@judithflow3131
@judithflow3131 2 роки тому
Exactly the same here, once got the requirement to add more comments, when I already had a lead in comment on every single function defining input, output, explaining train of thought and including edits *and* kept every function between 3 and 15 single statement lines of code (since I hate combining several actions into one long 3,000 character line of code). So they eventually found quite a few Playboys worth of ASCII art in there. The other thing I hated when reviewing code, was how some people turned everything into a function, nesting functions within functions within functions, to eventually end up with a function like TestIsHigher(a,b) {return (a>b)} when this outcome was something required several layers up in the hierarchy. At that point, it's no longer programming, but it's unnecessarily renaming of standard functionality of the programming language. Oh, and the function right above the one I mentioned in hierarchy was called something like DoTest(gTestType, a, b, c, d, e) which then split up to all these little single line functions depending on what globally defined type of test was required. And yes, there were some 60 global constants defined somewhere for each type of function, and yes, calling DoTest did require including arguments which might not be used or even be available by the calling function.
@thomasmaughan4798
@thomasmaughan4798 2 роки тому
I learned old school programming -- structured, indented, commented. Can you remember YOUR OWN ALGORITHM six months later? Never mind maintaining someone else's program. So in college it took me longer to complete a programming assignment because my homework was nicely structured and commented. The professor, who unfortunately was also the dean of the computer science department, said, "What did you do all that for?" and I was speechless; "What, everyone else is NOT?" EDIT/Add: I program mostly in "C" and used to do rather a lot of assembly language programming where the task is NOT obvious by inspection. Even in "C" the task may not be obvious and the example Javascript is very much non-obvious such as where did pad.method(x) come from? Well, probably because "String" is a class with methods and pad = String implicitily adds a whole library of non-obvious functions (methods) to what you thought was a simple string variable, "pad". I am reminded of Gary Larson's cartoon, "a miracle happens here".
@Jcarr250
@Jcarr250 6 років тому
"It's a stringly typed system"
@ishdx9374
@ishdx9374 3 роки тому
so, bash?
@charlestaylor9424
@charlestaylor9424 Рік тому
@@ishdx9374 snobol
@gaunterodimm3569
@gaunterodimm3569 3 роки тому
I love how almost each and every video in this channel is simultaneously educating and entertaining!
@bigcheesetaste
@bigcheesetaste 4 роки тому
Frankly, if your code has too many imports, the issue isn't that you should be using wildcards. It's that your class is doing too much all by itself. Half the reason it's recommended that you import everything explicitly is exactly so that you can identify it as a code smell.
@GuyPaddock
@GuyPaddock 7 місяців тому
This, exactly. IMO He should have just said to stop folding imports but not suggested using wildcards, because both folding and wildcards hide the real problem. Java is also rare in that it even supports wildcard imports. Header-based languages like C and C++ absolutely require being specific about what you're importing (unless your headers have multiple types defined per header, which is another code smell). Even JavaScript -- the language he uses for a lot of his examples -- requires explicit type imports.
@fenxis
@fenxis 7 місяців тому
Too many imports? Yes... let's wildcard it to import even more🎉/s There a reason wildcard imports go against many style guides.
@streettrialsandstuff
@streettrialsandstuff 7 місяців тому
Using FQN imports are good practice BECAUSE if you need to replace some class with a class with the same name but in a different package you can perform find and replace. This really happens in the Android world, for example when we had to use backward compatible DateTime API, and once enough Android devices with a newer version were on the market we could drop older device support and use native DateTime apis. There were other cases when we needed to find and replace all usages by FQN.
@kaelon9170
@kaelon9170 6 місяців тому
@@fenxistbf changing a bunch of imports to a wildcard import does NOT mean more classes are imported in the end-result. On compilation, the Java Compiler figures out exactly which classes you are and aren't using and only compiles the bits that are needed to run the program into the executable assembly. With that knowledge, I'd say that importing specific classes over a wildcard import achieves nothing of value and only adds noise to the code.
@traister101
@traister101 6 місяців тому
​@@GuyPaddockThe thing with header based languages is you _also_ get the headers imports which is hard to notice unless you memorize/look at the entire include tree
@Lttlemoi
@Lttlemoi 3 роки тому
Having only started with Objective-C(++) less than a year ago, I lost count how many times I wanted to look up and strangle the person who came up with that language's naming convention. *"Nonono. Having a function **_doThing(ArgType):arg_** and another function **_doThing2(ArgType):arg (Arg2Type):arg2_** is **_bad._** You should call these functions **_startThingDoerWithArgument(ArgType):arg_** and **_startThingDoerWithArgument(ArgType):arg andSecondArgument(Arg2Type):arg2_** "* - some daft maniac who really likes poetry, I suppose. The only reason why we stuck to this style for our iOS code is because other iOS developers expect this style. Repetition does indeed increase truthfulness. No wonder people have huge full HD or 4k monitors these days. It's in an attempt to fit method calls on one line.
@monstertrucks9357
@monstertrucks9357 4 роки тому
22:14 " _...and we've reduced it to its essence, and we can wander around feeling mathematical, functional, and remarkably cool, and also very certain of our jobs. So there's this other side to Enterprise Programming that we see in a number of cases, and again I want to refer to this point as being Art: It's clearly a unique result of a unique temperament..._ "
@lennysmileyface
@lennysmileyface 4 роки тому
I like seeing: /* * The id of the object. */ private int id;
@JesseLH88
@JesseLH88 4 роки тому
//My reply to you String theReplyToYourCommentString = "Yup."
@HrHaakon
@HrHaakon 4 роки тому
That is literally banned in our codebase. You're not allowed to do that. Straight to jail.
@__gig__
@__gig__ 4 роки тому
my old university was guilty of this. the automatic code-grading system required students to have javadoc-like comments for every single field in a class -- you'd lose "style" points if you forgot them -- so there were lots of lines of code exactly like your original comment.
@gnack420
@gnack420 4 роки тому
That's not a comment, technically, even though it is treated as such by the compiler. It's more akin to a decorator or an annotation. It has an actual purpose which is that it is read by docs-generating software (and IDEs). It's definitely "pointless" for the person reading the code, but it's going to be there for consistency so that you get docs for every field instead of just arbitrary ones.
@HrHaakon
@HrHaakon 4 роки тому
​@@gnack420 Depends on language. Maybe some C preprocessor does it? IDK. In Java you have /** This is a javadoc comment */ and in C# it's /// for documentation comments, IIRC. Why you'd not have some way to tell your tools which comments to care about I have no idea.
@BryonLape
@BryonLape 7 років тому
"We don't touch the sacred defaults." I must really be a heathen as that's usually the first thing I change.
@AndrewErwin73
@AndrewErwin73 6 років тому
You are a heathen... but progress requires heathens!
@Trezker
@Trezker 6 років тому
Those darn defaults are always wrong.
@landonpowell6296
@landonpowell6296 6 років тому
If you have to change your IDE's defaults, use a real text editor and tmux/screen.
@markuslachinger
@markuslachinger 6 років тому
You mean use a real text editor with a real tiling window manager, right?
@landonpowell6296
@landonpowell6296 6 років тому
+Mihail Malo Sway is pretty cool. I wish Xmonad would run in Wayland. +Markus Lachinger Nope. Sometimes I don't have the time to install Xorg, which is basically only useful for running a web browser.
@jeromej.1992
@jeromej.1992 4 роки тому
The problem is often not so much the variable name but because your code does too many things so you have difficulties finding simple names, and often, I feel, it indicates much required refactoring / decomplexification instead of renaming. Renaming can't help you there.
@RyanLynch1
@RyanLynch1 Рік тому
agreed
@jeromej.1992
@jeromej.1992 Рік тому
@Harshil Pandey Many. There are a few ways/tricks to achieve cleaner code. Try to separate your input, the logic and consequences (the persistence). This helps your code being more readable, more plug-and-play, more easily testable,...
@TehPerz
@TehPerz Рік тому
Local variable shadowing lets you reuse names of variables you no longer need rather than try to make up new names that mean the same thing. Too bad a lot of languages don't support it.
@nosirrahx
@nosirrahx 3 роки тому
I watch a lot of these lectures and I always take the same thing away: Damn, I am glad that I am retired and code fun little projects for myself.
@malusmundus-9605
@malusmundus-9605 3 роки тому
I code only for myself and I think EXACTLY this
@edgeeffect
@edgeeffect 3 роки тому
For work, I write Enterprise-grade GUK! For my hobby projects, I use assembler with less than 1K of RAM... It feels like taking the thumbscrews off.
@grapy83
@grapy83 2 роки тому
Damn! I envy you sir... Good Job and happy living.
@robwillett4960
@robwillett4960 2 роки тому
Me too lol
@matthewsheeran
@matthewsheeran 2 роки тому
Nothing beats your own single developer projects with consistent conventions across the codebase booyeah!
@xcoder1122
@xcoder1122 2 роки тому
1:01:12 Actually C once required you to make all declaration on top of a function. Not sure at which version of C that changed but as many people like to write C code that can be compiled with oldest compiler the world still uses, even long after that has been changed a lot of code was written that way and of course other programmers copied that style. Also very early compilers did not reuse stack space and by having all declarations on top it was immediately possible to see how much stack space a function requires (already), which was important in very limited environments, especially if you planned on calling it recursively.
@mettaursp309
@mettaursp309 2 роки тому
I believe C89/90 required it, while C99 didn't. Must have been either C95 or C99 that changed that. I definitely remember that restriction from uni projects, and I vaguely remember seeing that some of the messes like that were cleaned up in C99 code elsewhere. I can't say what version really changed it for sure between the two though because I quickly moved on to C++ after learning C89/90.
@samyvilar
@samyvilar 2 роки тому
I think it’s C99 since that was the biggest update to the core language, as to why declarations had to be made up front, it becomes quite obvious when implementing a C compiler, since declarations may modify the stack specially within compound statements, and goto statements allow you jump anywhere w/i a function, a naive/simple implementation of goto can very easily corrupt the stack, should the 2 be intermingled, hence for the sake of simplicity initially all declarations where made up front modifying the stack before hitting anything else, greatly simplifying things, with C99 you have to take great care to make sure the stack is in the “expected” state when dealing with goto, it goes without saying implementing goto “correctly” or at the very least “safely” is an epic pain in ass … some C99 compilers “cheat” by copying all declarations even those w/i nested compound statements to the start of the function, while replacing their original instances with initialization code, on one hand you only need to modify the stack twice, once at entry and again at exit, while also simplifying goto, o.t.h. this could use far more memory since out of scope storage can’t be reused until the function exits, thankfully most modern C compilers aren’t that inefficient …
@MenachemASalomon
@MenachemASalomon 2 роки тому
In C (and in C++), the compiler needed to know how much space to allocate for local variables (on the stack) when entering a function (or scope). Requiring a programmer to define all variables was therefore reasonable, as there were no side effects. But in C++, defining a variable can have a side effect (such as calling a constructor), and the programmer needs the flexibility to control when that happens. So, despite efforts in allowing C++ to be implemented by a single-pass compiler (which is not possible for C), C++ had to allow local variables to be defined at the point of usage, and the compiler will have to backtrack a bit to fix the stack size. With C/C++ compilers on the market (that is, a single compiler system that could do both), allowing C programmers the same flexibility was simple enough, so it became a common non-standard extension, available (I think) on both the GNU and the Microsoft compilers by the early '90s. C99 merely standardized the behavior that was by then ubiquitous, as it did several other features that migrated from C++, such as single-line comments. (Function prototypes had been migrated to C from C++ by K&R2 in `86, which became ANSI C and then C89.)
@therealax6
@therealax6 2 роки тому
@@samyvilar I should probably point out that C11 was an even bigger update than C99. (And C23 promises to be even bigger. I'm looking forwards to it.)
@RARufus
@RARufus 2 роки тому
We run software that about 80% of the companies users rely on every day. When designing an API, I mentioned to the enterprise architecture team it was an enterprise document API. They asked if it accounted for all documents for all systems…I said no, just our teams system which accounted for 99% of all documents in the company by volume. He remarked that it wasn’t an enterprise API then and it was an application API. I said “sure” and moved onto the next thing in he meeting.
@robwillett4960
@robwillett4960 2 роки тому
I loved this talk. I retired last year (2021) but have seen this kind of stuff throughout my entire career in one form or another. Management don't understand any of this and people get promoted to positions where these practices are imposed on people below them in the hierarchy. Glad I'm out of it. Well done Kevlin.
@BangkokBubonaglia
@BangkokBubonaglia 2 роки тому
Re: object oriented naming around the 40 minute mark. This guy has obviously never written a patent application in his life. Coming up with the most general description for a means of doing something has been refined by the legal profession into an art form. Once you start working with patent attorneys on your inventions (method patents are legal in the USA), you will never, ever again call a door a "door". Anyone worth his salary will automatically start referring to it as a "Selective Passage Or Inhibition Means". And management will reward you handsomely for this, because it shows you are thinking outside of the box and into the future. 17 years later, when your code is being used in a trial between 2 multinationals who acquired your small company (in a deal which made millions for the management), the fact that you never once said the word "door" will mean that one trillion dollar multinational will win a multi billion dollar lawsuit against another trillion dollar multinational who tried to replace your simple door with a laser activated safety screen and patent it as a new innovation in the field.
@lucasterable
@lucasterable 2 роки тому
Other examples of import collisions: - DateUtils (apache.commons vs apache.http vs of.course.your.own) - Function (java.util vs various spring packages) - List (java.util vs hibernate) - Collection (java.util vs hibernate) - Map (java.util vs hibernate) - Optional (java.util vs bytebuddy) - StringUtils (apache.commons.lang vs apache.commons.lang3 vs of.course.your.own) - Date (java.util vs java.sql) - Assert
@tonnentonie2767
@tonnentonie2767 2 роки тому
junit vs junit.jupiter
@imadetheuniverse4fun
@imadetheuniverse4fun Рік тому
Yep, the wildcard import advice is really bad. Just import the module itself if you need a million functions from it.
@rolfs2165
@rolfs2165 Рік тому
@@imadetheuniverse4fun The most baffling thing I've seen was fellow students importing _the entirety_ of apache.whatever for String.isNullOrEmpty(). Like, for one you don't need to add several megabytes of unused imports for that, for two, that's a freaking one-liner to write yourself! I've only tutored Basic VHDL, so includes and such came later (meanwhile we had half of the class "doing their homework together" - with students from 10 years ago), but that would have been a serious "explain why you're doing this" moment for me.
@originuk
@originuk Рік тому
@@rolfs2165 Brilliant post! I agree with that so much! Students are now told to not bother re-inventing the wheel. There's already a library to do what you need, and the authors will understand the problem better than you. Right, so there's no point in understanding the problem either? Yup... That's character building. If you're going to stand on the shoulders of giants, you'd better be sure they're standing on solid foundations first.
@originuk
@originuk Рік тому
If the IDE giveth and taketh imports... the IDE should figure-outeth the correct import. If the project has now java.awt imports, it's highly likely the project needs java.util.List....
@pt8306
@pt8306 Рік тому
Singletons do have one use and one use only - when you need an object that only ever exists once, AND you need late initialisation for some reason. Otherwise you can just use a static class. I know static classes are considered "evil" these days, but there's really nothing wrong with them if you are literally, genuinely and seriously only ever going to have one. People don't like the "you call functions on the class not an instance" aspect, but that's literally the whole point.
@wmrieker
@wmrieker Рік тому
...or the class implements an interface that you have to pass to something.
@pt8306
@pt8306 Рік тому
@@wmrieker If you are at a point where you need to pass a generic interface around, a singleton isn't appropriate anyway.
@bdijkstra1982
@bdijkstra1982 8 місяців тому
@@pt8306 an empty collection could be a singleton.
@pt8306
@pt8306 8 місяців тому
@@bdijkstra1982 Nah, you're better off using a static const
@arjandikhoff5201
@arjandikhoff5201 7 місяців тому
One caveat is that static classes can cause problems in multithreaded systems.
@VAXHeadroom
@VAXHeadroom 2 роки тому
1:01:30 If you're going to distribute declarations like that you MUST provide a trigger warning first :) For embedded systems I insist on declaring variables first so that an estimate of the amount of stack the variables will require can be assessed at a glance (especially on legacy microcontroller systems with limited RAM). Feel free to disagree :)
@draconicepic4124
@draconicepic4124 2 роки тому
Or, if your still using C, it's required. It's also required if you end up doing dynamic stack allocation to prevent undefined behavior.
@VAXHeadroom
@VAXHeadroom 2 роки тому
@@draconicepic4124 Working on spacecraft I try to NEVER do dynamic memory allocation and to restrict stack data pretty hard. If we do use memory allocation it's "Allocate and hold forever" but I prefer compile-time allocation. I also do hand-written link scripts so the linker will tell me how much memory is used in the map file, but that's a whole other topic! :)
@therealax6
@therealax6 2 роки тому
@@draconicepic4124 If you're still using C89, you mean. C99 (23 years old by now!) removed that requirement. I have no idea of why people think C must mean ancient C.
@grex2595
@grex2595 8 місяців тому
Wait, so in order to make the last bit of code more readable, we factor out the part of the code that converts the strings to numbers, factor out the error logging and throwing, and finally factor out the whole function, making everything the caller's responsibility. Did you not just move every line of code you just cleaned up into a function that already has other lines of code in it, making that function less clean and more complex than the original one you're cleaning up? You mostly had me until that point, but your final clean code example is effectively, "instead of splitting code into functions, just put all the code in one function."
@redstoneprojectrules
@redstoneprojectrules 4 роки тому
Can we just all respect the eye-strain friendly slides?
@Baekstrom
@Baekstrom 3 роки тому
The C++ specs for string.data() used to state that the implementation was not required to include a null terminator, while the c_str() function did. However, as Kevlin pointed out, every implementation included the null terminator in the data, because it was the easiest way to implement the internal representation of a string, so in later versions of the specs the null terminator is now required, so the functions data() and c_str() are now identical. You can use whichever one you like, although if I was to bet on which one is going to be deprecated, if any, I would bet on data(), because it is rarely used anyway.
@hrgwea
@hrgwea 2 роки тому
I've seen the opposite; .data() is much more common than .c_str(). I, personally, always use data() because it's easier to type (and shorter).
@briannoel7398
@briannoel7398 8 місяців тому
.c_str() is non-modifiable (without const_cast), so it achieves less utility than .data()
@waytospergtherebro
@waytospergtherebro Рік тому
"Recursion is so cool it obviously belongs absolutely everywhere and should form the basis of every interview process." - A 22 Year Old CTO
@funkiekeda
@funkiekeda 6 років тому
Quite entertaining video, but the guy sure loves to talk a lot, his verbosity can easily outmatch verbosity of the code he was bashing at some point.
@monstertrucks9357
@monstertrucks9357 4 роки тому
Yes, but code verbosity is generally always a bad thing because effective code succinctly expresses its operation. Human verbosity, on the other hand, can be a good thing...
@Android480
@Android480 4 роки тому
I had to stop watching.
@casperes0912
@casperes0912 4 роки тому
national holiday It’s a very different context. This is a speech with a large part of it being meant as entertainment in addition to education. And both of those warrant extra verbosity. If jabbering on makes something more fun that’s good entertainment. If jabbering on means more people will understand what you’re trying to convey that’s good education. Code is meant to be quickly and easily understood
@prgnify
@prgnify 4 роки тому
@@casperes0912 I really wish his talk was only for education and not entertainment. It was so verbose he did a disservice to the message he wanted to give.
@prgnify
@prgnify 4 роки тому
@@casperes0912 45:30 the cards are really ironic
@SemiMono
@SemiMono 4 роки тому
In the final section, where he refactors some code... Good refactors, but deceptive. The only actual reduction in code was a few conversions from old-style to new-style, namely using managed pointers from the start and using exceptions from within the connection class rather than converting an error result into an exception. I think to fully understand the simplification of the code we ought to be able to see the changes made to the surrounding classes.
@manaquriazertyuio4555
@manaquriazertyuio4555 4 роки тому
yeah, basically half is moved to the constructor, and the other half to whatever function is calling, and we probably don't want to deal with the configuration so we write a `connect to server` that takes no parameters and fetches the address and port from the config, and we're basically more or less back at square one (though some part of the log and throw would be done in the connection)
@SemiMono
@SemiMono 4 роки тому
@@manaquriazertyuio4555 Right. I think that architecturally it was better to move those things outside of the function... PROBABLY, depending on the context it's used in. However it still seemed like he was making himself look smart... or something... while he was actually just moving things around. Depending on what actually used this method and the scope of the refactor he was undertaking, this might actually be a bad change (not everything he did, but getting rid of the method and moving the configuration access etc. out). What if that connection class he modified is part of a library? What if you have 150 different places this function is referenced that all now need to read the configuration themselves; is that really in scope of the refactor you're doing? Etc. etc.
@erkan2284
@erkan2284 3 роки тому
@@SemiMono `What if you have 150 different places...` actually his way makes better because now 150 place can use different configurations and you can test this method, and also yes refactoring 150 place is hard, so usually you don't change the original version of the method and push refactoring 1 level deeper and your original method becomes adapter between refactored and non-refactored version of your codes, when you keep refactoring everything you change it to the cleaner version and your code always works.
@zechordlord
@zechordlord 3 роки тому
@@erkan2284 [[deprecated]] attribute in modern c++ works wonders there.
@milanstevic8424
@milanstevic8424 3 роки тому
@@SemiMono you didn't quite understand the point of his 'refactoring'.
@57thorns
@57thorns 2 роки тому
Something else that is funny (that I know some IDEs will try to help you solve): If you switch from one implementation to another (say collections.List to collections.Set) your List import still remains, despite not being used. So the list always grows, unless you IDE decides to delete the line for you, in which case the next time you want a List the ide adds list from std.List, not collections.Listm which has slightly difference implementation and semantics, and vastly different performance.
@kaelon9170
@kaelon9170 6 місяців тому
Most IDEs allow you to run code cleanup (and code formatting, if desired) upon saving the file. I have this enabled so that all unused imports and local variables are removed and the code is reformatted on save. At work we also run checks for this in the build pipeline for PRs, to ensure people don't introduce unused imports or variables in the codebase.
@EmberQuill
@EmberQuill Рік тому
I've worked with several people who are guilty of "over-enterprising" their code to the point of absolute ridiculousness. I still remember when one of my colleagues took a fairly simple problem (check if a new server instance has the proper tags applied when it starts, terminate the instance and email the owner if it doesn't), and abstracted it out into this modular enterprise-ready mess that I never could quite understand. He liked to throw around the phrase "orchestration layer" so much that it lost all meaning. It grew like some kind of infection for about six months before it was quietly canceled and left unfinished due to our old boss leaving and being replaced with someone who changed around a lot of our priorities. Meanwhile, AWS had introduced their own solution for tag compliance that was fully managed and required minimal configuration. In fact, it may have already existed when our solution was still in development.
@RonJohn63
@RonJohn63 Рік тому
16:20 This reminds me of a group project (written in Turbo Pascal) that we had to do in college back in 1985. My team's code was about 60KB (and worked except for a couple of corner cases), while another team's was *three 360KB floppy disks* just to insert, modify and delete data from an inverted list.
@ME0WMERE
@ME0WMERE 8 місяців тому
sometimes abstraction and whatnot is good, but jesus, there is a limit
@CuriousCritter9
@CuriousCritter9 7 місяців тому
To be fair, the devil lies in the corner cases. They are really important, as bugs tend to show up there only after a while, when the code is well in production. It's easy to make something that works 90-99% of the time. It's hard to make something that works 100% of the time. But I guess the 15x difference in code size sounds a bit much even to handle a couple of corner cases. Personally, though, I will almost always prefer large, correct (and even slow) code over small, buggy (and even fast) code. The ideal is fast, small, and correct, but correct is always my primary goal. Make it work correctly, and then refactor to increase the speed and decrease the size if needed.
@RonJohn63
@RonJohn63 7 місяців тому
@@CuriousCritter9sure, make it work, no matter how suboptimal, but 18x larger is just Bad Design. Just as importantly, "quantity has a quality all it's own"; all that extra code is more surface area for bugs.
@programaths
@programaths 4 роки тому
27:36 Comments can be used for WHY, not how. Most languages have systems to document assumptions and even have them checked in debug builds. It's also possible to use comments for code that is not self explanatory, but written that way for performance reasons. One can't assume everyone has the knowledge. One example is the "fast square root" or even if one need to compute some terms in a series.
@programaths
@programaths 4 роки тому
Was kinda 60 minutes early with that one 🤣
@richdobbs6595
@richdobbs6595 3 роки тому
I hate using wildcard imports, since when I read my own code I can recall all of the possibilities that I might be flattening down, rather than keeping them explicit and obvious. But I never seem to have particularly long import lists. If I did, I would think that that file had too many concerns.
@TheExileFox
@TheExileFox 2 роки тому
Boost for C++ is practically a wildcard library. You can't load just what you need, you have to load the entire thing and so compiling suddenly takes forever.
@marktellez3701
@marktellez3701 Рік тому
This is exactly correct, be specific, be exact, and be descriptive and you never need a comment
@jerrykim7777
@jerrykim7777 3 роки тому
love the part after ides where he brings up the matrix. But seriously, imports are interesting to me as it lets me quickly preview all the objects that are going to be involved and this fails hard with a wildcard import. Not a problem since I can do ctrl-d on vim a couple times or /public class and I'm instantly where I want to be.
@LPFan33
@LPFan33 2 роки тому
I kind of agree. I also feel that if there are tons of imports, it smells to me that the module is doing too many things or at least has too tightly coupled dependencies. I would rather be aware of the smell and do something about it than hide it.
@DylanYoung
@DylanYoung 2 роки тому
Tells you immediately how much work it will be to remove a dependency as well.
@peceed
@peceed Рік тому
1) Import list is not a noise, it allows you to know the exact class of used types regardless of IDE. Without that your code is fragile and can stop compiling when imported packages are extended by colliding names. What we really need is the syntax like: import java.util.{List, Map, HashMap}. 2) Use f*** IDE. 3) Don't hesitate to use refactoring support in IDE to rename types and variables later. 4) Example names are trivially misleading, it is list of "cult cargo naming".
@kylewilson4097
@kylewilson4097 2 роки тому
On comments, one I encountered was a function that was written by one developer to clear out working files from a scratch folder. It only removed files and did not recurse into subfolders. He created it for that one purpose. He had no subfolders in the scratch area he used this on. A few years later he had added subfolders with other scratch data and updated the function to handle this and walk the tree deleting subfolders. In his mind this is what that function was intended to do, it just didn't need the folder walk until then and this was an enhancement. Worked perfectly until he committed it to source code control... The following morning the whole place was in an uproar. Turned out that the server developers had see this handy little function and were calling it to clear out working files at the top of the database tree and expecting that it would leave subfolders alone. Nothing in the name of the function implied that nor did they talk to the person who wrote it originally...they read the code and considered it self documenting. That morning every working data store in the company was deleted before anyone realized what had happened. These were working data and thus weren't in source code control and most weren't backed up in a usable form. This incident was my first revelation that code can only self-document its current intent and that only human readable comments and communication can get the bigger job done. If the function had contained comments noting that it was intended to remove sub-folders then at least the folks who turned it into a common library function would have had a fighting chance of avoiding disaster. As it was it took some time to recover from this mistake as this deleted test databases that had been crafted by various developers and rebuilding them was not always easy.
@Mish844
@Mish844 2 роки тому
funny that you would suggest a solution that has absolutely identical problem - writing those in english doesn't solve it if the person doesn't update intent, and practice indicates tha in a project old enough you can't outright trust the comments in the first place, cuse at some point intent and comment are a mismatch. Not to mention that no code is self documenting if you don't bother reading. You're telling us that practices in that organization were so yolo-driven-development that noone noticed a diff in function that suddenly started including going down in a tree? Sounds self documenting enough, unless the entirety of the code was obfuscated beyond recognition.
@kylewilson4097
@kylewilson4097 2 роки тому
@@Mish844 Ah but in this case I talked to the developer and he had that intent from day one...just hadn't intended anyone else to use the function. If he had included a comment (or used a fifteen word long name for the function) the intent would have been clear...instead others used úndefined' behavior of the function and got burned. It is often easier for human beings to write in words what they intend a function to do than it is to write and validate the final functionality well before it is needed., No solution is perfect but the 'self documenting code' solution is cripplingly bad as those reading the lines of code cannot ever intuit the unstated intentions of the person who is maintaining that code. People started using the function as was and then months later the original developer added the new functionality. Automated builds compiled the code and delivered it to the pipeline and then the first time they ran anything the following morning disaster ensued. It was a poorly structured development environment but i could easily see the same thing happening at Amazon Robotics (where I worked for a couple of years) and potentially nuking things...the function would have passed all of the relevant unit tests as there wouldn't have been any to verify that it didn't recurse folders. Sometimes the native language of the developer is a better and easier way to convey future intent than code that has not been written yet...
@Mish844
@Mish844 2 роки тому
@@kylewilson4097 my apologies, but did that developer obfuscate the code? If not the intent you describe is simple enough that you can find it... in the code, rendering the comment redundant. Not to mention that changing a big change in a code that is aleady used should raise a flag which leads me to the punchline that you shouldn't blame the rule of self documenting code if the issue was in bad habits. No documentation, including great code helps if peope don't read it in the first place. And someone writes in a team project code with intent that noone should or would use this code... Jfc, they should stop working in team projects. To summarize: the way you describe this case leads to the conclusion that the crippling component wasn't the self documenting code approach but (a) terribly inexperienced developers(s) or even outright horrible one(s). But fixing this issue with "wrte some (more) comments" is trying to close a wound with duct tape. Putting aside the issue that comments sometimes are necessary, just to make things clear, though not in a way you described. In some cases code can't contain the gist of method in which you try to solve an issue. Typically if you perform some hard to grasp but short in code operation, using a comment is a good idea. Explaining that you don't want to use recursive in files? Putting aside that's on you, because it's a simple case, if you feel like you MUST make it more explicit, you can write a simple unit test that mocks a file structure and returns failure when nested files have any changes. It's a lot faster than some would think and this way you'll actually avoid the problem of comments not being read by coompiler, cuse this method actually gives you some feedback if you make change not expected by author.
@kylewilson4097
@kylewilson4097 2 роки тому
@@Mish844 It was many years ago and that team wasn't great. SO your expectation is that the documentation would be supplied by the developer using the code reading the unit tests to determine what future updates to the function would do? My experience has been that unit tests get written half assed and just enough to cover the happy path (Amazon in particular did that everywhere) as proper unit tests for even simple code are 5-10 times the size of the code being tests if you're going to provide comprehensive coverage of all intetended behavior and both happy and unhappy paths. No place I've ever worked at (including life critical medical devices) has allocated time for that level of unit test.
@kylewilson4097
@kylewilson4097 2 роки тому
@@Mish844 From what I saw and remember the code was very simple, enumerate files and delete each file. I think the code to handle folders was simply missing and the test cases did not include folders as that was a future feature. He didn't advertise this code as a general piece of library code so I agree no one should have used it in their code (separate issue with this place as in plenty of other areas people reinvented the wheel many times over rather than putting common things in a library).
@jackfirth8890
@jackfirth8890 Рік тому
I'm really surprised nobody mentioned the main driving reason Java wildcard imports are a bad idea: they make it possible for libraries to break you by adding new classes! If you import foo.* and bar.* to get everything from two different libraries, and the foo library defines a Thing class, then your code will break if the bar library adds its own Thing class. Fully qualified imports eliminate this possibility. If most Java code used wildcard imports, widely used Java libraries would be unable to add new public classes because odds are they'd break *somebody.* Wildcard imports are great for reading code and for library users, but they hinder library developers. Java prioritizes library developers over library users. So your code will always look a little noisier than it needs to, but on the other hand, there's a *ton* of great libraries to use that have been around and continuously maintained since the dawn of time. (I'm a Java expert and library developer working at Google)
@TonyCoyle
@TonyCoyle Рік тому
If a library changes, you should be considering the impacts of that change ANYWAY, so your example is simply that (in update X, library Y added new func Z. Exsting func Z from A.B is therefore fully expressed). ONE line gets added to your code WHEN NEEDED. And you have another opportunity to refine and revise.
@MD-vs9ff
@MD-vs9ff Рік тому
@@TonyCoyle One line in how many different source files?
@cregkly5444
@cregkly5444 2 роки тому
Yes! I get on my soap box at work about how important names are. This is perfect and explains it better than I ever could.
@krzaq666
@krzaq666 6 років тому
As of C++11 string::data() and string::c_str() are equally good. It's also weird that the leak of a Connection object in the original code (in case of throwing an exception after it was created) wasn't touched upon.
@timseguine2
@timseguine2 6 років тому
I was also surprised he didn't mention the memory leak. Memory leaks love to hide in code like this after all.
@ShredST
@ShredST 2 роки тому
He changed it to a unique_ptr. What else did he need to do?
@MD-vs9ff
@MD-vs9ff Рік тому
@@ShredST Mention it before changing it. It is still a bug in the original code that's worth bringing up.
@gnack420
@gnack420 4 роки тому
We need to bring back 'thenceforth'
@zyansheep
@zyansheep 3 роки тому
Agreed
@ekszentrik
@ekszentrik 3 роки тому
Thenceforth it shall be used again.
@celebrim1
@celebrim1 3 роки тому
Did it ever leave?
@slipoch6635
@slipoch6635 4 роки тому
I prefer the curly braces for containing. that way i can always see exactly what is inside any area i use them in.
@NOLFLON
@NOLFLON 3 роки тому
"If you get the names right, you are communicating design" : 43:16 Leading into real code examples of "Stop trying to hit me, and hit me" (renaming methods/classes to make it clear, specific and concise) : 46:40 and 47:46
@xybersurfer
@xybersurfer 3 роки тому
probably the best talk about refactoring that i've seen. the world would be a better place with more programmers like this. it's really not so hard
@karaloop9544
@karaloop9544 Рік тому
10:05 Not a JavaScript programmer either, but as far as I know String() was added in later versions of the language, and I believe the same is true for String.repeat(). So to be applicable to even early versions of JS the code was a little bit more cluttered on purpose.
@CottidaeSEA
@CottidaeSEA 6 місяців тому
It honestly just seems like code that is supposed to be runnable on all JavaScript engines. I think the code looks just fine. My worry is rather in the fact that so many people depended on it despite having polyfill readily available, or not needing the backwards compatibility at all.
@arnerademacker
@arnerademacker 6 місяців тому
@@CottidaeSEA They depended on it because it's an insanely performant piece of code that doesn't need poly-fills or abuses the weirdness of the language in some way. It's just basic JS that runs on literally every machine and does exactly one thing incredibly well. I agree though, I think very few people needed this specific implementation. Not all projects need compatibility and not all projects need this degree of performance. And if you did, there is an argument to be made to just create your own function, following the code example that the npm package sets.
@CottidaeSEA
@CottidaeSEA 6 місяців тому
@@arnerademacker Exactly. Even if they want to have it, there's no reason they couldn't just download it and store it locally in the project, keeping all license stuff in the file, etc.
@jhoughjr1
@jhoughjr1 3 роки тому
Preaching to the choir. This expresses well so many of the difficulties Ive seen in the last decade of programming
@tony1923
@tony1923 2 роки тому
Sooo close ... I was in agreement with him until the last 2 minutes. Where he basically extracted the responsibility of checking config input values out of the function he was refactoring. He didn't refactor 30+ lines of code down to 1 line. He refactored down to 1 line + x lines in a function calling that function or single line.
@GonziHere
@GonziHere 2 роки тому
I would call it a comedic effect. I mean, even the first code was impressively bad. It did ilustrate the point quite nicely.
@TheOceanLoader
@TheOceanLoader 2 роки тому
My tip to junior devs: Study everything everywhere. You should doubt everything is anywhere better than you can make it, but be humble enough to spot good code. Tools are everything - so master your IDE and learn keyboard shortcuts - in fact - all shortcuts to make common tasks as quick as possible. Also - C# is an easy transition from Java but has different coding conventions so you need to master coding conventions for different languages as per the creator's guidelines.
@Stettafire
@Stettafire 2 роки тому
This. Though the advantage of C# is that the documentation is stellar
@mrcryptozoic817
@mrcryptozoic817 10 місяців тому
Speaking from experience in 2005: There are three reasons (at least, the best) to rewrite code: 1. Old code is running too slowly or is kludgey. 2. Old code is too difficult to update with maintenance (as for new requirements, or wrong language used initially). 3. Old code is hard to understand (like assembly language with no comments). At the very least, we haven't been limited to 8 byte names for at least 2.5 decades. Go through and make the names understandable.
@mrcryptozoic817
@mrcryptozoic817 6 місяців тому
@@jmc000 I can tell you've never had to fix assembly language code. I've rewritten a system monitor (previously assembly ) using Rexx and can attest to a better naming convention. Those 8 byte names are cryptic and tell you almost nothing. I finally, gave up and just switched languages and rewrote it from scratch ditching the native assembler code. I could make the modules fully understandable by including a decent naming convention saying what their home routine is and what called them. So I took care of whoever followed me.
@ericmememan4632
@ericmememan4632 Рік тому
looking at writing code as applied semiotics is incredibly fascinating and i would love to see more of it
@MuhammadShaheer
@MuhammadShaheer 6 років тому
This was quite helpful to understand some of the coding frustrations and the verbosity of the talk helps people without programming backgrounds.
@MykhayloS
@MykhayloS 5 років тому
IDE is the reason why we DO NOT NEED to include explicit import statements. Try to figure out the origin of the class once you open the code in a text editor. That is why I prefer to explicitly include full import statements, because it helps to sort the things out. If I remember it well, wildcard import is reported by SonarQube by default. So, it is considered to be quite a good coding practice.
@RoverT65536
@RoverT65536 6 років тому
toBe = nobility(suffering(fortune.slings, fortune.arrows)) < nobility(ending(arms, troubles))
@manonthedollar
@manonthedollar 4 роки тому
#define QUESTION (bb || !bb)
@artemkorotenko666
@artemkorotenko666 3 роки тому
@@manonthedollar #define QUESTION (true)
@Slashx92
@Slashx92 3 роки тому
@@artemkorotenko666 if (true) { // remove later ... // code }
@ade8890
@ade8890 3 роки тому
@@Slashx92 if (true) { // remove later GOTO END } END:
@MechMK1
@MechMK1 2 роки тому
"Capture pragmatics, not statements" is one of the most profound wisdoms of one of my professors.
@ThatIrritatingGuy
@ThatIrritatingGuy 3 роки тому
10:23 the list of tests that the original implementation failed is shown only for a second, making it impossible to read during presentation. If you pause it and actually read the tests, or better yet go back and check the code, you will find that the tests were wrong. If a padding function allows me to pass a multi-character string and I supply it with a multi-character string, I expect that multi-character string to be repeated as padding. Implementation of the presenter takes only the first character, making it incorrect and would make it fail a proper test case. Presenter is being extremely disingenuous.
@cornholiooooooo
@cornholiooooooo 3 роки тому
yeah. i rewinded and stopped for that, too. wtf.
@forbiddenera
@forbiddenera 3 роки тому
I actually agree; when reading through the tests I thought that seemed weird; I suppose it depends how you define valid input but I agree with the commenter that if it allows a multiple character input that it should repeat that padding. Perhaps his interest was in dispelling any ambiguity on how multiple character strings are handled; repeating is the obvious choice but not the only answer. What if you passed "$0",3 with the input 12.31 expecting "$00012.31" and got "$0$012.31" or even "$0$0$0$012.31"; padding is generally done with a single character in most cases and perhaps that's why he made the test that way but again I feel like multiple character input in that situation should cause an error or exception..otherwise the behavior should be well defined..accepting and ignoring input is not.
@forbiddenera
@forbiddenera 3 роки тому
The 2nd one is interesting too..raises the question: should the pad input be the number of characters to add or the total number of characters required? Again it would depend on your use case, whether you're trying to make all strings a certain length with padding or whether you're just adding padding to the strings. I suppose a good function could do either. If the pad input is negative then that's the number of spaces to add from the left, if is positive than that's the total length of the string
@jclounge64
@jclounge64 3 роки тому
I have to disagree. Firstly the original parameter is called 'ch' which indicates it's expecting a single padding character, and secondly if you pass it more than 1 character then the padding code itself won't work properly in the way someone would expect padding to work. Instead it would produce the wrong number of padding characters all the time, throwing the alignment all over the place.
@svivs
@svivs 3 роки тому
7:47 No, I would say the original code is broken. The length parameter is treated as "number of repeats of ch" instead of "final length of the returned string" by the code. In addition, as already noted, ch would indicate a single character. Imagine using this code to populate fields in a database that have a fixed length, you would get overflows and lose data or cause a crash. :)
@adrianconstantin1132
@adrianconstantin1132 2 роки тому
The way to solve name conflicts between awt.* and util.* presented here only works during development. If a new Java version introduces yet another conflict, old code that used to compile suddenly gives conflicts now and needs to be updated.
@ConcerninglyWiseAlligator
@ConcerninglyWiseAlligator Рік тому
"let's create a problem in every file in the project because in a highly unlikely future a handful of them might have a problem" I'll extrapolate this to a slight bigger but related topic: Code can't be and shouldn't be future proof. It will most likely make the code worse now, since general solutions tent to be mediocre solutions. If the problem changes, solutions should change as well. Because solutions must be fitted around the problem to be the best solutions to it.
@ghostofrecon1
@ghostofrecon1 2 роки тому
Great talk! This definitely has me rethinking some of my coding habits
@MarkTomczak
@MarkTomczak 8 місяців тому
What impacts does wild card importing have on the performance of one's IDE? Naively, I would expect it requires the IDE to scan all sub packages in the wild card to understand the context of the code. That could have real impact on the performance of the tools you need to write the code. I do a lot of C++, and on a medium sized code base VS code falls over because the #include import system doesn't give the IDE the opportunity to ignore code out of scope.
@snknsnp
@snknsnp 4 роки тому
To be honest, most modern IDE's strip away import statements anyway. Therefore I strongly dislike wildcard import statements, because this pollutes your code with classes that are not necessarily intentional imports, but still very much present as imported classes. Certainly once you start working on larger projects, you will see that quite many classes can share the same name. For an easy example, consider the class `Proxy`, it is present in: - java.lang.reflect - java.net - javassist.util.proxy - javassist.tools.rmi - org.springframework.boot.autoconfigure.elasticsearch.jest - org.springframework.boot.autoconfigure.sendgrid - org.springframework.boot.devtools.autoconfigure.RemoteDevToolsProperties - org.eclipse.jetty.client - org.springframework.cglib.proxy - ... And probably a lot more. If I were to use ` java.lang.reflect.*`, it would get annoying to use `org.eclipse.jetty.client.Proxy` as well. In our company we call this import pollution. It's true that you can specify and override this, but the point is that it is often more difficult to spot which `List` is the true one. Same for `Proxy`, etc...
@Kenionatus
@Kenionatus 2 роки тому
What you can also do (at least in Python) is to do "import pandas as pd" for packets that are used a lot but you don't want to clutter your namespace with. In this case I think the abbreviated name is a good idea since you are typing it a lot so a more verbose name would clutter your code. At the same time, the import statement self documents the abbreviation.
@matheusjahnke8643
@matheusjahnke8643 2 роки тому
Also, if the languages allows you, you could just import where you need it; first_function(parameters) { import *Stuff* from *Module* do things with parameters and Stuff } second_function(parameters) { import *Other Stuff* from *OtherModule* do things with parameters and Other Stuff } Sometimes I do that in Rust(for specific names I use somewhat frequently and that would collide outside the scope of the function)
@petervansan1054
@petervansan1054 2 роки тому
@@Kenionatus you can't do that in Java (thank the god)
@aloveofsurf
@aloveofsurf 3 роки тому
I am in wow by 5:45. I already believe I have learned great lessons of my life from his trip to the dictionary as pedagogical enterprise.
@patwilson2546
@patwilson2546 2 роки тому
In most ways, well written code and testable code are the same thing. Start with the simple mandate that code have tests. You will end up with pretty clean code. Imposing the requirement to test code naturally leads to smaller code elements, code that is structured for a single purpose, code that separates data acquisition from business logic, etc. Making developers responsible for tested code forces them to think about how to test it, which should lead to writing code that can be tested. The same elements that allow easy testing also allow easy reading and understanding.
@Xiph1980
@Xiph1980 6 місяців тому
Tests should support the code, not the other way around. You are drinking 10 wines.
@patwilson2546
@patwilson2546 6 місяців тому
​@@Xiph1980 If your resume ever comes across my desk, remind me not to hire you. If you want to learn how to code properly please feel free to read the many treatises on the relationship between tests and production code. In particular, look up the phrase "tests are not second class citizens". Until then, stop dispensing advice on how to develop software. It is obvious that you are no more capable of doing that than I am of suggesting a brain surgery procedure.
@TroyNiemeier
@TroyNiemeier 4 роки тому
I gave this video a like after the "stop trying to hit me and hit me!" analogy for naming things. Brilliant!
@TroyNiemeier
@TroyNiemeier 4 роки тому
Another 'like' for correcting the comments' grammar before removing them. lol
@CYXXYC
@CYXXYC 2 роки тому
I use comments just as a step-by-step or block separation. Like if you look up some kind of algorithm on wikipedia, there is possibly a list of steps, where each step takes a couple of lines of code. Before each of those lines I'd put a "// 1. ..." comment with a description similar to the one that wiki page suggested. The purpose of it is not explanation of the code, but either paraphrasing in human language (of course you can read complex math and understand it, but I'm pretty sure it's often more comfortable to read the same thing but using words) or just separating steps for clarity - the code itself should in fact also be self-explanatory or just plain readable. Arguably it can be turned into functions, but I usually don't want to pass over 100 parameters instead of just keeping them in scope. As for block separation, its an interesting case since I don't see it done at all. I logically (subjectively) place fields, getters, setters, methods, functions, static data, etc. near each other, and place a triple // above it, separating those parts of code from the others. As an example, the usual approach is to slap all the fields at the very top of the class, and all of the getters at the bottom, even when given a 1000 line file. In my eyes, even a simple "// // Boilerplate //" (newlines omitted) block at the top and placing fields, getters and setters (yeah, Java) nearby should make if not more readable, at least neater looking code.
@PanduPoluan
@PanduPoluan 2 роки тому
Basically, add comments to help others understand your code, if it's not obvious. Good comments will help you remember why you do things in a particular way when you revisit the code after several months.
@Jollyprez
@Jollyprez 4 роки тому
The issue, really, is maintenance. 80% of all software engineering is maintenance. I've had to maintain my own code for literally decades. In pure self-defense I have developed a way of coding that I can go back to after a decade and still understand what is going on. Also, in my case, I consistently use the simplest coding possible. This means that I tend to avoid using language-specific special syntax when a more common syntax will work. I imagine that I would fail some javascript tests because I don't find it necessary to use '=>' and I avoid 12-part ORs inside an if or whathaveyou. As a result, my code, while maybe "old-fashioned" is usually only about 25% of the size of just about any other programmer's code I've ever seen. And, yes, I've done some seriously complex stuff. When asked a few years ago by a UI designer for my guidance on what a very complicated UI could look like - I told him that if he could draw it, I could code it - AND - make it responsive. He was flabbergasted. But, he did it, and so did I. And the code was tiny.
@arekkrolak6320
@arekkrolak6320 6 років тому
Sir you have made my day with your video!
@brianshacklett9882
@brianshacklett9882 8 місяців тому
I'm getting flashbacks as he talks about imports. I can't count how many times I've wondered where an identifier is coming from in a Java source file, only to find out that they've used wildcards while importing multiple different frameworks, giving me no point of reference as to what type I'm dealing with. It's absolutely maddening. FWIW, I'm a (Neo)Vim user, and strong advocate of understanding before doing
@whirled_peas
@whirled_peas 3 роки тому
The point at 57:50 is particularly applicable outwith programming - bad code is everywhere but programmers aren't stupid - blind adherence to ill-applied systems produces stupidity. Ideological possession produces some of the most stupid and wasteful activities there are. Always be on your toes.
@originuk
@originuk 2 роки тому
Watched this before, a long time ago, but couldn't remember the title. Found it again, with gratitude. Love the eloquent delivery of words of experience, described with great metaphors. Sensible summarisations and enthusiastic energy! Bonkers World! Love it! Computer science has 2 major problems: 1. Cache Coherency. 2. Naming. 3. Off-by-one errors.
@justinkendall8341
@justinkendall8341 3 роки тому
Regarding the star imports, at first I was apprehensive about this because `import com.company.managers.*` is very opaque, but then realized that's not an issue with * importing; it's an issue with bad granularity of namespaces. So my thought on this has been improved to such: use *'s where possible, and name specific classes only when the library in question is not namespaced at the granularity you need for a clear understanding of the dependencies.
@Roescoe
@Roescoe 2 роки тому
I was generally concerned that it would slow down things if I import lots of packages. unsure if that's true, and even if it is, if it matters.
@swapode
@swapode 2 роки тому
I really like re-exports. In Rust it's common for libraries to have a so-called prelude module that re-exports everything for the common use case which you can then import via wildcard (use some_library::prelude::*;). You keep the internal structure that makes sense for the library but offer a more streamlined way to import/use it.
@cyrusol
@cyrusol 9 місяців тому
I don't fully agree with the refactoring in the end. The semantics is different. At some point you gonna have to parse a proper IP address and port from a string. The original function did that. The "refactored" (deleted) version does not and thus simply shifts the burden onto something/somewhere else in the codebase. Of course it's "flashy" to show how you can just delete something but again, the behavior changed and you necessarily have to refactor more than what is showed.
@BenRangel
@BenRangel 2 роки тому
His version of leftpad was hard to read. I don't get the function arguments...What is "pad" are suppose to be. int? string? No turn outs it's a single character. I think the original name "char" was more obvious. Then he stringifies this pad variable and takes the first char from it and assigns that to the pad variable. My first thought was just "what?" I had to read that line many times. I think by overwriting the same variable he's making it much harder to read and losing out on the clarity that a new var name could add. It's much faster to read 4 obvious lines than 1 "clever but quirky" line.
@timonix2
@timonix2 2 роки тому
It was a wall of text. Might as well have been the opening statement of the Iliad in Greek. The other ones at least tried
@bothieGMX
@bothieGMX 2 роки тому
The real reason for explicitly naming every single class instead of whole packages is name space pollution. If you do import package a.*; import package b.*; and your code compiles fine, then you only have to wait for version 2 of package 'a' getting released to get a clash of identifiers. And then, nobody remembers, which instance of class Foo you meant. a.Foo or b.Foo? So you can't even resolve this issue without hours of investigation. (Except in the lucky case, you just try a.Foo and it does NOT work, then you know, it was wrong and take b.Foo. But if a.Foo seems to work and b.Foo seems to work too, then you're screwed.)
@Exilum
@Exilum 2 роки тому
Or whoever updated 'a' checks whether what they did does not cause problems and the problem never existed. Or more than one person is working on it and thus there is versioning, which can easily help you know it was b.Foo you were using. The second is a failsafe for the first, which not doing would literally be considered a grave error. Doing wildcards with exceptions, rather than only explicit naming, is simply just one of the potential better methodologies.
@ThomasBomb45
@ThomasBomb45 2 роки тому
@@Exilum it's good to avoid potential problems even if someone else would be blamed for them if they occur. Especially given that it might not be obvious if something has gone wrong
@RobertWHurst
@RobertWHurst 2 роки тому
Thanks for the insightful talk. I program Go, Rust, and TypeScript on the regular. I've done plenty of Ruby and Python as well. The knock on JS is a bit much. You don't need to apologize for associating with it. The language has changed and improved a lot since the early Netscape and Internet Exploder (IE6). Also in your fizzbuzz example you used let, you should be using const to declare your variables unless you plan on reassigning them. Other than those minor thoughts, great talk. Thanks for sharing with us :)
@Yawhatnever
@Yawhatnever 2 роки тому
A quick google search shows that the const keyword was not fully supported in Safari until six months after this talk was uploaded, and in some other browsers it was supported only a few months before the talk was posted.
@RobertWHurst
@RobertWHurst 2 роки тому
@@Yawhatnever that's fair, but I wouldn't say that's its just a simple search. I hadn't realized this talk was so old, and given that const landed quite a while ago, I think my comment is reasonable given I thought the talk was more recent. But your point absolutely makes sense given timeline. That said I stand by the rest of my comment. Even when this talk came out it was a bit tacky to trash JS as a toy language. It had evolved sufficiently since the Netscape days even then.
@tissuepaper9962
@tissuepaper9962 2 роки тому
@@RobertWHurst *offended JS dev alert!* *offended JS dev alert!* *offended JS dev alert!*
@RobertWHurst
@RobertWHurst 2 роки тому
@@tissuepaper9962 I'm a polyglot. JS does have plenty of shortcomings. I wouldn't get much of the stuff I work on done if I was limited to a single language. Provincial attitudes about tooling and languages do bother me though - comes from ignorance.
@tissuepaper9962
@tissuepaper9962 2 роки тому
@@RobertWHurst wow, using the word "provincial" in your complaint about ignorance. Do you not see that irony in that? Get bent. I was just poking fun, but now it's clear your head really is up your own ass.
@simondrew2914
@simondrew2914 2 роки тому
Having just praised his own coding practice for being brief (and presumably, efficient), he pours scorn on the use of a perfectly good word, 'thenceforth', to mean 'from that point onwards'.
@MrSquishles
@MrSquishles 8 місяців тому
I kind of like the specific imports in java, because the other thing they're bad at is determining package namespace cohabitation. people jam a lot of stuff into one package probably named after it's logical layer rather than it's use case.
@seephor
@seephor 3 роки тому
My test is. You know you're dealing with enterprise-level code when you can copy/paste the entire 50 file project into a single file that you can now actually read and you feel like you've accomplished something.
@herbert164
@herbert164 2 роки тому
I understand your point, but making a monolithic file to replace multiple can be in its own right bad practice.
@Stettafire
@Stettafire 2 роки тому
@@herbert164 Agreed. For one code reuse becomes more challenging, leading to a lot more copy paste. (Also it's ugly)
@pt8306
@pt8306 Рік тому
Yeah enterprise code seems to be absolutely chock full of unnecessary abstractions and redirections and extremely bloated class hierarchies. When copy-pasting it all across you can usually see where the issues are and just remove those classes entirely.
@dsmyify
@dsmyify 5 років тому
We change the tool and the tool changes us. IDE edition. Thanks for sharing.
@programaths
@programaths 4 роки тому
When I did QA, I did search for comments. Those are often a great indication that the code that follow has to be in a dedicated function OR is making assumptions. In the second case, that means tracing the code backward to find out a "boundary" where the assumption has to be checked.
@kitsunde
@kitsunde 4 роки тому
Yeah, no one has time to cover every single border case in every single situation, but you should account for the known considerations or you're asking people to relearn them or infer them from your code. Code comments should be written for the things that the code doesn't explain. I.e. I'm not covering case X, I'm ordering these things in an unusual manner for performance, I'm doing a check here because the nature of this object means we can do an early return in this particular case, we have a usual case to cover because an external client is depending on this implementation. etc. etc.
@programaths
@programaths 4 роки тому
@@kitsunde Yep, our commenrs crossed each other. 14h earlier, I wrote that: Comments can be used for WHY, not how. Most languages have systems to document assumptions and even have them checked in debug builds. It's also possible to use comments for code that is not self explanatory, but written that way for performance reasons. One can't assume everyone has the knowledge. One example is the "fast square root" or even if one need to compute some terms in a series.
@TomaszWiszkowski
@TomaszWiszkowski 3 роки тому
i see all that more frequently than i would wish, yet, as Fernest points out, this really boils down to who authored the code, and how deeply attached people are to their "child" (because come on, if that was just a thing we would not be seeing this. right?) you will see totally bizarre pieces of code addressing undocumented laziness, long forgotten, with no corresponding tests, which nobody can tell why is still needed (it's clear as a day it is needed, but why - is a totally different question). you will see people oblivious to "where you're going" but in authority to tell you "how to get there", frequently sending you the wrong way, but you have to listen or face passive aggressive backlash. this talk is great, but it assumes all engineers are rational. They're not. even in large, established and respected organizations, you will frequently see people who are just too insecure to realize that it is a shared goal to make things better. but hey, this is how the old software dies and gets replaced with a new, better software. resist to improvement is a signal of deterioration and a coming death of a project.
@sabriath
@sabriath 3 роки тому
With the network function, it was like watching reasoning of companies having middle management.....upper management says what they want done, peons at the bottom get it done, middle management literally passes that information on.
@jocr6230
@jocr6230 3 роки тому
Modern JS has String.padStart() and String.padEnd(). Loved the talk, looking forward for more conference stuff from Kevlin Henney!
@ysakhno
@ysakhno 8 місяців тому
"Is too many imports in your code a bad thing?" Depends on whether those imports are actually used or not. Unused imports are a bad thing, and should not be there, period. Otherwise, there is no count of imports that would tip into "too many" area. Usually, it's the other metric signifying so-called 'bad code', that comes into effect first, like too large / to complex a file, etc. The imports are not for _you_ to read, they are needed for the compiler. The alternative would be to spell full class names explicitly each time, or import everything there is to import (via a hypothetical, but thankfully non-existent construct like "import **"). I mean, the rhetorical question in such case is - if one can import the whole package via the star-import, why stop there and not import _all_ the packages at once? If you've spoken to people and nobody could explain to you why use explicit imports, you've spoken to wrong people. That's the only conclusion you should come to. And your conclusion should not be that you're smarter than everybody else and found truth and became enlightened.
@qf6894
@qf6894 3 роки тому
The talk title discussion is really on point.
@chrismoscoso3304
@chrismoscoso3304 6 років тому
this talk had too much 'noise' compared to 'signal'
@eltyo340
@eltyo340 5 років тому
-1 dB
@monstertrucks9357
@monstertrucks9357 4 роки тому
Depends on your definitions of signal and noise. If this is noise, I quite like the noise.
@JamesSully
@JamesSully 4 роки тому
The stuff that wasn't informative was entertaining. I appreciated it.
@heartbeatpoetry7704
@heartbeatpoetry7704 5 років тому
I do find it useful having all the import statements be explicit. Most of the time it is hidden by the ide and I don't look at it, but when I do want to look at it, it can be very helpful. If you've designed your code well and each file only does 1-2 things, just from looking at the import lines you can get a rough idea of what the file does and how it is doing it. For example if I'm looking at code I've never seen before and I see that in this file it uses a HashMap and a HashSet but no Lists, the set of possible algorithms and implementations that can be in this file is much different from if I see the only java collection being used is List or Vector. This is even more helpful if you are a small cog in a big company which has massive internal libraries and you want to get a quick overview of what possible dependencies you might have to keep in mind when you are looking at a brand new piece of code someone else has written. Uncle Bob's guideline on the wildcard makes sense in a world without ides but with ides, you get the benefits of having the explicit lines without the costs of the clutter and the hassle of manually maintaining them.
@morlanius
@morlanius 2 роки тому
@37:11 In the example on the screen here, wouldn't it be good practice to specify which implementation when creating the object in order to avoid collision as in his example you wouldn't be able to use the other object if you need it somewhere down the line? @53:30 This became quite the issue for Tesla, to the point of the product failing.
@KipIngram
@KipIngram 2 роки тому
Absolutely fabulous video, Kevlin. Great information and vastly entertaining style. And just so, so, so much truth hiding in the shadows you're wandering through.
@PhillipParr
@PhillipParr Рік тому
I used to be a web developer, but then React happened and everyone's approach to code drove me to insanity.
@clockworksaint
@clockworksaint 2 роки тому
The complaints about imports would be more convincing if they addressed: 1. The versioning problem - there might not be a collision today but what happens when you update the dependencies tomorrow? 2. If you strive not to depend on an IDE, how do you tell where a name comes from? Non-wildcard imports make it easier for readers to tell what the code means without depending on extra tools to search multiple namespaces for you. I read more code than I write and wildcard imports are more of a nuisance to me than verbose ones.
@Exilum
@Exilum 2 роки тому
1.1. Collisions are actually a pretty negligible problem. If your library doesn't collide with your other libraries, there are little chances it does in the future. 1.2. Nothing stops you from only doing partial imports on one of the colliding libraries. You can use wildcards for 99% of your imported classes, and just have that one outlier be imported specifically. That's still way cleaner. 1.3. Any maintained library will go through a deprecation phase. You know your classes or the part of the class your are using is going to be deprecated long before the version it actually stops working at. 1.4. Whether you imported the class individually or not, you are still warned in the same way about said deprecation, and you still have to change your code the same way, the only thing that changes is that you don't need to change the imports in the case of a wildcard, just switch to the newer library. 2.1. You DO NOT need to tell where a name comes from. You need to tell what a name does, and is used for. This is what naming is for in the first place. 2.2. With an IDE, you can hover your mouse over the name and see where it comes from, and eventual additional comments. Without an IDE, the library name would have been less specific and thus wouldn't have helped you knowing what the name does more than it already does. 2.3. Non-wildcard imports do not make life easier for readers, it's an illusion. By having more information, you think you know more, but you have duplicate infos. These imports give you general information that should already either be specified in the names you use, either by the way they are used. 2.4. And that's with an IDE, if you're looking to read code without an IDE, you'd need more time to figure out which one of the 100 or so lines concerns your one piece of code than to just read it anyway. You'd need not only to text search one way, but also do so the other way to find back your code. And in the end, you wouldn't have gotten more information than you already had. If it's a library you knew, you already knew it, if it isn't, you won't know it, and the name is more descriptive in both cases.
@szirsp
@szirsp 7 місяців тому
37:00 I think the same thing is happening in C++ when people say don't use using namespace std; The STL is part of the standard. It's there to use. C++ is "incomplete" without it. AND if you want to switch from the std implementation one day to your own / in house / 3rd party then search and replacing std:: is worse than using a different namespace. And in the meanwhile it makes the code longer, uglier, harder to read.
@sherwinbangs
@sherwinbangs 7 місяців тому
No
@Spiderboydk
@Spiderboydk 3 роки тому
A lot of this aligns surprisingly well with the manstras of programmers like Jonathan Blow.
@enkephalin07
@enkephalin07 7 місяців тому
What I hated about Java when I first learned it (for university) was that it was a poorly performing language further hampered with cargo cult conventions. I had already learned how to code on a platform (LPC) with up to 140 realtime interacting users, ~20-30 of them other developers. You really needed to squeeze the performance out of your code to produce more value than burden to the system. Elegant and efficient code was appreciated by users and fellow devs, and there was no particular respect for conventions that didn't support that.
@BeesAndSunshine
@BeesAndSunshine 3 роки тому
My Python fizzbuzz function fizzbuzz = lambda n: (("fizzbuzz", "fizz"), ("buzz", n))[bool(n % 3)][bool(n % 5)]
@mask477
@mask477 3 роки тому
fizzbuzz = (n) => [["fizzbuzz", "fizz"],["buzz",n]][n%3?1:0][n%5?1:0] FUCK Javascript :@
@EmperorFool
@EmperorFool 3 роки тому
@SArpnt Did you test your "more accurate" version? > Uncaught TypeError: Cannot read property 'false' of undefined
@dingolover6969
@dingolover6969 3 роки тому
That's pretty good!
@dingolover6969
@dingolover6969 3 роки тому
@SArpnt Don't worry, you can write fizzbuzz = n => [["fizzbuzz", "fizz"], ["buzz", n]][+!!(n % 3)][+!!(n % 5)]
@ab-iz1yi
@ab-iz1yi 3 роки тому
sorry just gotta flex on 'ya fizzbuzz = lambda n:[str(n),'fizz','buzz','fizzbuzz'][(not n%3) + (not n%5)*2]
@GuyPaddock
@GuyPaddock 7 місяців тому
Even though it is no longer required to declare at the top of blocks, doing so encourages you to keep your code short. If you are finding yourself defining a lot of variables at the top and/or having to scroll back and forth from where the variables are declared to where they're being used, it's an easy way to detect violations of the single responsibility principle for functions/methods.
@0MVR_0
@0MVR_0 3 роки тому
At first import as normal. Then select for the necessary external methods, rewriting any algorithms that can be done 'by-hand' or use only a single dependency package. A code illegible is a similar to an archeologist finding an indecipherable artifact, yet the complexity is rarely of length, and rather gratuitous shorthand.
@PuzzleQodec
@PuzzleQodec 4 роки тому
1:07:40 Actually, dear sir, the braces are there to make sure that when doing a merge, the syntactic structure of a nested if-statement does not change unintentionally, or it will give a conflict. It is less likely that whoever does the conflict resolving will make an error.
@DerrickJolicoeur
@DerrickJolicoeur 3 роки тому
Hmm, an interesting justification. Thanks for the insight
@milanstevic8424
@milanstevic8424 3 роки тому
So your explanation puts an emphasis on how mindlessly people merge two codebases. In other words, if we imagine the two wildly different domains -- the one that is about the mindfulness of the software engineers that are doing the merge, and the other that is the technical and cognitive state of the product of software engineering -- you're brazenly mixing between the two with the idea that it's the same thing, which they are not. Your solution doesn't change or correct the irresponsible malice of the social/labor domain of codebase merging (which is effectively producing a new codebase without exception), it merely prevents the potentially catastrophic outcome by chance, by employing an unnecessary and opaque safeguard that further complicates the cognitive structure of the product (i.e. readability), encourages further boilerplate, and does that mostly for conspiratorial, superstitious, and particularly defensive cross-domain reasons. That's a hidden accident waiting to happen, while you're doing nothing to eradicate the root causes. In fact, I'd immediately fire you for remedying a cross-domain problem like that, because you're hiding the actual cause of any potential situation, and are diluting the responsibility of the action. You're basically breeding a dragon. If that's not a term, it should be. It's a particularly vicious type of dragon, one >>you thought
@PuzzleQodec
@PuzzleQodec 3 роки тому
@@milanstevic8424 Heh, it's hard to take you seriously when this is something you'd fire me for. "I made things harder for you and still you made an error? You're fired!", or if this idea is taken to a more extreme level: "Let's not write tests so my programmers will be more responsible!" Nah I don't buy it. Trust me that my team is much better off when they focus on more interesting problems to solve. Considering the size of merges (or rebases, whatever workflow takes your fancy), you don't need large codebase merges for this particular accident to happen. We've been using continuous integration for years, and it still happened to us once. Those merges weren't hard, and we did them carefully. It can occur already when whitespace conflicts are resolved incorrectly (if no braces are used). Considering readability, this is the first time I've heard somebody call two braces 'boilerplate'. I wonder what you think then of Pascal's _begin_ and _end_ keywords. You also had the opportunity to suggest an alternative: put the 'then' clause on the same line as the if-condition: ```if (condition) DoSomething();``` No extra braces, no merge problems, even more condensed code. Best of all worlds. Responsible programmers learn responsible habits. I consider usage of braces one of them. For the record, please don't insult me by saying I'm doing cargo cult programming, or using defensive programming without reason. I didn't take offense, but you don't know who you're talking to.
@milanstevic8424
@milanstevic8424 3 роки тому
@@PuzzleQodec I never called two braces boilerplate. I said that the two braces invite boilerplate and abnormal cluttering. Which they do. The thing is, if you don't actually need the two braces, then you don't need the two braces. Placing them everywhere makes every little bit of code lovingly compatible for a few more lines to be quickly added by your colleagues that are likely to be less than enthusiastic about finding or inventing a proper place for them. This goes out of hand quickly and invites further boilerplate. "Responsible programmers learn responsible habits." There is a massive contradiction lurking beneath this quote. There are no good habits in programming. Literally none of the habits are good, let alone responsible. You also don't need habits to be a good programmer. And no business wants its programmers to be run by habits. If you're thinking like "hygienic habits" like washing your hands after visiting the restroom, that is exactly what is known as a boilerplate, and we need less of it in code, not more. Maybe it's good for you (or your management) because you strain less and appear to do more work with less energy, but that's not exactly desirable if you ask me. Maybe it is desirable for you, but if you're on cruise-control 24/7, never checking your assumptions and never trying to figure out the non-habitual ways of doing things, I'm sorry but you're not a great programmer. I seriously don't want to know in which company you're applying that attitude. "I didn't take offense, but you don't know who you're talking to." Of course you didn't take any offense, because I didn't offend. I can state the latter part just as easily and with greater authority, but why does that matter? Please don't venture into argumentative fallacies. I have concretely criticized your approach in how you're theoretically handling a multi-domain problem, in a non-offensive manner, while you haven't even addressed what I said. Yes, I would fire you big time for doing that. You're basically acting all smart without understanding the eventual consequences that are typical for such an irresponsible behavior. You're OPTIMIZING early, you're saving someone's ass to save your own production line, you're covering up a mistake that SHOULD go off, because then a better practice and a better convention could be invented. All in all, you're just following the unspoken rules of your management, who practically can't discern between a poor merge and poor implementation, which is also typical, and you've learned to covering it all up, only to make things run smoothly. That whole concept needs to go away, can you understand that? If your management is idiotic, the company SHOULD suffer from their appalling practices and poor understanding of how things work. And you, on the other hand, if you're an engineer, should focus instead on how to have the cleanest possible code, completely free of habits, superstition, and clutter, while providing its users maximum experience. You're basically committing a fraud by thinking that your solution is for a greater good. Everything appears shiny from the outside, but you're invisibly bloating the codebase and cramming it up with unnecessary symbols that cumulatively make the code harder and harder to understand, with an excuse that it "saves lives" and money in the long run. After a certain point, and this is bound to happen sooner than later, trivial things/methods/routines become very labor-intensive to read and maintain, and it's NO ONE's fault. Not even yours. It's "how we run things, that's normal, no problem in that".. So very much like that Java import situation from the video, which is a ridiculous real world example. Finally, you're the only one who can navigate this two-brace labyrinth of your doing, because you've trained yourself against such malpractices for years, artificially making you irreplaceable in your organization. Everything is enveloped in two braces, has 16 indentations, null checks all over the place, funny-looking imports, multi-lined function calls, and whatnot, and voila you have created a symbolic culture that a beginner (however proficient he or she might be with the language itself) can't decipher without earning rites of initiation in your company FOR YEARS. Do you get where your problem lies? It's as much social as it is technical. I think I've thoroughly explained why I think you're wrong and why you shouldn't go through that red light even if there is no traffic on the intersection. Don't play smart. I'd fire you twice if I could. So instead of being offended, try to learn something out of it, and stay happy because you're obviously working for crappy companies that seem to pay attention someplace else instead of where their money and reputation actually lives.
@PuzzleQodec
@PuzzleQodec 3 роки тому
@@milanstevic8424 Sorry, I think you're only arguing for the sake of it. I'll stop wasting my time.
Lambda? You Keep Using that Letter - Kevlin Henney
1:00:53
NDC Conferences
Переглядів 97 тис.
The Worst Programming Language Ever - Mark Rendle - NDC Oslo 2021
1:00:41
NDC Conferences
Переглядів 1,3 млн
LIVE - Парад Победы в Москве. 9 Мая 2024
2:27:56
AKIpress news
Переглядів 2,2 млн
skibidi toilet 73 (part 2)
04:15
DaFuq!?Boom!
Переглядів 31 млн
DYNAMICS PROJECTILE MOTION 5
17:57
ENGR. MIKAY
Переглядів 143
Ctrl-Alt-Del: Learning to Love Legacy Code - Dylan Beattie
56:47
NDC Conferences
Переглядів 130 тис.
🚀  Seven Ineffective Coding Habits of Many Programmers (Kevlin Henney)
54:28
DevTernity Conference
Переглядів 19 тис.
Decremental Development (Kevlin Henney)
1:03:06
DevTernity Conference
Переглядів 4 тис.
Clean Code : Horrible Performance | Full Interview
47:13
ThePrimeTime
Переглядів 197 тис.
The Art of Code - Dylan Beattie
1:00:49
NDC Conferences
Переглядів 4,7 млн
Refactoring to Immutability - Kevlin Henney
1:03:22
NDC Conferences
Переглядів 92 тис.
How Senior Programmers ACTUALLY Write Code
13:37
Healthy Software Developer
Переглядів 1,3 млн
M4 iPad Pro Impressions: Well This is Awkward
12:51
Marques Brownlee
Переглядів 5 млн
APPLE УБИЛА ЕГО - iMac 27 5K
19:34
ЗЕ МАККЕРС
Переглядів 83 тис.