about 26:00. I worked at a company once that required every line of code be commented. The comments were extracted later and became the documentation for the code.
@Peter Mortensen So we had code that looked like the following. This is C code /* if value is less than 100 */ if ( value < 100 ) { /* then do awesome */ awesome(); } Which made the documentation if value is less than 100 then do awesome. Literally it was the worse way to create any kind of documentation.
12:13, 'goto' keyword would had save the day. Another way to bureaucratically prevent that would be to adopt a practice of write a checking at the beginning of each f(), according to a debug compilation. For instance: some_type_in_return use_modes_pointer () { #ifndef NDEBUG /* Check pointers. */ #endif /* ... */ } 49:30, '4. Keep it simple': functional programming is simpler, but I use OO in most cases, because '3. Design for security policies'. The "const correctness principle" (all const by default) is a '5. Deny by default' and keeps the '6. least privileges'. However, it seems, by examples I've been seeing, that languages other than C++ fail to achieve the 6, regarding to hiding data changing, or keeping the '6. least privileges' of who has the right to change data.
OOP isn't safer, it's just more anal. OOP in dynamically typed languages doesn't do a thing with regards to type and interface "safety". It may give a completely false sense of security, though.
@@lepidoptera9337 At least in C++, it's possible to say exactly which f()s are allowed to change variables from each class. This is a huge "game changer". It seems Java and C# don't have this, thus are less safe. I would not wonder if other higher level languages were as dumb as those. And what do you mean by "anal"?
@@MrAbrazildo Yes, and deployed C++ code has millions and millions of other security problems like vulnerability to buffer overflow attacks. I have code out there that has 100% uptime and 0 bugs that works entirely with global variables. Compartmentalization is not an effective technique to improve code quality. It just makes your inner micromanager feel good.
@@lepidoptera9337 It depends on the project complexity. If it always follow some f()s calls order, it's easy to manage, no matter how complex it has inside those f()s - scientific ones, for instance. But there are projects in which the order of events, f() call and other things may change drastically, according to values in variables - games, for instance. For those, variables should be hidden.
@@MrAbrazildo I think there is a general misunderstanding about what a bug is: it's not an error that the computer and the compiler make. From that it follows that the compiler can't catch these bugs for us, either. It simply faithfully does what we tell it to do. A bug is simply the disconnect between what we wanted to happen vs. what we told the computer to do. That means bugs happen in our minds. They are a failure of the programmer's mental model to anticipate the program's response. That's hardly a surprise: we are, after all, automating tasks that are too hard to do manually or mentally, both in terms of number of operations as well as complexity. Scoping is merely a band aid on the gushing wound of that problem. I would go one step further: all attempts to reduce the expressiveness of a language produce a nasty side effect: instead of doing the obvious thing (like reading and writing a global variable), we are now looking for Rube Goldberg workarounds to accomplish whatever it is that we want to do. A global state change is a global state change no matter how it is done (because it has to be!). In this case replacing a global with deeply scoped variables might turn into something like our class method calling another class method written by the team in India that calls a class method that was written by a world famous consultant that creates an event that a global event handler licensed from "GlobalEventHandlersAreUs LLC" translates into a global variable change while also logging who, when and for what reason changed "turnLeftSignalBoolean" to "True" using an open source database backend hosted on an Amazon server. How stupid is that? There may be three hundred or thousands of lines of code involved in an operation that required nothing but a simple memory write. Absolutely nothing was gained, except job security for a dozen people who can't even imagine that all they are doing on an average day is to overcomplicate what would otherwise have been a trivial problem. If you don't believe me... tell me what functionality a server version of Office 365 has over a 16kB word processor or a spreadsheet written in 8bit assembler on an Apple II. Absolutely none. Both tools get the job done. One just uses a lot more CPU cycles and electricity than the other and needs hundreds of programmers instead of one, two or three. So the next time you feel good about NOT accessing a global by calling somebody else's class method instead, try to evaluate just how many opportunities for nasty bugs are lurking in the code complexity of what you are doing over a simple assignment. You will, in general, find that the simple solution would have been far less risky while being orders of magnitude higher performing.
To answer your question: 1. Yours doesn't do the same thing. leftpad accepts any character to use as padding, whereas yours always uses a space character. 2. .repeat wasn't added to to ECMAScript spec until 2015, long after leftpad was written. In fact, I think it fails a number of the functional tests presented at 46:43
Yes, if an object can't be constructed, the constructor should throw an exception. An objects lifetime starts when its constructor successfully returns.
Does Java have the concept of pointers exposed to the programmer? I know that in C# everything is a pointer, but that fact is hidden from the programmer.
Non-primitive data types are passed by reference, which are pointers. That's not Java specific. It simply doesn't make sense to copy a GByte size array onto the heap for a function call.
@@lepidoptera9337 In other words the same as C#. I have met many programmers that did not understand that non primitive types were always references (aka pointers that cannot be null) in C#. I'm betting that the same is true for Java programmers.
@@johnmcleodvii Yes, there are a lot of programmers who are absolutely clueless about what they are doing. If C# passes even primitive types as references, then it is a dangerous and inefficient language. There are good reasons (efficiency is one of them because passing by reference is extremely expensive on a modern machine that can produce a cache miss that way) not to do that, which is why C gives programmers both options. C simply requires a programmer to understand the difference between a variable and a reference to a variable. That's like the ABCs of computer science. I think my CS professor taught this in his first lecture about machine design.
@@lepidoptera9337 but C++, unlike C# and Java allows the programmer to create complex types on the stack or create a pointer to them on the heap. In C# and Java, all complex types are created on the heap, you just have a pointer to the heap on the stack.
about 26:00. I worked at a company once that required every line of code be commented. The comments were extracted later and became the documentation for the code.
@Peter Mortensen So we had code that looked like the following. This is C code
/* if value is less than 100 */
if ( value < 100 ) {
/* then do awesome */
awesome();
}
Which made the documentation
if value is less than 100
then do awesome.
Literally it was the worse way to create any kind of documentation.
Pretty stellar presentation. First exposure to Kelvin, but I suspect not the last.
It's Kevlin!
Now I want to go back in time to capture all the cool failures I saw.
Another great talk by Kelvin.
interesting upload GOTO Conferences. I killed the thumbs up on your video. Keep on up the superb work.
31:09 i might have said this before, but at this point it becomes increasingly simpler to write straight assembly
'We do that in English, we do in Dutch... But not in Java' hahaha
You don't code if you gaven't had to deal with a "Thing controller manager proxy factory".
"Thing controller manager proxy factory controller manager proxy" - thing.
12:13, 'goto' keyword would had save the day. Another way to bureaucratically prevent that would be to adopt a practice of write a checking at the beginning of each f(), according to a debug compilation. For instance:
some_type_in_return use_modes_pointer () {
#ifndef NDEBUG
/* Check pointers. */
#endif
/* ... */
}
49:30, '4. Keep it simple': functional programming is simpler, but I use OO in most cases, because '3. Design for security policies'.
The "const correctness principle" (all const by default) is a '5. Deny by default' and keeps the '6. least privileges'. However, it seems, by examples I've been seeing, that languages other than C++ fail to achieve the 6, regarding to hiding data changing, or keeping the '6. least privileges' of who has the right to change data.
OOP isn't safer, it's just more anal. OOP in dynamically typed languages doesn't do a thing with regards to type and interface "safety". It may give a completely false sense of security, though.
@@lepidoptera9337 At least in C++, it's possible to say exactly which f()s are allowed to change variables from each class. This is a huge "game changer". It seems Java and C# don't have this, thus are less safe. I would not wonder if other higher level languages were as dumb as those.
And what do you mean by "anal"?
@@MrAbrazildo Yes, and deployed C++ code has millions and millions of other security problems like vulnerability to buffer overflow attacks. I have code out there that has 100% uptime and 0 bugs that works entirely with global variables. Compartmentalization is not an effective technique to improve code quality. It just makes your inner micromanager feel good.
@@lepidoptera9337 It depends on the project complexity. If it always follow some f()s calls order, it's easy to manage, no matter how complex it has inside those f()s - scientific ones, for instance. But there are projects in which the order of events, f() call and other things may change drastically, according to values in variables - games, for instance. For those, variables should be hidden.
@@MrAbrazildo I think there is a general misunderstanding about what a bug is: it's not an error that the computer and the compiler make. From that it follows that the compiler can't catch these bugs for us, either. It simply faithfully does what we tell it to do. A bug is simply the disconnect between what we wanted to happen vs. what we told the computer to do. That means bugs happen in our minds. They are a failure of the programmer's mental model to anticipate the program's response. That's hardly a surprise: we are, after all, automating tasks that are too hard to do manually or mentally, both in terms of number of operations as well as complexity. Scoping is merely a band aid on the gushing wound of that problem.
I would go one step further: all attempts to reduce the expressiveness of a language produce a nasty side effect: instead of doing the obvious thing (like reading and writing a global variable), we are now looking for Rube Goldberg workarounds to accomplish whatever it is that we want to do. A global state change is a global state change no matter how it is done (because it has to be!).
In this case replacing a global with deeply scoped variables might turn into something like our class method calling another class method written by the team in India that calls a class method that was written by a world famous consultant that creates an event that a global event handler licensed from "GlobalEventHandlersAreUs LLC" translates into a global variable change while also logging who, when and for what reason changed "turnLeftSignalBoolean" to "True" using an open source database backend hosted on an Amazon server. How stupid is that? There may be three hundred or thousands of lines of code involved in an operation that required nothing but a simple memory write. Absolutely nothing was gained, except job security for a dozen people who can't even imagine that all they are doing on an average day is to overcomplicate what would otherwise have been a trivial problem.
If you don't believe me... tell me what functionality a server version of Office 365 has over a 16kB word processor or a spreadsheet written in 8bit assembler on an Apple II. Absolutely none. Both tools get the job done. One just uses a lot more CPU cycles and electricity than the other and needs hundreds of programmers instead of one, two or three.
So the next time you feel good about NOT accessing a global by calling somebody else's class method instead, try to evaluate just how many opportunities for nasty bugs are lurking in the code complexity of what you are doing over a simple assignment. You will, in general, find that the simple solution would have been far less risky while being orders of magnitude higher performing.
Amazing talk sir, thanks a lot!
Why not just this... ?
var PadL = (str,len) => " ".repeat(Math.max(0, len - str.length)) + str;
To answer your question:
1. Yours doesn't do the same thing. leftpad accepts any character to use as padding, whereas yours always uses a space character.
2. .repeat wasn't added to to ECMAScript spec until 2015, long after leftpad was written.
In fact, I think it fails a number of the functional tests presented at 46:43
Constructor failing?
Yes, if an object can't be constructed, the constructor should throw an exception. An objects lifetime starts when its constructor successfully returns.
Does Java have the concept of pointers exposed to the programmer? I know that in C# everything is a pointer, but that fact is hidden from the programmer.
Non-primitive data types are passed by reference, which are pointers. That's not Java specific. It simply doesn't make sense to copy a GByte size array onto the heap for a function call.
@@lepidoptera9337 In other words the same as C#. I have met many programmers that did not understand that non primitive types were always references (aka pointers that cannot be null) in C#. I'm betting that the same is true for Java programmers.
@@johnmcleodvii Yes, there are a lot of programmers who are absolutely clueless about what they are doing. If C# passes even primitive types as references, then it is a dangerous and inefficient language. There are good reasons (efficiency is one of them because passing by reference is extremely expensive on a modern machine that can produce a cache miss that way) not to do that, which is why C gives programmers both options. C simply requires a programmer to understand the difference between a variable and a reference to a variable. That's like the ABCs of computer science. I think my CS professor taught this in his first lecture about machine design.
@@lepidoptera9337 but C++, unlike C# and Java allows the programmer to create complex types on the stack or create a pointer to them on the heap. In C# and Java, all complex types are created on the heap, you just have a pointer to the heap on the stack.
@@lepidoptera9337 I think this was covered in my 4th or 5th lecture on the C language (a year before my first Data Structures class.)
Quintor interesting.