Clean Code - Uncle Bob / Lesson 2

01:06:00
https://www.youtube.com/watch?v=2a_ytyt9sf8

Sintesi

TLDRLa vidéo explore l'origine de la Lune en commençant par débattre de diverses théories telles que la capture d'un astéroïde ou la Lune provenant de la Terre elle-même. Les caractéristiques particulières de la Lune, telles que sa composition presque identique à celle de la Terre mais sans fer, et son orbite unique qui ne s'aligne pas avec l'équateur terrestre, compliquent l'identification de son origine. La théorie la plus acceptée aujourd'hui est celle de l'impact géant. Selon cette théorie, un corps céleste de la taille de Mars aurait percuté la Terre il y a environ 4,5 milliards d'années. L'impact aurait causé une fusion de matériaux, projetant des silicates légers pour former un anneau qui s'est ensuite coalescé pour devenir la Lune, tandis que les noyaux de fer des deux corps auraient fusionné dans le noyau de la Terre. Ce processus arrivé il y a plusieurs milliards d'années a aussi engendré une orbite circulaire et stabilisée de la Lune, laquelle est verrouillée sur la Terre montrant toujours la même face. La vidéo mentionne également que le processus d'éloignement de la Lune continuera des milliards d'années.

Punti di forza

  • 🌍 La Lune provient probablement de la Terre.
  • 🔄 Sa composition est similaire, mais sans fer.
  • 🪐 Elle a un orbite circulaire atypique.
  • 🔒 La Lune est verrouillée sur la Terre.
  • 💥 Théorie actuelle : impact géant avec un corps de taille martienne.
  • 🛠 Fusion de matériaux suite à une collision.
  • 🌌 Formation dûe à un anneau de débris.
  • ↔️ Éloignement progressif de la Lune.
  • ⏱️ Ancien jour terrestre de 6 heures.
  • ⚙️ Ajustement continu dans le système Terre-Lune.

Linea temporale

  • 00:00:00 - 00:05:00

    La question de l'origine de la lune est plus complexe qu'il n'y paraît. Elle pourrait provenir de la Terre, mais cela implique plusieurs théories sur sa formation : capturée comme un astéroïde, émergeant de la Terre, ou formée par la collision avec un autre corps. Les particularités de son orbite et de sa composition chimique compliquent davantage le mystère, jusqu'à la théorie moderne d'une collision géante ayant créé un anneau qui est devenu la lune.

  • 00:05:00 - 00:10:00

    Les commentaires dans le code servent à expliquer des parties de code qui ne peuvent pas s'expliquer d'elles-mêmes. L'auteur critique l'usage excessif de commentaires en se référant à des anecdotes sur les limitations de langages anciens comme le Fortran. Aujourd'hui, les structures des langages modernes permettent de s'exprimer par du code explicite, rendant souvent les commentaires redondants ou nuisibles.

  • 00:10:00 - 00:15:00

    Chaque commentaire représente un échec à s'exprimer clairement en code. Les commentaires se détériorent avec le temps, étant rarement mis à jour ou même lus dans le contexte du code. L'auteur défend l'idée que le code doit, autant que possible, expliquer son propre but et que les commentaires doivent être un dernier recours.

  • 00:15:00 - 00:20:00

    Les exemples de bons commentaires incluent des avertissements sur des conceptions spécifiques, par exemple les méthodes singletons ou des expressions régulières complexes. Cependant, même certains commentaires bien intentionnés peuvent devenir trompeurs s'ils ne sont pas maintenus à jour avec le code.

  • 00:20:00 - 00:25:00

    Les mauvais commentaires incluent ceux qui ne font que répéter le code, ceux qui deviennent obsolètes, ou ceux qui sont inutiles et encombrants. L'auteur préconise d'éviter les commentaires superflus, soulignant que la responsabilité professionnelle implique de ne pas laisser des excuses dans le code.

  • 00:25:00 - 00:30:00

    Les lignes directrices pour les commentaires indiquent que celles qui sont justifiées apportent une valeur ajoutée, surtout lorsqu'elles clarifient l'intention derrière des astuces de codage ou résument des concepts complexes qui ne peuvent pas être exprimés facilement en code.

  • 00:30:00 - 00:35:00

    Les commentaires de mauvaise qualité proviennent souvent d'une obligation de commenter, menant à des contributions vides de sens ou préjudiciables. Par exemple, l'abus de JavaDocs et les mises à jour manquantes transforment les commentaires en liabilité plutôt qu'en atout.

  • 00:35:00 - 00:40:00

    L'analyse des projets Java montre une variété dans la taille des fichiers source, peu corrélée à la taille du projet. Des projets plus petits peuvent avoir des organigrammes similaires aux plus grands, suggérant que la taille des fichiers est une question de style de codage et non de nécessité structurelle.

  • 00:40:00 - 00:45:00

    Concernant la taille des lignes, une tendance commune émerge des projets étudiés : les lignes de code ont tendance à avoisiner les 30-40 caractères, et peu dépassent 80 caractères. L'ergonomie des lignes courtes facilite la lecture du code et rend les longs défilements horizontaux désagréables.

  • 00:45:00 - 00:50:00

    Les noms dans le code apportent une mine d'informations sur la fonction et le contexte du système. Ils doivent être intelligibles et proportionnels à la portée : plus le contexte est large, plus le nom doit être court, et vice versa. Les noms trop cryptiques ou non expressifs mènent à des ambiguïtés dans la compréhension du code.

  • 00:50:00 - 00:55:00

    Les anciens préfixes pour identifier les variables et arguments sont remplacés par des outils modernes, rendant ces conventions obsolètes. Cependant, il est crucial d'éviter les mots factices ou redondants dans les noms, qui ajoutent du bruit sans clarification ni différenciation significative entre différents types ou variables du système.

  • 00:55:00 - 01:00:00

    La distinction entre les noms doit être claire pour éviter des erreurs visuelles dans le code. À une époque, les préfixes étaient utilisés pour cette raison, mais les IDE modernes rendent cette pratique désuète. Une gestion soignée des noms empêche la confusion entre des variables aux noms semblables.

  • 01:00:00 - 01:06:00

    En développant sur le sujet des noms, on met en avant l'importance de choisir des noms qui communiquent clairement l'intention, qui sont prononçables et éviter le charabia technique. La pratique de la programmation en binôme est vantée comme un moyen plus efficace de vérifier et partager le code que les revues de code traditionnelles.

Mostra di più

Mappa mentale

Mind Map

Domande frequenti

  • Pourquoi la Lune présente toujours la même face à la Terre ?

    La Lune est tidally locked à la Terre, conservant toujours le même visage vers nous.

  • Quels sont les arguments contre l'idée que la Lune a été capturée par la Terre ?

    La Lune a une orbite circulaire non typique pour un corps capturé, et sa composition est similaire à celle de la Terre.

  • Pourquoi la composition de la Lune suggère-t-elle qu'elle provient de la Terre ?

    La Lune manque de fer et présente des isotopes similaires à la Terre, suggérant une origine commune.

  • Quelle est la théorie actuelle sur la formation de la Lune ?

    Une collision avec un objet de la taille de Mars aurait pu heurter la Terre, formant un anneau de débris devenu la Lune.

  • Pourquoi l'orbite de la Lune change-t-elle au fil du temps ?

    La Lune s'éloigne lentement de la Terre et cela pourrait prendre onze milliards d'années pour que la Terre soit verrouillée par marée à la Lune.

Visualizza altre sintesi video

Ottenete l'accesso immediato ai riassunti gratuiti dei video di YouTube grazie all'intelligenza artificiale!
Sottotitoli
en
Scorrimento automatico:
  • 00:00:15
    yeah okay so where did the moon come
  • 00:00:17
    from came from the earth probably this
  • 00:00:23
    is true although it's a little more
  • 00:00:24
    complicated than that
  • 00:00:26
    I remember my my grade school science
  • 00:00:29
    book gave us some options for where the
  • 00:00:32
    moon came from one of the options was
  • 00:00:34
    that the moon was captured it was an
  • 00:00:36
    asteroid that the earth simply captured
  • 00:00:39
    with its gravity and another option was
  • 00:00:42
    that the moon bubbled out of the earth
  • 00:00:45
    somehow and to demonstrate that point my
  • 00:00:48
    science book showed a picture of the
  • 00:00:51
    Pacific Ocean with the moon superimposed
  • 00:00:55
    on it because the moon would fit right
  • 00:00:57
    into the Pacific Ocean so clearly that's
  • 00:00:59
    where the moon came from the problem of
  • 00:01:04
    figuring out where the moon came from is
  • 00:01:06
    actually fairly complicated because the
  • 00:01:08
    moon is a strange object first of all it
  • 00:01:12
    does not orbit in the plane of the
  • 00:01:15
    Earth's equator it orbits in the plane
  • 00:01:18
    of the solar system so the angular
  • 00:01:20
    momentum of the moon is more strongly
  • 00:01:22
    related to the Sun than it is to the
  • 00:01:24
    earth that argues that the moon did not
  • 00:01:27
    come from the earth on the other hand
  • 00:01:30
    the orbit of the moon is circular it's
  • 00:01:33
    very difficult for a captured body to
  • 00:01:36
    have a circular orbit any kind of
  • 00:01:38
    captured body would have a wildly
  • 00:01:39
    elliptical orbit so how did how did we
  • 00:01:43
    get this circular orbit an object if it
  • 00:01:47
    didn't come from the earth and then you
  • 00:01:49
    look at the composition of the moon and
  • 00:01:51
    the composition of the moon is virtually
  • 00:01:53
    identical to the earth right down to the
  • 00:01:56
    isotope ratios with one glaring
  • 00:01:59
    exception which is that the moon has no
  • 00:02:01
    iron and the earth is mostly iron
  • 00:02:04
    so although the minerals in the moon are
  • 00:02:07
    very similar to the earths it's missing
  • 00:02:10
    the iron if the moon came
  • 00:02:12
    from the earth some process must have
  • 00:02:14
    filtered all of that iron out
  • 00:02:16
    and finally the moon is tidally locked
  • 00:02:20
    to the earth it keeps the same face to
  • 00:02:23
    the earth at all times and that can only
  • 00:02:25
    happen if the orbit started much closer
  • 00:02:28
    to the earth and was pushed outward by a
  • 00:02:31
    transfer of angular momentum
  • 00:02:33
    so what could satisfy all these
  • 00:02:36
    constraints and scientists have worked
  • 00:02:39
    on this for a very long time and
  • 00:02:40
    eventually about 30 years ago they came
  • 00:02:42
    to this very interesting conclusion it
  • 00:02:45
    turns out that in every orbit 60 degrees
  • 00:02:48
    away there are stable points in that
  • 00:02:51
    orbit so if you take a look at the Earth
  • 00:02:53
    Moon system and you go 60 degrees away
  • 00:02:55
    from the moon there's a stable point in
  • 00:02:58
    the Earth's orbit there it's possible
  • 00:03:00
    that another body formed a body maybe
  • 00:03:05
    the size of Mars and the these stable
  • 00:03:09
    points are metastable they're not
  • 00:03:11
    perfectly stable so if you disrupt an
  • 00:03:13
    object there it will start to slide
  • 00:03:15
    across the orbit until it impacts you so
  • 00:03:18
    it's possible that some object roughly
  • 00:03:20
    the size of Mars maybe four and a half
  • 00:03:23
    billion years ago formed at one of these
  • 00:03:26
    stable points in the earth-sun orbit got
  • 00:03:30
    disrupted moved in and smashed into the
  • 00:03:32
    earth melting both bodies the two iron
  • 00:03:35
    cores went to the center of one of the
  • 00:03:37
    bodies and the there was a splash that
  • 00:03:40
    splash formed a ring the splash was only
  • 00:03:43
    the lightweight silicates none of the
  • 00:03:45
    iron the ring coalesced into the moon
  • 00:03:48
    and then the angular momentum coupling
  • 00:03:50
    drove the moon away from the earth and
  • 00:03:52
    tidally locked it circularized the orbit
  • 00:03:54
    so that's the current current theory for
  • 00:03:57
    what we think about the origin of the
  • 00:04:00
    Moon wouldn't it have been fun to be
  • 00:04:03
    there to watch an object the size of
  • 00:04:07
    Mars smash into the earth and form a
  • 00:04:12
    ring that turned into the moon in those
  • 00:04:14
    days the the length of an earth day was
  • 00:04:19
    on the order of six hours and the moon
  • 00:04:22
    was so close it would have filled the
  • 00:04:24
    sky and then the
  • 00:04:26
    angular momentum coupling drove the moon
  • 00:04:28
    farther and farther away and tidally
  • 00:04:30
    locked the moon to the earth the earth
  • 00:04:32
    slowed its rotation rate down to once
  • 00:04:35
    every 24 hours that process is
  • 00:04:37
    continuing the moon is getting farther
  • 00:04:38
    and farther away the earth continues to
  • 00:04:41
    slow down and it'll take about eleven
  • 00:04:43
    billion years before the earth finally
  • 00:04:45
    tidally locks to the moon we don't have
  • 00:04:49
    eleven billion years left so we don't
  • 00:04:51
    have to worry about that in any way
  • 00:04:52
    we're not supposed to be talking about
  • 00:04:53
    this I do want to talk about comments so
  • 00:04:57
    a complete change of topic let's talk
  • 00:05:00
    about comments what is the purpose of a
  • 00:05:03
    comment to explain the code that that
  • 00:05:12
    you can't use the code to explain yeah
  • 00:05:16
    okay fine that's fine um the purpose of
  • 00:05:19
    a comment is to explain the purpose of
  • 00:05:24
    code if the code can't explain its own
  • 00:05:27
    purpose can code explain itself well
  • 00:05:32
    generally it can now by the way it did
  • 00:05:34
    not used to be the case Fortran could
  • 00:05:38
    not explain itself there was no hope one
  • 00:05:41
    of the problems with Fortran is that
  • 00:05:44
    does anybody remember the length of a
  • 00:05:46
    name the maximum length of a name in
  • 00:05:48
    Fortran six characters right you can
  • 00:05:53
    have a name six characters long that was
  • 00:05:54
    it and in fact most languages in the
  • 00:05:57
    early days had a limit very much like
  • 00:05:59
    that I once worked on an assembler that
  • 00:06:01
    had a limit of four you can't get a lot
  • 00:06:03
    done with four basic the original basic
  • 00:06:07
    one letter one number that was it a 1 B
  • 00:06:11
    2 k5 those were your choices so it's
  • 00:06:14
    very difficult to get any kind of
  • 00:06:17
    explanation done when you've got limits
  • 00:06:19
    like that
  • 00:06:20
    today's languages are remarkably rich we
  • 00:06:25
    can have names that are very long we've
  • 00:06:27
    got structure in these languages classes
  • 00:06:30
    and variables and methods and namespaces
  • 00:06:34
    so we've got all these tools that we can
  • 00:06:37
    use to write code that explains
  • 00:06:40
    itself
  • 00:06:50
    I found this code on the internet I
  • 00:06:54
    don't know if it's real I have seen
  • 00:06:58
    enough like it to know that it could be
  • 00:07:02
    real this is bad really bad it's really
  • 00:07:08
    really bad hack if you're an employee of
  • 00:07:11
    inter Troad communication but I'm really
  • 00:07:14
    really sorry that you have to maintain
  • 00:07:15
    this I was honestly planning on removing
  • 00:07:18
    this tomorrow but I've been known to
  • 00:07:19
    forget things like this it happens no it
  • 00:07:24
    doesn't not if you are a professional
  • 00:07:27
    software developer it doesn't happen you
  • 00:07:29
    don't put an excuse like this in the
  • 00:07:31
    code now he might have done something
  • 00:07:34
    stupid here I'm not I'm not worried
  • 00:07:36
    about the stupid thing he did he was in
  • 00:07:37
    the middle of a production crisis and he
  • 00:07:39
    had a whole bunch of pressures on him so
  • 00:07:41
    he did something dumb that was okay the
  • 00:07:44
    problem I have is that he wrote this
  • 00:07:46
    comment and made an excuse for what he
  • 00:07:48
    did and checked it in and that's you
  • 00:07:52
    just don't do that do not check stuff
  • 00:07:55
    like that in so here's the thing I can't
  • 00:07:58
    seem to figure out why the account ID
  • 00:08:00
    variable isn't set and I've looked and
  • 00:08:01
    look but I gotta leave now well okay he
  • 00:08:04
    had to leave okay anyway I found that I
  • 00:08:07
    can just grab the account ID from the
  • 00:08:09
    debugging logs I suppose that to fix it
  • 00:08:16
    you'd have to locate where it's clearing
  • 00:08:17
    out the idea again I'm sorry okay so the
  • 00:08:20
    problem I have with this comment is that
  • 00:08:22
    it was irresponsibly checked into the
  • 00:08:25
    production source code control system I
  • 00:08:28
    have no real objection to what he did to
  • 00:08:30
    fix the problem in a minimun immediate
  • 00:08:32
    emergency that's fine but he should
  • 00:08:36
    never have checked that and he should
  • 00:08:37
    never have made this excuse whoever that
  • 00:08:39
    person was and then excuses the fact
  • 00:08:43
    that he's not going to fix it later
  • 00:08:44
    that's a problem so I want to talk about
  • 00:08:48
    comments and I use that as a preface but
  • 00:08:51
    let's talk about the right and the wrong
  • 00:08:54
    reasons to do comments nothing can be
  • 00:08:57
    quite so helpful as a good comment I say
  • 00:09:00
    that up front because most of what I'm
  • 00:09:02
    going to be doing is
  • 00:09:03
    ranting about comments so I want to make
  • 00:09:06
    it very clear upfront that not all
  • 00:09:08
    comments are bad some comments are great
  • 00:09:13
    on the other hand nothing can be quite
  • 00:09:16
    so obscuring as a bad comment comments
  • 00:09:20
    are not pure good many of us were taught
  • 00:09:26
    that comments were pure good we were
  • 00:09:31
    taught in school or we were taught by
  • 00:09:32
    early early books that everything should
  • 00:09:35
    be commented a programmer should comment
  • 00:09:38
    everything comment comment comment we
  • 00:09:40
    got to the point that we measured the
  • 00:09:42
    quality of the code by Counting the
  • 00:09:45
    comments which by the way it's really
  • 00:09:47
    easy to make high quality code if all
  • 00:09:49
    you're going to do is count the comments
  • 00:09:51
    this led to absurd kinds of comments
  • 00:09:56
    like AI + + / / increment I the proper
  • 00:10:06
    use of a comment is to compensate for
  • 00:10:09
    our failure to express ourselves in code
  • 00:10:13
    to the extent that we can express
  • 00:10:16
    ourselves in code we do not need
  • 00:10:18
    comments but we cannot perfectly express
  • 00:10:21
    ourself in code and so in those cases we
  • 00:10:25
    need comments every use of a comment
  • 00:10:29
    represents a failure a failure to
  • 00:10:33
    express yourself well in code this is
  • 00:10:35
    how I want you to look at comments
  • 00:10:37
    comments are not the kind of thing that
  • 00:10:39
    you pat yourself on the back for entail
  • 00:10:41
    good I was a good programmer I wrote
  • 00:10:43
    comments every comment you write is a
  • 00:10:46
    failure
  • 00:10:47
    now you will fail you will fail to
  • 00:10:49
    express yourself you will have to write
  • 00:10:51
    comments but you should look at every
  • 00:10:53
    comment as an unfortunate necessity not
  • 00:10:59
    a great achievement
  • 00:11:07
    why well one of the reasons is the
  • 00:11:11
    comments lie
  • 00:11:12
    now nobody intentionally write them up I
  • 00:11:15
    guess some people do but most people
  • 00:11:17
    don't intentionally write like comments
  • 00:11:19
    that lie but comments degrade over time
  • 00:11:23
    let me ask you this what color does your
  • 00:11:26
    IDE paint your comments in green like
  • 00:11:32
    the grass Oh gray Eve Gray's even better
  • 00:11:37
    soft gray ignore me gray I can't hurt
  • 00:11:41
    you great I don't bother you gray I'm
  • 00:11:44
    just part of the background gray we
  • 00:11:46
    paint our comments and colors that are
  • 00:11:49
    easy to ignore because we don't want to
  • 00:11:52
    see them we want to look at the code we
  • 00:11:54
    don't want to read the comments comments
  • 00:11:56
    gets in the way so we we make them fade
  • 00:11:59
    into the background now I changed my IDE
  • 00:12:01
    and I have my IDE paint comments in
  • 00:12:05
    bright red big staring glaring red
  • 00:12:09
    because I figure that if someone wrote
  • 00:12:11
    the comment I probably ought to read it
  • 00:12:13
    and then if I read the comment and I
  • 00:12:17
    think it's useless I will delete it and
  • 00:12:19
    that helps me get rid of a lot of
  • 00:12:21
    comments comments silently rot because
  • 00:12:25
    no one maintains them we paint them in a
  • 00:12:28
    color we can barely see so of course we
  • 00:12:30
    don't maintain them and no one reads the
  • 00:12:33
    comments when they're into the code
  • 00:12:34
    they're fiddling around in the code and
  • 00:12:35
    they're changing stuff around in the
  • 00:12:37
    code they don't read the comment that's
  • 00:12:38
    up here and so eventually the comment
  • 00:12:41
    starts to say things that have nothing
  • 00:12:42
    to do with the actual code
  • 00:12:44
    has anybody seen code anybody seen
  • 00:12:47
    comments that tell you to do exactly the
  • 00:12:49
    wrong thing you know they're 5 years old
  • 00:12:52
    and they tell you okay this is what
  • 00:12:54
    you've got to do when you read the codes
  • 00:12:55
    well if I did that that would crash
  • 00:12:57
    right but do we delete those comments do
  • 00:13:01
    we fix those comments or do we leave
  • 00:13:03
    them there because they're there for
  • 00:13:05
    posterity has anybody seen a comment
  • 00:13:12
    that is broken loose from the main body
  • 00:13:15
    of comments and migrated down into the
  • 00:13:18
    guts of the code
  • 00:13:19
    probably through copy/paste operations
  • 00:13:22
    where it hangs out there like a piece of
  • 00:13:24
    junk DNA just a fragment of a comment
  • 00:13:27
    hanging out there serving no purpose
  • 00:13:29
    whatever but no one will delete it
  • 00:13:33
    comments don't make up for bad code now
  • 00:13:36
    here's what happens you write a bunch of
  • 00:13:38
    code and you look at the code after
  • 00:13:41
    you're done with anything oh this is
  • 00:13:42
    awful and then you start to write a
  • 00:13:45
    comment I've better comment it because
  • 00:13:46
    this is really bad code I better comment
  • 00:13:48
    it no you should clean it don't comment
  • 00:13:51
    the code clean the code make the code
  • 00:13:53
    express your intent put the effort into
  • 00:13:56
    the code don't put the effort into the
  • 00:13:58
    comment if you finally fail at cleaning
  • 00:14:01
    the code then write the comment most of
  • 00:14:04
    the time however you will find a way to
  • 00:14:05
    make the code express itself explain
  • 00:14:14
    yourself in code not with comments so
  • 00:14:17
    here's an example the top says check to
  • 00:14:21
    see if the employee is eligible for full
  • 00:14:23
    benefits and then below that there's
  • 00:14:25
    this horrible boolean expression what
  • 00:14:27
    wouldn't it be nice if there were a
  • 00:14:28
    function called is eligible for full
  • 00:14:30
    benefits and then you could say if
  • 00:14:32
    employee that is eligible for full
  • 00:14:34
    benefits that reads a heck of a lot
  • 00:14:35
    better than that comment up there so
  • 00:14:39
    much better to use the names of
  • 00:14:42
    functions and variables to explain the
  • 00:14:44
    code than it is to use a comment to
  • 00:14:47
    explain the code now I'm going to walk
  • 00:14:50
    through a set of comments that I think
  • 00:14:54
    are I use the word good here on the
  • 00:14:57
    screen but that's not quite right these
  • 00:14:59
    comments are acceptable maybe I would
  • 00:15:04
    leave them I would not delete them and
  • 00:15:06
    I'm gonna walk through those and then
  • 00:15:08
    I'll walk through a batch of bad
  • 00:15:09
    comments copyrights
  • 00:15:14
    well okay I don't know what you're doing
  • 00:15:17
    in the Netherlands but in the United
  • 00:15:19
    States you've got to do this if you want
  • 00:15:20
    to protect your code and you have to
  • 00:15:23
    have this kind of weird punctuation so
  • 00:15:25
    fine we will leave the boilerplate code
  • 00:15:28
    up there
  • 00:15:30
    here's a comment
  • 00:15:32
    it's an informative comment and it's
  • 00:15:35
    really an interesting one it says it
  • 00:15:38
    returns an instance of the responder
  • 00:15:41
    being tested and then the function here
  • 00:15:44
    is responder instance now you could ask
  • 00:15:48
    this question why didn't he call this
  • 00:15:50
    responder being tested
  • 00:15:52
    why didn't he name it better why did he
  • 00:15:54
    have to have this comment there and the
  • 00:15:56
    answer is that he's using a design
  • 00:15:58
    pattern what design pattern is he using
  • 00:16:03
    singleton yeah now you might not like
  • 00:16:06
    the singleton pattern by the way who's
  • 00:16:07
    got the design patterns book and read it
  • 00:16:11
    yeah good yeah okay and the rest of you
  • 00:16:15
    who do not have this design patterns
  • 00:16:16
    book you must go out and buy the design
  • 00:16:18
    patterns book and read it and understand
  • 00:16:19
    it and then come back five years later
  • 00:16:21
    and read it and understand it again
  • 00:16:22
    it is probably the most important book
  • 00:16:24
    written within the last thirty years not
  • 00:16:27
    because it says anything new because
  • 00:16:29
    there's nothing new in that book it's
  • 00:16:32
    all about old stuff and what the design
  • 00:16:35
    patterns book does is it takes a bunch
  • 00:16:38
    of old ideas that have been around
  • 00:16:40
    forever and are still around today and
  • 00:16:41
    it gives them names and canonical forms
  • 00:16:45
    so that you and I can discuss singleton
  • 00:16:49
    or decorator or visitor or composite we
  • 00:16:55
    can talk about those things and if you
  • 00:16:56
    know these patterns if you know if
  • 00:16:59
    they're in your head then I can say to
  • 00:17:01
    you you know we could use a visitor for
  • 00:17:03
    that and the whole design pops into your
  • 00:17:05
    head
  • 00:17:06
    oh yeah we could use a visitor for that
  • 00:17:08
    and we could talk about the design at a
  • 00:17:11
    higher level of abstraction we could
  • 00:17:13
    discuss the patterns that we're going to
  • 00:17:16
    use to solve a problem if you are
  • 00:17:18
    reading code and you see the word report
  • 00:17:22
    visitor and you know that pattern the
  • 00:17:24
    design of that code pops into your head
  • 00:17:26
    if the author has been faithful to the
  • 00:17:28
    pattern the design of that code pops
  • 00:17:30
    into your head and all of a sudden you
  • 00:17:32
    know what to expect
  • 00:17:33
    inside that code it's very powerful very
  • 00:17:36
    important please know your design
  • 00:17:38
    patterns there are folks out there
  • 00:17:41
    nowadays who are saying design patterns
  • 00:17:43
    were so 1995 and now things are so
  • 00:17:46
    more modern and our languages nowadays
  • 00:17:48
    don't need pet it's complete nonsense
  • 00:17:51
    don't fall for that silly trick right
  • 00:17:54
    the design patterns are good things to
  • 00:17:56
    know and good things to have in your
  • 00:17:57
    head what happened here is that this guy
  • 00:18:01
    is using the singleton pattern the
  • 00:18:03
    singleton pattern canonical form has the
  • 00:18:07
    function using this naming pattern
  • 00:18:09
    responder instance so he could not name
  • 00:18:12
    it a better name and therefore he used
  • 00:18:14
    to comment to back himself up and that
  • 00:18:16
    was fun that's a comment that I would
  • 00:18:18
    leave there the pattern forced him to
  • 00:18:20
    use this name so he could not use a
  • 00:18:24
    better name fine he can use the comment
  • 00:18:27
    below that we see another kind of
  • 00:18:30
    informative comment which is to tell us
  • 00:18:35
    what this regular expression matches now
  • 00:18:37
    regular expressions are hideous horrible
  • 00:18:40
    syntaxes that no one understands it
  • 00:18:42
    looks like gobbledygook alright you look
  • 00:18:46
    at emergent expression and your eyes
  • 00:18:48
    kind of go oh so it's a really good idea
  • 00:18:52
    to have a comment telling you what the
  • 00:18:55
    regular expression is matching and
  • 00:18:57
    clearly you can see that his attempt
  • 00:18:59
    here is to match a timestamp he's gonna
  • 00:19:02
    match hours minutes seconds and then
  • 00:19:04
    whatever the heck of that is e
  • 00:19:06
    month/day/year
  • 00:19:07
    that's probably the time zone right so
  • 00:19:10
    okay that's fine I'm glad he told me
  • 00:19:13
    what he expected to match but do you
  • 00:19:16
    notice that the regular expression
  • 00:19:18
    actually matches much more than just
  • 00:19:21
    that his comment is lying to me the
  • 00:19:24
    regular expression does not just match
  • 00:19:26
    that timestamp it matches lots more than
  • 00:19:29
    that because of these stars so two-edged
  • 00:19:34
    sword he was informative but he also was
  • 00:19:37
    telling me a lie
  • 00:19:43
    here's a comment that I would leave and
  • 00:19:46
    I love the phrasing right when
  • 00:19:49
    programmers write comments they use such
  • 00:19:51
    interesting grammar right we are greater
  • 00:19:56
    because we are the right type I love
  • 00:19:59
    this right this is the Imperial weed we
  • 00:20:02
    are not amused so okay what he's trying
  • 00:20:07
    to tell us here is that this is the
  • 00:20:09
    compare to function in Java and this is
  • 00:20:13
    the canonical form of the compare to
  • 00:20:15
    function in Java and the first thing you
  • 00:20:16
    check of course is that the incoming
  • 00:20:18
    object is the right type okay well what
  • 00:20:21
    do you return if it's the wrong type and
  • 00:20:23
    so what he said here is look if it's the
  • 00:20:26
    wrong type than I'm going to say that
  • 00:20:28
    the this object is greater than the
  • 00:20:31
    incoming object we are greater because
  • 00:20:34
    we are the right type okay fine I could
  • 00:20:36
    have probably phrased it better but I at
  • 00:20:38
    least understand the intent I would
  • 00:20:40
    leave that comment there I might improve
  • 00:20:44
    the wording this is our best attempt to
  • 00:20:52
    get a race condition by creating a large
  • 00:20:54
    number of threads now you can see what
  • 00:20:56
    he's doing here he's going to create a
  • 00:20:58
    thousand threads and then he's going to
  • 00:21:03
    hope to get a race condition apparently
  • 00:21:06
    he's got some some multi-threaded thing
  • 00:21:08
    and he's expecting some kind of race to
  • 00:21:10
    happen this is a terrible way to make a
  • 00:21:12
    race condition by the way if you ever
  • 00:21:14
    want to make a race condition you don't
  • 00:21:16
    do it this way because this will just
  • 00:21:18
    set up a nice little resonance amongst
  • 00:21:20
    all the threads and they won't race
  • 00:21:21
    properly so we really want to test a
  • 00:21:23
    race condition you have to line up the
  • 00:21:25
    threads right at the race point with
  • 00:21:27
    some semaphores and then release the
  • 00:21:28
    semaphores and let the race continue so
  • 00:21:30
    he's using the wrong strategy but at
  • 00:21:34
    least he's telling me what he's going to
  • 00:21:36
    do here now he could have put this into
  • 00:21:38
    a function named attempt race condition
  • 00:21:42
    that would have been better
  • 00:21:43
    so I'm questionable about this comment I
  • 00:21:46
    think he probably should have put it
  • 00:21:47
    into a better named function and then of
  • 00:21:49
    course he should have learned how to
  • 00:21:50
    actually create a race condition
  • 00:21:54
    I wrote this probably about nine or ten
  • 00:22:00
    years ago now and the comments over here
  • 00:22:04
    were an attempt to deal with this
  • 00:22:06
    horrible optical illusion code is rife
  • 00:22:11
    with optical illusions we line things up
  • 00:22:14
    in code there are repeated patterns in
  • 00:22:17
    code and they make your eyes twist and
  • 00:22:19
    turn in strange ways so it's very easy
  • 00:22:22
    to create these bits of code that are
  • 00:22:24
    virtually impossible to see just because
  • 00:22:27
    of the optical illusion so you look in
  • 00:22:29
    here and holy cow you know they're all
  • 00:22:32
    assert truths at least there's no assert
  • 00:22:34
    false is in there and Hasen a B's and B
  • 00:22:37
    A's and B's and what the devil is going
  • 00:22:39
    on so I tried to explain over here what
  • 00:22:43
    the intent of these comparisons was and
  • 00:22:46
    it's successful on the other hand it's a
  • 00:22:50
    double-edged sword because a reader is
  • 00:22:52
    going to come along a person is going to
  • 00:22:54
    come along and try and read this code
  • 00:22:56
    and they will be drawn to the comments
  • 00:22:58
    and they will ignore the actual code if
  • 00:23:01
    those comments are wrong they'll never
  • 00:23:04
    see the real code so that's a bit of a
  • 00:23:07
    problem I have struggled with this batch
  • 00:23:10
    of code for many years trying to figure
  • 00:23:12
    out a way to get it to be expressive
  • 00:23:14
    this is one of those examples where it's
  • 00:23:15
    very hard to make this code express
  • 00:23:18
    itself well now here the programmer is
  • 00:23:25
    warning you
  • 00:23:29
    don't run that test until you've got
  • 00:23:32
    some time to kill and you can see why
  • 00:23:33
    you know what is that a 10 million he's
  • 00:23:36
    gonna write 10 million lines in a file
  • 00:23:38
    well that's going to take some time and
  • 00:23:41
    some of you may remember old j-unit you
  • 00:23:45
    know before we had all those @ signs and
  • 00:23:48
    Janet we the way you turned off a test
  • 00:23:51
    in Jane it was to put an underscore in
  • 00:23:53
    front of the name of the test and that
  • 00:23:56
    would turn the test off so what he's
  • 00:23:58
    telling us here is that this is a
  • 00:23:59
    disabled test and if you turn it on you
  • 00:24:02
    can expect some pretty hefty delays I
  • 00:24:04
    would leave the comment in seems
  • 00:24:07
    reasonable to me this is a comment that
  • 00:24:14
    I encourage you sometimes wonder you
  • 00:24:18
    know what the age was of the people who
  • 00:24:23
    wrote the Java library and you know what
  • 00:24:25
    were they kindergarten programmers or
  • 00:24:27
    something because sometimes the Java
  • 00:24:29
    library is full of code that is you know
  • 00:24:31
    very questionable this is one of those
  • 00:24:33
    cases simple date format is not
  • 00:24:36
    thread-safe they've got static variables
  • 00:24:38
    in simple date format and if you don't
  • 00:24:40
    know this and you don't anticipate it
  • 00:24:42
    then you're going to get caught in some
  • 00:24:43
    kind of a concurrent update problem so I
  • 00:24:46
    always encourage people to put that
  • 00:24:48
    comment in and say remember that simple
  • 00:24:50
    date format is not thread safe just as a
  • 00:24:55
    defensive measure when I wrote this
  • 00:25:02
    slide probably six years ago I thought
  • 00:25:07
    to do comments for a really good idea
  • 00:25:09
    that two new comments were brand new in
  • 00:25:12
    IntelliJ about six or seven years ago
  • 00:25:13
    and I thought it's so cool that you can
  • 00:25:16
    put this tutu in there and then you can
  • 00:25:18
    push a little button on the IDE and get
  • 00:25:20
    a whole list of all your to-do comments
  • 00:25:22
    that's just so cool and now I realize
  • 00:25:25
    that the word to do means don't do I
  • 00:25:29
    finally understand that and so now I see
  • 00:25:32
    code set code that is just loaded with
  • 00:25:34
    to do comments everywhere nobody ever
  • 00:25:36
    does them and so nowadays I have a
  • 00:25:39
    different rule for to do comments I will
  • 00:25:42
    use two
  • 00:25:43
    comments I will put them in but I will
  • 00:25:44
    not check them him to do comments must
  • 00:25:47
    either be done or deleted before I will
  • 00:25:49
    check the code in because once you check
  • 00:25:52
    it in it turns into it don't do so
  • 00:25:55
    that's my new rule for to do comments I
  • 00:26:02
    wrote this comment oh probably nine
  • 00:26:08
    years ago I was working on a system and
  • 00:26:11
    I I needed to put this trim in now trim
  • 00:26:17
    is one of those functions that it occurs
  • 00:26:20
    so often people use it so often and they
  • 00:26:24
    use it for reasons that are ignoring
  • 00:26:28
    because just you just call trim on all
  • 00:26:31
    kinds of if it comes in from the outside
  • 00:26:32
    world called trim on it so I wanted to
  • 00:26:35
    point out that this particular trim was
  • 00:26:37
    actually really important it was
  • 00:26:39
    actually doing something semantic inside
  • 00:26:42
    the algorithm so I amplified that with a
  • 00:26:44
    comment I didn't want people to just
  • 00:26:46
    ignore the trim
  • 00:26:51
    do you write Java Docs now I think Java
  • 00:26:57
    Docs are fine you know especially if you
  • 00:26:59
    are producing an API for the outside
  • 00:27:02
    world if you're going to be writing a
  • 00:27:04
    whole sub nice library for the outside
  • 00:27:07
    world of concern to consume then Java
  • 00:27:09
    Docs are fine but inside the team if
  • 00:27:13
    you're writing code that only the team
  • 00:27:15
    is going to see you don't need Java Docs
  • 00:27:17
    for that because the team ought to know
  • 00:27:20
    the structure of the code anyway and
  • 00:27:22
    code ought to have names that
  • 00:27:24
    communicate pretty well so I don't like
  • 00:27:27
    Java Docs unless they are for external
  • 00:27:31
    api's and even then I want them to be
  • 00:27:33
    pretty minimal okay bad comments
  • 00:27:43
    and for this I'm going to sit the
  • 00:27:47
    programmer here was talking to himself
  • 00:27:52
    notice where this comment is sitting
  • 00:27:54
    it's in the catch block that does
  • 00:27:57
    nothing now that's weird all by itself
  • 00:28:02
    notice what the the code is doing right
  • 00:28:05
    he's got some file that he opens up it's
  • 00:28:08
    a properties file oh thank you for that
  • 00:28:10
    oh that was for me so that screen is
  • 00:28:13
    okay yep got it
  • 00:28:14
    he's opening up a properties file and
  • 00:28:17
    then he's going to load the properties
  • 00:28:19
    from some from that file and then
  • 00:28:21
    there's this i/o exception that he
  • 00:28:23
    catches and he says no properties files
  • 00:28:26
    means all defaults are loaded where are
  • 00:28:32
    all the defaults loaded how do I know
  • 00:28:35
    that's true he says it here he asserts
  • 00:28:37
    it that all the defaults are gonna be
  • 00:28:39
    loaded here
  • 00:28:39
    I don't know that true I don't see the
  • 00:28:40
    code that loads all the defaults he's
  • 00:28:42
    talking about some code somewhere else
  • 00:28:44
    and here it is he's talking about some
  • 00:28:47
    code that's in some different place I
  • 00:28:49
    don't know if that code is still there
  • 00:28:50
    I don't know if this is true or not this
  • 00:28:53
    helps me not at all I understand why he
  • 00:28:55
    did what he did he's assuming that all
  • 00:28:57
    the defaults are gonna be loaded but I
  • 00:29:00
    don't know that that's actually taking
  • 00:29:01
    place so I looked at this and think well
  • 00:29:04
    this guy was just talking to himself it
  • 00:29:06
    was justifying why he was catching the
  • 00:29:09
    exception and then simply ignoring it
  • 00:29:11
    what he probably should have done here
  • 00:29:13
    is load the default he'd loaded the
  • 00:29:15
    defaults here then I wouldn't have to we
  • 00:29:17
    wouldn't have to have the comment it
  • 00:29:18
    would be very clear what was going on
  • 00:29:20
    but he did this instead now here's a
  • 00:29:27
    comment that is harder to read than the
  • 00:29:30
    code utility method that returns when
  • 00:29:34
    this stock closed is true throws an
  • 00:29:35
    exception if the timeout is reached okay
  • 00:29:38
    now first of all it's wrong it just it
  • 00:29:41
    describes the way this function works
  • 00:29:43
    but it describes it incorrectly because
  • 00:29:44
    it there are ways to return from this
  • 00:29:47
    this function that it doesn't talk about
  • 00:29:49
    and second of all it's easier to read
  • 00:29:51
    the code you know while we're not closed
  • 00:29:52
    on the timeouts greater than zero then
  • 00:29:54
    wait 100
  • 00:29:55
    decrement the time out that's pretty
  • 00:29:57
    simple to read so I think the comment is
  • 00:29:59
    not only useless it's worse than useless
  • 00:30:04
    this kind of stuff makes me nuts what
  • 00:30:09
    what motivated this guy to put a comment
  • 00:30:13
    in front of every single variable not
  • 00:30:16
    only that they're javadocs
  • 00:30:17
    these are Java Docs and look at them the
  • 00:30:21
    child containers belonging to this
  • 00:30:23
    container keyed by name now first of all
  • 00:30:25
    the word container is a strange word and
  • 00:30:28
    he can't seem to be can't seem to make
  • 00:30:31
    up his mind whether he wants to use
  • 00:30:32
    container a component so sometimes he
  • 00:30:34
    uses component in sometimes container
  • 00:30:36
    he always capitalizes container I don't
  • 00:30:40
    know why it's just it's a very strange
  • 00:30:43
    thing the child containers belonging to
  • 00:30:46
    this container keyed by name well it's a
  • 00:30:48
    hashmap
  • 00:30:49
    yeah it's keyed by name and what's the
  • 00:30:51
    name of it children okay
  • 00:30:52
    bunch of children keyed by name I don't
  • 00:30:54
    need the comment to tell me that the
  • 00:30:56
    processor delay for this component
  • 00:30:57
    background processor delay the variable
  • 00:31:00
    name says more than the comment does
  • 00:31:01
    life cycle support event for this
  • 00:31:04
    component life cycle support container
  • 00:31:06
    event listeners listeners loader
  • 00:31:08
    implementation loader logger
  • 00:31:10
    implementation logger all these comments
  • 00:31:13
    are completely useless I don't know why
  • 00:31:15
    he put them in there I believe he was
  • 00:31:17
    motivated by some strange urge to
  • 00:31:21
    comment everything because comments are
  • 00:31:22
    good I would much rather those comments
  • 00:31:26
    be ripped out of there I already talked
  • 00:31:32
    about that one has anybody seen a coding
  • 00:31:36
    standard that mandates comments thou
  • 00:31:39
    shalt put comments on every function
  • 00:31:42
    thou shalt put comments on every class
  • 00:31:43
    this is stupid and you must find the per
  • 00:31:47
    people who wrote those that coding
  • 00:31:50
    standard and inform them that this is
  • 00:31:52
    stupid
  • 00:31:53
    because you don't want to ever mandate
  • 00:31:55
    comments when you mandate comments you
  • 00:31:58
    get stupid comments that's when people
  • 00:32:01
    will write the dumbest doggone thing so
  • 00:32:03
    here
  • 00:32:08
    this is stupid now what really gets me
  • 00:32:20
    about this one is that this is a Java
  • 00:32:24
    doc right and the purpose of Java doc is
  • 00:32:26
    to run the Java doc tool to generate the
  • 00:32:28
    HTML that perforates the nice little
  • 00:32:31
    webpage for you right then and if you
  • 00:32:34
    take that comment out and run the Java
  • 00:32:38
    doc tool it will generate virtually the
  • 00:32:41
    identical HTML because the Java doc tool
  • 00:32:46
    is smart enough to look at the class and
  • 00:32:47
    and say okay title author tracks
  • 00:32:50
    duration in minutes I would miss a
  • 00:32:52
    couple of things I guess but almost no
  • 00:32:56
    difference in the HTML and somebody's
  • 00:32:57
    told him he had to put that kind of crap
  • 00:32:59
    in there
  • 00:33:12
    long long ago in the deep dark past when
  • 00:33:18
    we did not have source code control
  • 00:33:20
    systems we would put the journal
  • 00:33:24
    comments in the first part of the source
  • 00:33:26
    file this is something we all did but
  • 00:33:29
    nowadays we have source code control
  • 00:33:31
    systems what what source code control
  • 00:33:33
    system are you using git see there get
  • 00:33:37
    good good that's the right one ok so
  • 00:33:43
    nowadays we can put all of our journal
  • 00:33:47
    comments and to get we don't have to put
  • 00:33:50
    them in to the beginning of the source
  • 00:33:53
    file so I hope nobody is doing this and
  • 00:33:56
    if you find any of that stuff in the
  • 00:33:58
    source code you could probably get rid
  • 00:33:59
    of it now
  • 00:34:00
    what would happen if you deleted it you
  • 00:34:03
    would still be in git
  • 00:34:05
    you're not going to delete it right you
  • 00:34:07
    delete stuff out of a source file it
  • 00:34:09
    stays in git you don't have to worry
  • 00:34:12
    about the fact I hold I'm gonna delete
  • 00:34:13
    this stuff don't do this please don't do
  • 00:34:17
    this
  • 00:34:18
    it is the dumbest thing to do it's also
  • 00:34:22
    insulting you know I know that's a
  • 00:34:24
    default constructor I'm a Java
  • 00:34:26
    programmer who the hell do you think
  • 00:34:27
    you're talking to
  • 00:34:34
    now this one this was a little bit scary
  • 00:34:39
    and because you got that last one wrong
  • 00:34:43
    all right little copy-paste going on
  • 00:34:47
    here I found this one in Tomcat and I
  • 00:34:55
    was fascinated by it because I still
  • 00:34:58
    don't understand the comment it's been
  • 00:35:00
    years now right
  • 00:35:01
    does the module from the global list mod
  • 00:35:05
    in angle brackets I don't know why the
  • 00:35:07
    angle brackets out there depend on the
  • 00:35:10
    subsystem we are part of I can't I can't
  • 00:35:16
    understand that comment but I was able
  • 00:35:20
    to use the IDE to extract out variables
  • 00:35:24
    so at the bottom you see how I extracted
  • 00:35:27
    out the variables I extracted out module
  • 00:35:32
    dependencies from s module get depends
  • 00:35:36
    subsystem so you can see that here as
  • 00:35:38
    module that gets depends subsystem is
  • 00:35:40
    there I extracted that out into a
  • 00:35:42
    variable called module dependencies the
  • 00:35:44
    IDE told me what the type was so that's
  • 00:35:48
    cool ArrayList of module ok cool these
  • 00:35:51
    are the modules I guess that are that we
  • 00:35:54
    are part of maybe I don't know and then
  • 00:35:56
    I extracted out the other part you know
  • 00:35:59
    subsys mod get subsystem and I called
  • 00:36:02
    that our subsystem and the IDE told me
  • 00:36:05
    that was a module and now look at the if
  • 00:36:07
    statement if module dependencies
  • 00:36:10
    contains our subsystem I love the way
  • 00:36:12
    this reads I don't know if it matches
  • 00:36:15
    the intent of the comment because I
  • 00:36:17
    can't still can't understand the comment
  • 00:36:22
    don't do this it's stupid you do not
  • 00:36:28
    have to yell and then tell me that these
  • 00:36:31
    are instance variables right I know that
  • 00:36:33
    their instance variables you don't have
  • 00:36:35
    to do that sometimes it is important to
  • 00:36:38
    yell in a comment right sometimes you
  • 00:36:42
    want to do that sometimes you are saying
  • 00:36:43
    something that you really want to
  • 00:36:45
    attract attention to and then it is
  • 00:36:46
    appropriate to put some kind
  • 00:36:48
    you know big flag in there like this but
  • 00:36:50
    if you use that for instance variables
  • 00:36:53
    no one will ever pay any more attention
  • 00:36:55
    to your big red flags so this is like
  • 00:36:57
    the little boy who called wolf don't do
  • 00:37:00
    that stuff it's pure clutter does
  • 00:37:03
    anybody do that anymore
  • 00:37:06
    the comments on the closing braces
  • 00:37:09
    remember there was a time than our IV
  • 00:37:11
    eat well over the time we didn't have IV
  • 00:37:12
    ease you know in the 80s when we were
  • 00:37:15
    when we were coding in VI with text
  • 00:37:18
    files how did you keep track of your
  • 00:37:20
    closing braces and this was one of the
  • 00:37:22
    techniques but it's probably not
  • 00:37:24
    necessary anymore
  • 00:37:26
    this is graffiti you do not have to tell
  • 00:37:33
    me that you were here the source code
  • 00:37:36
    control system will remember so if we
  • 00:37:39
    need to know who to blame we can find
  • 00:37:41
    out of all the sins of comments
  • 00:37:47
    commented out code is the worst of them
  • 00:37:50
    all it is a is it an abomination before
  • 00:37:53
    nature and nature's God when I see
  • 00:37:55
    commented out code I don't read it I
  • 00:37:58
    don't try to understand it I just delete
  • 00:38:00
    it and get it out of the system
  • 00:38:03
    commented out code is a horror now
  • 00:38:06
    people get very upset about that you
  • 00:38:08
    can't delete that code someone might
  • 00:38:09
    need it one day well if they need it
  • 00:38:11
    it's in the source code control system
  • 00:38:12
    so they can go back and look for it
  • 00:38:14
    there but I'm not going to tolerate it
  • 00:38:16
    sitting in a module like this do I
  • 00:38:19
    comment out code yes while I'm doing
  • 00:38:22
    experiments but I will not check it in I
  • 00:38:24
    will not check in commented out code
  • 00:38:26
    look at this what does it mean header
  • 00:38:30
    pause equals bite pause did it first of
  • 00:38:32
    all is it code it's got a semicolon
  • 00:38:34
    after it so that's a pretty good
  • 00:38:35
    indication that it's code why is it
  • 00:38:39
    there
  • 00:38:39
    is there a variable called header pause
  • 00:38:41
    I don't know Dana posi equals bypass
  • 00:38:44
    thank you I don't know why that's there
  • 00:38:46
    I'm going to delete it gonna get rid of
  • 00:38:48
    it do not let put commented out code in
  • 00:38:51
    don't check it in this is somebody who
  • 00:38:57
    wanted to write a really pretty Java doc
  • 00:39:01
    so we loaded it up with all kinds of
  • 00:39:04
    HTML macros and crud like that
  • 00:39:08
    forgetting that the place you want the
  • 00:39:11
    comments to be most readable is in the
  • 00:39:14
    code the fact that you've got a Java doc
  • 00:39:17
    tool that scrapes out HTML and does a
  • 00:39:19
    nice little print job for you is fine
  • 00:39:21
    you can use that tool but the place you
  • 00:39:26
    want the comments most readable is in
  • 00:39:29
    the code so you don't want to obscure
  • 00:39:31
    your comments with a whole bunch of HTML
  • 00:39:33
    and make them unreadable and force
  • 00:39:35
    people to run the Javadoc tool and then
  • 00:39:37
    look at it on the on the web page if
  • 00:39:39
    you're gonna write a comment make sure
  • 00:39:42
    it's readable in the code for that
  • 00:39:43
    reason I don't tolerate HTML in my java
  • 00:39:46
    - no one can put HTML in a java doc I'm
  • 00:39:50
    just to use some other mechanism to
  • 00:39:52
    format it so I will tolerate a pre and
  • 00:39:55
    end pre in the giant as the HTML and the
  • 00:39:59
    Java doc which keeps all these fonts
  • 00:40:01
    mono spaced port on which Fitness would
  • 00:40:08
    run defaults to 8080 - it does where do
  • 00:40:13
    I see that 8080 to where here is this
  • 00:40:15
    8080 - there's a fundamental rule about
  • 00:40:17
    comments right you never talked about
  • 00:40:19
    code that's somewhere else if you write
  • 00:40:22
    a comment you only talk about the code
  • 00:40:23
    that's right there because if you talk
  • 00:40:26
    about code that's somewhere else that
  • 00:40:27
    codes going to change and your comment
  • 00:40:29
    will turn into a lie for the same reason
  • 00:40:32
    you never put where used lists in
  • 00:40:34
    comments because those where of used
  • 00:40:36
    lists will change like crazy as well
  • 00:40:40
    here's somebody who simply did not want
  • 00:40:42
    to write the code they wanted to write
  • 00:40:44
    about the code so they wrote a whole
  • 00:40:47
    little essay
  • 00:40:53
    I hope I drove the point home comments
  • 00:41:00
    aren't bad but I don't want you write in
  • 00:41:03
    comments by default I don't want you in
  • 00:41:05
    the mindset of saying I've got to write
  • 00:41:07
    a whole bunch of comments now if you're
  • 00:41:10
    going to write a comment you need a good
  • 00:41:11
    reason to write a comment because what
  • 00:41:13
    you should be doing is making the codes
  • 00:41:16
    speak for itself to the greatest extent
  • 00:41:18
    possible and then if you fail at that
  • 00:41:22
    well then you'll maybe you'll have to
  • 00:41:24
    write a comment
  • 00:41:44
    how long should a source file be how
  • 00:41:51
    many lines should there be in a source
  • 00:41:52
    file this is not an easy question to
  • 00:41:57
    answer it's not like you know the the
  • 00:41:59
    one thing the one rule principle it's
  • 00:42:03
    not like that this is something else
  • 00:42:05
    so so I did a little study
  • 00:42:08
    I took seven projects that I found off
  • 00:42:10
    the off the internet and I analyzed
  • 00:42:14
    their file sizes and I found something
  • 00:42:16
    really interesting so here's the the
  • 00:42:19
    seven projects one of them is j-unit
  • 00:42:21
    this was probably 2001 mm maybe 2005
  • 00:42:26
    when I did this and notice that Janet is
  • 00:42:30
    like 6,000 lines of code and the the
  • 00:42:37
    plot here is called a box plot so this
  • 00:42:40
    is the smallest file this is the biggest
  • 00:42:43
    file this is one standard deviation and
  • 00:42:47
    the mean is right in the middle right so
  • 00:42:50
    j-unit which is about 6,000 lines of
  • 00:42:53
    code has a whole bunch of modules inside
  • 00:42:56
    it but those modules the smallest module
  • 00:42:58
    is four lines of code the biggest line
  • 00:43:02
    module is two hundred three hundred four
  • 00:43:04
    five hundred lines of code
  • 00:43:06
    the average module is around 20 30 40 50
  • 00:43:11
    lines of code and most of them are
  • 00:43:14
    between 130 that's that's pretty good
  • 00:43:18
    that's pretty standard notice there's a
  • 00:43:20
    log scale here all right so as you move
  • 00:43:23
    up it changes a lot Fitness this is
  • 00:43:27
    another project it's about 50 thousand
  • 00:43:30
    lines of code so much larger than j-unit
  • 00:43:32
    but almost an identical structure this
  • 00:43:36
    is interesting because you would expect
  • 00:43:37
    that large projects would have a
  • 00:43:39
    different structure they'd have a
  • 00:43:40
    different different statistical array of
  • 00:43:43
    file sizes but that does not appear to
  • 00:43:45
    be the case
  • 00:43:45
    Fitness much larger than Jane it has the
  • 00:43:48
    same structure test ng sng is a tool
  • 00:43:53
    similar to j-unit it's because 72
  • 00:43:56
    thousand lines of
  • 00:43:57
    which makes you wonder what the hell it
  • 00:43:59
    does and it has a wildly different
  • 00:44:04
    structure interesting and so I'm not
  • 00:44:07
    quite sure what that's about but the you
  • 00:44:09
    know there's a big file in there looks
  • 00:44:11
    like 1500 lines of code
  • 00:44:13
    the average is like 40 lines of code but
  • 00:44:17
    there's a huge standard deviation so
  • 00:44:19
    he's got no regularity to the size of
  • 00:44:21
    the files time and money
  • 00:44:24
    that's about 6,000 lines of code that's
  • 00:44:26
    Eric Evans example of domain driven
  • 00:44:28
    design very similar structure to fitness
  • 00:44:32
    and J in it
  • 00:44:34
    J depends JD Ben is really old it was
  • 00:44:37
    probably written in 98 about 7,000 lines
  • 00:44:40
    of code and a slightly different
  • 00:44:42
    structure looks like his average file
  • 00:44:44
    size is about 120 he's got a couple of
  • 00:44:48
    big files in there although they're not
  • 00:44:49
    really big it's just that the average
  • 00:44:51
    seems to be larger than usual and I
  • 00:44:53
    think the reason for that is that he
  • 00:44:55
    Javadoc everything and that just drove
  • 00:44:58
    his file sizes up a little bit aunt
  • 00:45:03
    200,000 lines of code and aunt
  • 00:45:06
    the average file of sizes around 200
  • 00:45:09
    lines that's pretty big he's got a
  • 00:45:11
    couple of big files in there is one
  • 00:45:13
    that's 2,000 lines long Tomcat 384
  • 00:45:17
    thousand lines of code look at that man
  • 00:45:18
    2 average size is about 200 lines he's
  • 00:45:22
    got a file in there with 5,000 lines in
  • 00:45:26
    it now what I find interesting about
  • 00:45:30
    this is that there's no correlation
  • 00:45:32
    between file size and distribution right
  • 00:45:38
    you've got a couple of big ones a small
  • 00:45:40
    one here and a big one here and another
  • 00:45:42
    small one there and a slightly larger
  • 00:45:44
    one there I'll have roughly the same
  • 00:45:46
    correlation we've got really big ones
  • 00:45:47
    out here and a small one here that you
  • 00:45:50
    know there's no correlation there so
  • 00:45:53
    what that tells me is that file size is
  • 00:45:58
    not a function of project size file size
  • 00:46:01
    is a style that you can impose upon your
  • 00:46:04
    system and since that's true what style
  • 00:46:07
    would you like to impose on your system
  • 00:46:10
    how big should
  • 00:46:11
    your files be and it looks here like you
  • 00:46:14
    can build a fairly significant system
  • 00:46:16
    with files that are on the average 50
  • 00:46:19
    lines long most of them are less than a
  • 00:46:21
    hundred lines
  • 00:46:22
    that's probably nice so that might be a
  • 00:46:26
    a goal to strive for I'll come back to
  • 00:46:39
    that stuff because I want to do another
  • 00:46:42
    statistical analysis this one this is an
  • 00:46:45
    interesting analysis of the length of
  • 00:46:47
    lines same projects but the length of
  • 00:46:51
    the lines in the projects and look at
  • 00:46:54
    the interesting correlation here every
  • 00:46:56
    color is a different project but look at
  • 00:46:59
    how they follow the same interesting
  • 00:47:00
    curve now this is a histogram
  • 00:47:03
    it's a histogram of line length so this
  • 00:47:06
    is the number of these this is a line
  • 00:47:08
    length down here and the vertical scale
  • 00:47:11
    is the percentage of lines that have
  • 00:47:13
    that length and notice that the vertical
  • 00:47:15
    scale is a log scale so there's a lot of
  • 00:47:20
    lines that have no length these are
  • 00:47:23
    probably blank lines and and then they
  • 00:47:26
    fall off pretty rapidly to a minimum
  • 00:47:28
    here of about 12 and then there's this
  • 00:47:32
    gradual climb look at the look at how
  • 00:47:34
    tight that's clustered these seven
  • 00:47:37
    wildly different java applications but
  • 00:47:40
    really tight clustering right in here
  • 00:47:42
    with a peak and they all peak about the
  • 00:47:44
    same place right around 3035 something
  • 00:47:47
    like that lines of code where 1% of the
  • 00:47:49
    lines of code now are at this level and
  • 00:47:52
    then it starts to fall off and this
  • 00:47:54
    looks like a slow fall off but this is a
  • 00:47:55
    log scale so it's actually a very rapid
  • 00:47:57
    fall off you get to about here and
  • 00:48:00
    realized that nobody wants to see any
  • 00:48:02
    lines that are longer than about 80 so
  • 00:48:05
    this is the interesting part of that
  • 00:48:07
    curve and what I find fascinating about
  • 00:48:10
    it is that it's that all seven of these
  • 00:48:13
    projects follow the same curve so it
  • 00:48:16
    seems that we have a preference for
  • 00:48:19
    lines that are on the order of 30 to 40
  • 00:48:23
    line 40 characters long
  • 00:48:25
    is that a change in well so that's
  • 00:48:34
    interesting yes lines the screens are
  • 00:48:36
    getting bigger is that having an effect
  • 00:48:39
    on our line lengths and this argues that
  • 00:48:42
    it's not because look at how look at how
  • 00:48:44
    small that is that Peaks it's in there
  • 00:48:46
    right around 40 35 40 right so the fact
  • 00:48:51
    that our screens are getting bigger does
  • 00:48:52
    not seem to be affecting the
  • 00:48:55
    distribution of line lengths I find that
  • 00:48:57
    to be very interesting now what does it
  • 00:48:59
    tell us about what kind of guidance does
  • 00:49:01
    it give us well I think the guidance is
  • 00:49:03
    pretty obvious you want your lines to be
  • 00:49:05
    on the order of 30 or 40 characters long
  • 00:49:07
    you don't want very many that go beyond
  • 00:49:09
    maybe 80 I actually have a a barrier put
  • 00:49:13
    into my IDE at 150
  • 00:49:16
    I will not go beyond 150 and I do that
  • 00:49:19
    because I believe it is rude to make
  • 00:49:22
    your readers scroll to the right so all
  • 00:49:26
    the codes should fit on the screen and
  • 00:49:30
    you should not make your your readers
  • 00:49:32
    scroll to the right if you make them
  • 00:49:34
    scroll to the right they won't and then
  • 00:49:36
    you can hide all kinds of crap out there
  • 00:49:38
    yeah
  • 00:49:50
    do they have different functions yeah I
  • 00:49:55
    don't know I didn't do that analysis
  • 00:49:57
    it's an interesting interesting thing to
  • 00:49:58
    do we have an awful lot of code now so
  • 00:50:01
    there's very interesting analyses that
  • 00:50:03
    we can do like this but I didn't do that
  • 00:50:05
    one anybody else have a question on this
  • 00:50:08
    good ok
  • 00:50:17
    show them let's talk about names
  • 00:50:27
    and see where's our names that goes to
  • 00:50:32
    about here there we go
  • 00:50:45
    early in programming we didn't have a
  • 00:50:47
    lot of options with names like I told
  • 00:50:49
    you before we were limited to like six
  • 00:50:50
    characters nowadays that limitation is
  • 00:50:53
    long gone so we can have names that are
  • 00:50:55
    as long as we want and we name things we
  • 00:50:58
    do a lot of naming in software we named
  • 00:51:00
    files and directories and programs and
  • 00:51:02
    classes and namespace and variables and
  • 00:51:04
    arguments we name all kinds of things
  • 00:51:06
    and because we do so much of it we
  • 00:51:08
    probably ought to be good at it so let's
  • 00:51:10
    talk about some rules for naming things
  • 00:51:14
    with the the rules that I'm going to
  • 00:51:17
    show you here are old they've been
  • 00:51:20
    around for a very long time they're
  • 00:51:22
    derived from Tim Ottinger 's list of
  • 00:51:26
    naming rules that has been very popular
  • 00:51:28
    circled around the internet for years
  • 00:51:31
    very obviously you want to reveal your
  • 00:51:34
    intent in a name so I'm going to give
  • 00:51:36
    you a couple of examples here is int D a
  • 00:51:40
    good name for a elapsed time in days now
  • 00:51:45
    your original thought would be well no
  • 00:51:46
    of course not because D is just a one
  • 00:51:48
    letter name that's awful but wait a
  • 00:51:51
    minute
  • 00:51:52
    how long should a variable name be
  • 00:51:57
    what's the rule for the length of a
  • 00:52:00
    variable name now consider the for loop
  • 00:52:03
    for I equals 0 I less than 10 I plus
  • 00:52:06
    plus do you want that eye to be
  • 00:52:07
    something other than I the answer that
  • 00:52:11
    is probably not and so there's there
  • 00:52:14
    does seem to be a place for single
  • 00:52:16
    letter variable names like I so what's
  • 00:52:19
    the rule what is the rule for the length
  • 00:52:22
    of a variable name and here's the rule
  • 00:52:24
    that I use a variable name should be
  • 00:52:28
    proportional to the size of the scope
  • 00:52:31
    that contains it if the scope is very
  • 00:52:35
    small like one line a single letter is
  • 00:52:38
    fine you don't want to have anything
  • 00:52:39
    else if it's a one line scope you don't
  • 00:52:42
    want to have anything else a single
  • 00:52:43
    letter is great D would be a perfectly
  • 00:52:46
    valid name for a date
  • 00:52:47
    if D existed only in a single line
  • 00:52:51
    because you wouldn't lose the context
  • 00:52:53
    you wouldn't need the name to remind you
  • 00:52:55
    of anything the function call that
  • 00:52:57
    generated the name would
  • 00:52:59
    enough long scopes need long names so
  • 00:53:04
    let's walk through the hierarchy here
  • 00:53:06
    inside of a an if statement you've got
  • 00:53:10
    maybe a couple of lines in that if
  • 00:53:12
    statement variables inside that if
  • 00:53:14
    statement ought to be very short
  • 00:53:16
    variables inside of a really tiny while
  • 00:53:18
    loop should be very short if you have a
  • 00:53:20
    function and that function is four lines
  • 00:53:23
    long the variables inside that function
  • 00:53:26
    should probably be pretty short because
  • 00:53:29
    it's four lines long maybe they'd have
  • 00:53:30
    to be a little bit longer arguments
  • 00:53:32
    would probably be a little bit longer a
  • 00:53:34
    word would probably be good for an
  • 00:53:36
    argument instance variables live inside
  • 00:53:39
    a class they have a slightly longer
  • 00:53:41
    scope they have the scope of the class
  • 00:53:43
    so probably an instance variable should
  • 00:53:45
    be long ish two words may be functions
  • 00:53:50
    the arguments to a member function
  • 00:53:52
    probably a word global functions mobile
  • 00:53:58
    functions have a huge scope they better
  • 00:54:00
    be very long got global variables sorry
  • 00:54:02
    global variables have a huge scope so
  • 00:54:04
    they should probably be very long
  • 00:54:10
    variables should have a length
  • 00:54:13
    proportional to the scope that contains
  • 00:54:15
    them what's the rule for functions
  • 00:54:19
    exactly the opposite
  • 00:54:22
    exactly the opposite the bigger the
  • 00:54:24
    scope the smaller the name for a
  • 00:54:26
    function and for very obvious reasons we
  • 00:54:29
    would not want to call the open function
  • 00:54:32
    if the name of the open function was
  • 00:54:34
    open file and throw exception if not
  • 00:54:36
    found as ace as the scope of the
  • 00:54:41
    function gets larger we want the name to
  • 00:54:44
    shrink we want the name to shrink
  • 00:54:46
    because we're going to call it more a
  • 00:54:48
    function that lives in a large scope
  • 00:54:50
    will be called from all over the place
  • 00:54:51
    so we want to shrink the name down
  • 00:54:53
    moreover if the function is in a large
  • 00:54:56
    scope it must be abstract it must be
  • 00:54:59
    dealing with a high level abstraction so
  • 00:55:01
    we want the name to be short as the
  • 00:55:05
    scope containing a function decreases
  • 00:55:08
    the name starts to get longer so the
  • 00:55:11
    instance variance
  • 00:55:12
    since methods of a class will probably
  • 00:55:15
    have slightly longer names private
  • 00:55:17
    functions called by public functions
  • 00:55:20
    will have even longer names private
  • 00:55:22
    functions called by private functions
  • 00:55:24
    will have even longer names you can
  • 00:55:27
    continue down that hierarchy for a very
  • 00:55:29
    long time especially if you're
  • 00:55:30
    extracting until you drop as you'll
  • 00:55:32
    extract and extract and extract and all
  • 00:55:34
    these extracted functions are going to
  • 00:55:35
    be private and every time you go down
  • 00:55:37
    another level the name gets longer and
  • 00:55:39
    longer and longer and it gets longer
  • 00:55:41
    because the function becomes more
  • 00:55:43
    precise it does something really tiny
  • 00:55:45
    really precise that you need words to
  • 00:55:48
    specify so the name of a function is
  • 00:55:53
    inversely proportional to the size of
  • 00:55:56
    the scope that contains it
  • 00:55:59
    what about classes same as functions
  • 00:56:03
    size of a class name is inversely
  • 00:56:06
    proportional to the size of the scope
  • 00:56:08
    that contains it classes at the global
  • 00:56:10
    scope have one word names derived
  • 00:56:12
    classes have multiple word names inner
  • 00:56:14
    classes have multiple word names as the
  • 00:56:17
    scope shrinks the name grows so that's a
  • 00:56:21
    reasonable rule for naming things or at
  • 00:56:25
    least controlling name length therefore
  • 00:56:28
    if d is not necessarily a bad name for
  • 00:56:31
    this variable as long as the scope that
  • 00:56:33
    it was contained in was small if the
  • 00:56:35
    scope was long than elapsed time in days
  • 00:56:37
    is perfectly reasonable what does that
  • 00:56:42
    function do take a look at it
  • 00:56:46
    spend a little time
  • 00:56:54
    it gets them what does it get well it
  • 00:57:01
    walks through a list and it interrogate
  • 00:57:04
    the first element of each list and if
  • 00:57:06
    that first element is a four then it
  • 00:57:10
    adds it to the output list list one
  • 00:57:12
    which it returns excellent good now we
  • 00:57:15
    know what this does it scans a list for
  • 00:57:20
    first elements four elements whose first
  • 00:57:24
    element is a four and then it returns
  • 00:57:27
    only those lists that have that okay
  • 00:57:30
    good I think I got that right that's the
  • 00:57:33
    same code but this changes everything
  • 00:57:41
    the the names here tell you what's going
  • 00:57:45
    on inside this function it's getting all
  • 00:57:46
    the flagged cells oh there are cells and
  • 00:57:49
    the cells are part of a game board and
  • 00:57:52
    every cell has a status value and if
  • 00:57:54
    that status value is flagged then we're
  • 00:57:57
    going to return that cell so this
  • 00:57:59
    function returns all the flagged cells
  • 00:58:02
    now notice what this nice naming system
  • 00:58:05
    does this naming system does more than
  • 00:58:07
    just make it easier to understand the
  • 00:58:09
    function it also tells you what program
  • 00:58:11
    contains the function this program is in
  • 00:58:14
    some kind of a game this function is in
  • 00:58:16
    some kind of a game probably minesweeper
  • 00:58:19
    if you know minesweeper of course nobody
  • 00:58:21
    knows minesweeper anyway because nobody
  • 00:58:23
    has that old desktop accessory from
  • 00:58:25
    Windows anymore but okay a good system
  • 00:58:31
    of names tells you not just about the
  • 00:58:34
    function you're working on but it tells
  • 00:58:36
    you about the entire context of the
  • 00:58:38
    system so that's the power of a good
  • 00:58:41
    system of names
  • 00:58:47
    let's see you gotta watch out for this
  • 00:58:50
    what's the first place where these two
  • 00:58:53
    variables differ that some of you
  • 00:59:03
    probably got fooled by that this is
  • 00:59:06
    really hard to see code is full of
  • 00:59:08
    optical illusions and you have to be
  • 00:59:09
    very you have to be cognizant of the
  • 00:59:11
    fact you have to be aware of the fact
  • 00:59:13
    that code can contain optical illusions
  • 00:59:16
    and you have to fight against that this
  • 00:59:18
    is really hard to see you're gonna be
  • 00:59:20
    looking at here especially because of
  • 00:59:23
    this and you also have to worry about
  • 00:59:26
    stuff like this
  • 00:59:27
    our modern ideas have gotten pretty good
  • 00:59:30
    at disambiguating 1 and L and 0 and O P
  • 00:59:35
    and Q but sometimes these letters and
  • 00:59:38
    symbols differ by one pixel so you have
  • 00:59:42
    to be careful about that sometimes it's
  • 00:59:43
    hard to just differentiate them do you
  • 00:59:50
    use prefixes any more like za and uh I
  • 00:59:56
    used to use this this of this convention
  • 01:00:00
    all of my local variables began with ah
  • 01:00:04
    the indefinite article here all of the
  • 01:00:08
    arguments to a function began with the
  • 01:00:11
    and all instance variables began with I
  • 01:00:15
    TS it's so its name it's date I used to
  • 01:00:21
    use that all the time I've stopped using
  • 01:00:23
    that now I used to use it in the 80s and
  • 01:00:25
    in the 90s but I've stopped using those
  • 01:00:27
    prefixes now because the IDS are just so
  • 01:00:30
    good at telling me that that's an
  • 01:00:32
    instance variable or a function I can
  • 01:00:34
    hover over it so I've kind of dropped
  • 01:00:37
    the whole prefix I'd be in that days
  • 01:00:41
    it's probably not a good idea to use
  • 01:00:43
    numbers series like this sometimes you
  • 01:00:46
    have to fall back on it but it's better
  • 01:00:47
    to give them reasonable names number
  • 01:00:49
    series aren't a great idea watch out for
  • 01:00:53
    noise words data and info David first of
  • 01:00:59
    all I want should realize date
  • 01:01:01
    is completely redundant right of course
  • 01:01:03
    it's data you don't need to say it's
  • 01:01:05
    data okay product and now here what is
  • 01:01:08
    the difference between product and
  • 01:01:09
    product data is there some is there does
  • 01:01:13
    this tell you anything about what what
  • 01:01:15
    is different about it there's a type in
  • 01:01:17
    the system called product there's
  • 01:01:19
    another type in the system called
  • 01:01:20
    product data there's yet another type in
  • 01:01:22
    the system called product info what is
  • 01:01:24
    the difference between them and these
  • 01:01:27
    type names don't tell you the difference
  • 01:01:28
    so that's a problem
  • 01:01:29
    those are noise words I'm not going to
  • 01:01:33
    talk about that because I'm going to
  • 01:01:34
    come back to it later this I found in a
  • 01:01:37
    real application and I find it scary as
  • 01:01:41
    hell
  • 01:01:41
    the the first line says there's a
  • 01:01:44
    function that will return the active
  • 01:01:47
    account get active account that's great
  • 01:01:49
    and it returns an account good but now
  • 01:01:51
    look at the next function get active
  • 01:01:53
    accounts this is in the same system now
  • 01:01:57
    that begs the question what the heck is
  • 01:01:59
    that first one returning this there can
  • 01:02:03
    be more than one active account so
  • 01:02:06
    what's the first one returning the third
  • 01:02:08
    function is even scarier get active
  • 01:02:11
    account info but it returns the list of
  • 01:02:13
    accounts so these are not well
  • 01:02:19
    disambiguated names the names are not
  • 01:02:21
    telling you what's going on here and you
  • 01:02:24
    look at them and go what that's not good
  • 01:02:28
    that's a WTF make sure your names are
  • 01:02:31
    pronounceable cooker three 'can't busy
  • 01:02:38
    name jigna minam's
  • 01:02:43
    now you can see why the last one
  • 01:02:45
    especially you can see why you used this
  • 01:02:47
    name it's the generation timestamp your
  • 01:02:49
    month day hour minute second makes
  • 01:02:51
    perfect sense but you can't say it now
  • 01:02:56
    you know you guys pair program but any
  • 01:03:00
    pair of programmers out there anybody
  • 01:03:02
    repair how often do you pair program not
  • 01:03:04
    very many people doing it why not it's a
  • 01:03:09
    good idea
  • 01:03:09
    pairing allows you to share knowledge do
  • 01:03:12
    you do code reviews who does code
  • 01:03:13
    reviews
  • 01:03:14
    ooh everybody has code reviews code news
  • 01:03:18
    a very inefficient pairing is very
  • 01:03:19
    efficient right how much how much time
  • 01:03:23
    should you spend on a code review let's
  • 01:03:28
    say that the original author required
  • 01:03:31
    five hours to write the module how long
  • 01:03:33
    should it take to review that module
  • 01:03:36
    well some function of five hours maybe
  • 01:03:39
    not exactly five hours but some
  • 01:03:41
    significant function of five hours
  • 01:03:43
    because if you're going to review the
  • 01:03:45
    module you need to walk through the
  • 01:03:47
    reasoning that the author originally
  • 01:03:48
    went through now hopefully the author
  • 01:03:50
    made that easy for you by refactoring it
  • 01:03:53
    and cleaning up the code so fine but
  • 01:03:56
    it's still going to take you some fairly
  • 01:03:58
    significant amount of time to review
  • 01:04:00
    that module if you if you review a
  • 01:04:03
    module that took five hours to write and
  • 01:04:06
    you review it in 15 minutes
  • 01:04:08
    all you've done is look for semicolons
  • 01:04:11
    so all you've done right and maybe it's
  • 01:04:13
    some indenting and maybe a few naming
  • 01:04:15
    conventions but you haven't done
  • 01:04:16
    anything significant you haven't
  • 01:04:19
    actually reviewed the code so you should
  • 01:04:21
    look at code reviews as requiring
  • 01:04:24
    roughly the amount of time it took to
  • 01:04:27
    write the module well okay if you're
  • 01:04:30
    going to spend that much time reviewing
  • 01:04:32
    the code why wouldn't you pair pairing
  • 01:04:34
    takes about the same amount of time but
  • 01:04:36
    when you're pairing you are actively
  • 01:04:39
    involved you are not passively reviewing
  • 01:04:42
    you are authoring there's a much better
  • 01:04:45
    way to share knowledge and contribute to
  • 01:04:48
    a team yeah
  • 01:05:02
    so the question was about noise words
  • 01:05:06
    because he didn't want to talk about
  • 01:05:07
    pairing the word exception appears in
  • 01:05:16
    lots of different types in Java
  • 01:05:18
    an illegal state exception illegal
  • 01:05:20
    argument exception nullpointerexception
  • 01:05:22
    so on does the word exception constitute
  • 01:05:26
    a noise word in that case no it doesn't
  • 01:05:28
    it's the it's the noun that is the base
  • 01:05:31
    class they all derive from exception and
  • 01:05:34
    then the derived classes have to add a
  • 01:05:36
    word on to that to describe what kind of
  • 01:05:38
    exception they are so that's not a noise
  • 01:05:40
    word and and it is not noisy also
  • 01:05:43
    because it tells you it's an exception
  • 01:05:45
    all right now back to this pairing thing
  • 01:05:47
    thank you for that we have to go out for
  • 01:05:51
    lunch
  • 01:05:51
    oh yeah it's 12:30 isn't it its feet is
  • 01:05:54
    what I'm talking about pairing even
  • 01:05:55
    though I don't yeah
Tag
  • Lune
  • origine
  • théorie d'impact
  • orbite circulaire
  • composition
  • fer
  • stabilisation par marée