SlideShare une entreprise Scribd logo
1  sur  67
© Henri Tremblay 2015
Henri Tremblay
Développeur Sénior
Terracotta, une filiale de Software AG
Être pragmatique
@henri_tremblay
2
Les histoires racontées durant cette
présentation sont vraiment arrivées
TOUTEFOIS
Toute ressemblance avec une
quelconque compagnie que vous
connaissez est fortuite
Avertissement
3
4
L’instinct
5
Henri Tremblay
6
Henri Tremblay
7
Henri Tremblay
8
9
10
Ne dépendre que
d’interfaces
11
Tu pourrais en
avoir besoin plus
tard
12
13
Tu pourrais en
avoir besoin plus
tard
14
15
16
17
18
Il faut une
interface pour
“mocker”
19
Être pragmatique
20
21
22
23
N’oublie pas ton
objectif
Règle #1
24
Si ça a l’air trop
compliqué pour
rien, utilise-le pas
Règle #2
25
26
Trouve comment
extérioser
Règle #3
27
It smells
28
C’est louche
29
Aaaaaaaaaaaaaa
aaaaaaaa!!!!!!
30
WTF!!!
31
Voyons
donc!Kossé ça!
32
33
Pourquoi?
(en prenant comme postulat
que l’autre n’est pas un
imbécile)
Règle #4
34
35
Méfiez-vous des
dangereux
architectes
Règle #5
36
UML
.NETJava
C++ ORM
JNI
Unmanaged
Incantation
Génération du
modèle
37
UML
.NETJava
C++ ORM
JNI
Unmanaged
Incantation
Humble requête
Génération du
modèle
38
39
Méfiez-vous des
dangereux
consultants
Règle #5bis
40
41
Méfiez-vous des
dangereux
gestionnaires
Règle #5ter
42
43
44
En as-tu vraiment
besoin
maintenant?
Règle #6
45
Brie
Oka
Camembert
Cheddar
Cheese.csv
46
CsvReader
47
CsvReader
48
Brie,"Mild soft cheese"
Oka,"Venerable Québec cheese"
Camembert,Strong soft cheese
Cheddar,"Hard cheese, taste nothing if not aged"
Maroilles,"Classified as ""chemical weapon"" in the USA"
Cheese.csv
49
CsvReader
50
Tu en as besoin
plus vite que tu
penses
Règle #7
51
15 minutes!
52
1 500 000 000 000
instructions
53
2 ans
54
Cheese REST
55
Cheese REST
56
Qu’est-ce que ça
coûte d’essayer?
Règle #8
57
Saut parachute
sans parachute
58
Saut parachute
sans parachute
 Peux mourrir
59
Migrer à Log4j 2
60
Migrer à Log4j 2
 3 JH
61
Convertir à JUnit 5
62
Convertir à JUnit 5
 20 JH
63
Utiliser Scala
(non)
64
Henri Tremblay
• A populariser les mock et proxy de classes
• A inventer le terme “partial mocking”
65
Qui a appris quelque
chose aujourd’hui?
?
66
Lecture suggérée
67
Questions? http://montreal-jug.org
?
http://easymock.org
http://objenesis.org
http:/ehcache.org
Henri Tremblay
http://blog.tremblay.pro
@henri_tremblay

Contenu connexe

Plus de Henri Tremblay

Confoo 2016: Initiation aux tests de charge
Confoo 2016: Initiation aux tests de chargeConfoo 2016: Initiation aux tests de charge
Confoo 2016: Initiation aux tests de chargeHenri Tremblay
 
Generics and Lambdas cocktail explained - Montreal JUG
Generics and Lambdas cocktail explained  - Montreal JUGGenerics and Lambdas cocktail explained  - Montreal JUG
Generics and Lambdas cocktail explained - Montreal JUGHenri Tremblay
 
Réactif, parallèle, asynchrone. Pourquoi!
Réactif, parallèle, asynchrone. Pourquoi!Réactif, parallèle, asynchrone. Pourquoi!
Réactif, parallèle, asynchrone. Pourquoi!Henri Tremblay
 
Microbenchmarking with JMH
Microbenchmarking with JMHMicrobenchmarking with JMH
Microbenchmarking with JMHHenri Tremblay
 
Lambdas and Generics (long version) - Bordeaux/Toulouse JUG
Lambdas and Generics (long version) - Bordeaux/Toulouse JUGLambdas and Generics (long version) - Bordeaux/Toulouse JUG
Lambdas and Generics (long version) - Bordeaux/Toulouse JUGHenri Tremblay
 
Vivre en parallèle - Softshake 2013
Vivre en parallèle - Softshake 2013Vivre en parallèle - Softshake 2013
Vivre en parallèle - Softshake 2013Henri Tremblay
 
Performance perpétuelle (Devopsdays Paris 2013)
Performance perpétuelle (Devopsdays Paris 2013)Performance perpétuelle (Devopsdays Paris 2013)
Performance perpétuelle (Devopsdays Paris 2013)Henri Tremblay
 
DevoxxFR 2013: Lambda are coming. Meanwhile, are you sure we've mastered the ...
DevoxxFR 2013: Lambda are coming. Meanwhile, are you sure we've mastered the ...DevoxxFR 2013: Lambda are coming. Meanwhile, are you sure we've mastered the ...
DevoxxFR 2013: Lambda are coming. Meanwhile, are you sure we've mastered the ...Henri Tremblay
 

Plus de Henri Tremblay (9)

Confoo 2016: Initiation aux tests de charge
Confoo 2016: Initiation aux tests de chargeConfoo 2016: Initiation aux tests de charge
Confoo 2016: Initiation aux tests de charge
 
Generics and Lambdas cocktail explained - Montreal JUG
Generics and Lambdas cocktail explained  - Montreal JUGGenerics and Lambdas cocktail explained  - Montreal JUG
Generics and Lambdas cocktail explained - Montreal JUG
 
Réactif, parallèle, asynchrone. Pourquoi!
Réactif, parallèle, asynchrone. Pourquoi!Réactif, parallèle, asynchrone. Pourquoi!
Réactif, parallèle, asynchrone. Pourquoi!
 
Perf university
Perf universityPerf university
Perf university
 
Microbenchmarking with JMH
Microbenchmarking with JMHMicrobenchmarking with JMH
Microbenchmarking with JMH
 
Lambdas and Generics (long version) - Bordeaux/Toulouse JUG
Lambdas and Generics (long version) - Bordeaux/Toulouse JUGLambdas and Generics (long version) - Bordeaux/Toulouse JUG
Lambdas and Generics (long version) - Bordeaux/Toulouse JUG
 
Vivre en parallèle - Softshake 2013
Vivre en parallèle - Softshake 2013Vivre en parallèle - Softshake 2013
Vivre en parallèle - Softshake 2013
 
Performance perpétuelle (Devopsdays Paris 2013)
Performance perpétuelle (Devopsdays Paris 2013)Performance perpétuelle (Devopsdays Paris 2013)
Performance perpétuelle (Devopsdays Paris 2013)
 
DevoxxFR 2013: Lambda are coming. Meanwhile, are you sure we've mastered the ...
DevoxxFR 2013: Lambda are coming. Meanwhile, are you sure we've mastered the ...DevoxxFR 2013: Lambda are coming. Meanwhile, are you sure we've mastered the ...
DevoxxFR 2013: Lambda are coming. Meanwhile, are you sure we've mastered the ...
 

Confoo 2018: Être pragmatique

Notes de l'éditeur

  1. Hello everyone and welcome to a session that may change your life. Today you will learn to be pragmatic. But first, who think he is pragmatic? Great, I dearly hope you are right. Because I am not presenting this session for you. I am selfishly presenting this session for me! I would love to be surrounded by pragmatic people! But first, let me get started with one disclaimer.
  2. Read the slide After all we are in the United States, land of the lawyer and I don’t want to get sued for telling war stories. Now, let’s get started
  3. True wisdom is knowing what you don’t know. And they actually both said pretty much the same thing. For real. And when Socrates and Confucius are saying the same thing, you can only humbly agree. And yes of course they both never said that. Those are English quotes made up by some marketing guy to sound punchy. But yes, the spirit of what they said is more or less preserved here. Anyway. True wisdom is really knowing what you don’t know. So there is everything you do know, and for everything else there is….. ?
  4. GUT FEELING! Yes sir. Gut feeling. What else can you do? If I don’t know, if just don’t know. So I just use my gut feeling. But not everybody was born equal. Some have better guts than others. So today, I will teach you how to train your gut. “Hey! Wait a minute! Who’s this guy telling me I’m not pragmatic. Who does he thing he is?” You are right. Let me step back a bit.
  5. I’m Henri Tremblay. I currently work for Terracotta, which is owned by Software AG and I develop Ehcache and some other stuff that surrounds it
  6. I’m also Java Champion.
  7. Mainly because of things that I did when I was young. Let me tell you about it. A long time ago, when I was young, I was asked by some analysts to retrieve some cheese from a database. I wasn’t actually cheese but let’s just assume it was.
  8. So here is my simple Cheese class, nothing worth of mention here
  9. And here is my DAO. See? I’m so awesome that I was already using Java 8 20 years ago. Anyway, I was quite happy with that so I went back to the analyst to show him what I did. And of course he wasn’t as happy as I was. He told me:
  10. God voice: Only depends on interfaces. Huh? Why? I have only one implementation. Today you have (grand architects tend to speak like Yoda), but
  11. “You might need it later” What? “You might need it later!” Ok. I got it right the first time. Let me rephrase that.
  12. You want to do modify my nice design to add all these interfaces? That’s will just make me loose tons of time swimming in uselessness! Why?
  13. “You might need it later” What? “You might need it later!” Ok. I got it right the first time. Let me rephrase that.
  14. Look let’s say I have a CheeseService that uses my CheeseDao
  15. And I then decide that I need another implementation of the CheeseDao so I extract an interface from it. What does it change for CheeseService?
  16. Nothing! Absolutely nothing! Now, two things can happen. One is that the analyst was in fact a vampire who never test his code and he turn into ashes
  17. Or, 2, he says:
  18. “You need an interface to mock it” And he’s right. In these old days, EasyMock, and all other mocking frameworks, were only mocking interfaces. So if you wanted to inject a mock, you need an interface. So I was doing it like everyone else, but it felt so wrong, so artificial. And one day, a guy named Bob Lee gave me an idea. “Hey, we could use this class proxying framework, cglib to mock classes” So that’s how pragmatic I am. Because it felt so wrong to have interfaces exclusively for unit testing, I got involved in open source and developed class mocking.
  19. Now, back to be pragmatic. During your developer’s life you have encounter multiple methodologies which have for sole goal to help you stay pragmatic
  20. Extreme programming in one
  21. Agile methodologies are one
  22. Lean is one. All these ideas where created only to help being pragmatic. If you apply them with respecting their purpose, if you forget what they are for, if you are just doing your scrum without thinking if anything you do make sense, all these methodologies will they fail. This will lead me to my first advise.
  23. Don’t lose the purpose What is your purpose? Do you want a product loved by your users? Or you want to play with Apache Spark? I need to choose and whenever there is a decision to make, always think about the purpose. What do you want to achieve? Once you know that, we can go to the second rule
  24. If it feels useless or overly complicated, it probably is. I mean it. You are not here to win a fight against a tool. I know developers. They have their pride, they wants to win against the machine. Ah ah! This damn framework is unusable! But it won’t beat me. I will use it! Whatever it takes! Ah ah! It should beat you. If it’s unusable, it’s not worth your time. Just drop it. Now. My rule is: If I can’t get it to work. By that I mean just the basic stuff. Like a getting started. In about 30 minutes, it should rot in hell because I have much better things to do. There is only one exception to this rule. Sometimes there are no alternative. When you are forced to use it.
  25. OAuth2 for instance. Have you ever noticed that most cryptic and unusable framework are for security? I’m starting to think that there’s a sect of overly paid security consultants that is behind this. But yes, I deeply have OAuth2 but it is all over the place so I got to use it. Sadly. But trust me, if I could do otherwise, I would. Anyway. Rule #2
  26. Yes. That sounds silly but I think it is really helpful. Because it gets automatic. As soon as you are in front of something that doesn’t feel like God would have wanted it, you can express yourself. Some examples
  27. “It smells” A classical one. Wildly used in extreme programming
  28. Huh? That’s not rights
  29. AAAAAAAAAAAAA!!!!!!! But not appropriate for an open space And of course my favorite
  30. WTF which stands for
  31. AAAAAAAAAAAAA!!!!!!! But not appropriate for an open space And of course my favorite
  32. Voyons donc! Kossé ça! Now you get it. It’s bad. Now put on your boy scout suit and go clean that mess. BTW, this was actual Ehcache code that I’ve refactored a bit since. Ok. Great. Now we have our quote. Let’s go to the next rule
  33. Voyons donc! Kossé ça! Now you get it. It’s bad. Now put on your boy scout suit and go clean that mess. BTW, this was actual Ehcache code that I’ve refactored a bit since. Ok. Great. Now we have our quote. Let’s go to the next rule
  34. Crazy architects are the most dangerous thing that can happen to a project. They can singlehandedly cost years of work. An example was a client who called us some years ago. They had multiple problems. One of them was the ORM. It was slow and hard to maintain. Their architects explained that he didn’t like hibernate. It was too slow and not doing stuff that I don’t remember. So instead he decided to code a homemade ORM
  35. And not only that. The process was also really wise. The grand architect was the only one allowed to modify the model. So you had to ask him for a new field, he would then add it when he has time, launch the generator and TADA, you have a new field. How long is it to run the generator? About 2 hours. WTF!!!!! Can I please have a hammer?
  36. And not only that. The process was also really wise. The grand architect was the only one allowed to modify the model. So you had to ask him for a new field, he would then add it when he has time, launch the generator and TADA, you have a new field. How long is it to run the generator? About 2 hours. WTF!!!!! Can I please have a hammer?
  37. And you can see why quotes are useful. They help externalize the problem. In the end, the architect left the company, afraid by my sledgehammer and we just replaced everything by Hibernate Next rule
  38. I’m talking about crazy consultant. Not good ones like myself. Or Venkat. Good ones are really useful. Consultants are paid by the company who hired them but frequently have their own agenda. So sometime there are not actually crazy. It’s just that their goals are not aligned with yours Here some real stories. A consulting firm is hired to tell us the best fit for a workflow engine. The verdict was: This one is bad, this other one is worst and this final one is awful. We recommend you to use the awful one because you have already started using it and we have some expertise with it so you could send you some consultant to help you I’m the performance expert from this big company selling application server. Ok, let’s work together. I will launch a benchmark and we can then do some tuning. Sure, meanwhile I will sneakily change your server configuration to use “well-known to improve performance” parameters You don’t need to look at the source code. We will send you the final binaries We are much more efficient when the entire team is made of our consultants And so on and so on A hammer is not enough. They require an halberd to get rid of.
  39. You might see a pattern here. I could just squash the two rules together to call it “Beware crazy people” but in fact, both tend to be dangerous in different ways. Note that crazy developers are also dangerous but in general in a more limited way. So, beware crazy managers. They want to be useful. Like. Hey Henri. Your app looks like a workflow. So here, I bought this workflow engine for you. Please use it.
  40. Aaaaaaaaa. I told you Aaaaaaa was useful as well. Anyway, cool down and be pragmatic
  41. What can you do to counter craziness. Sometimes means discussing the issue and find a pragmatic solution. Sometimes it means to get external help. But sometimes it’s nastier. It means ignoring the workflow engine for the sake of sanity. Or just to plainly leave the company because I have no time to loose. Yes, it happened. I told them to talk me back when they are ready to listen because otherwise they will crash. They crashed. Back to the rules
  42. Never use something you don’t need until you do. All parts of this rules are important. Especially the until. Which is why it is in bold. Never use something you don’t need UNTIL you do. And when is until is left to you to decide. Let me show you an example.
  43. My boss comes and tell me: “Hey Henri, people love your cheese app” “Cool” “We need to add more cheese. I have this CSV. Can you please load it in your DB” “Sure” And I went coding.
  44. Easy as pie. Then my boss comes back. “Hey Henri. We would now like won’t to add a description field in the csv”. “Ok, why not, let me change the parser”
  45. Hurray. Job done. Then, the actual file arrives.
  46. Oh dear Lord. That’s not what I expected. Double-quotes. Not all the time. Comma in the text. Escaped double-quotes. So now, you’re at a crossroad. You can go left and code and entire CSV parser by yourself, or go right and drop everything you did so far to use an off-the-shelf open source parser. So I take me code, delete it and use OpenCSV.
  47. That is the most efficient way. Too bad for the existing code. That’s the UNTIL. Before, I was fine with my simple code. After, I really need something else. I don’t want to maintain a full-fledge CSV parser. Of course, in this example it was easy to pick a side. In real life, it can mean to delete 10 000 lines of code. Or months of work. So keep in mind the purpose, do the right thing. Next rule.
  48. Yes. Now I’m just messing with you. I was just saying you should wait until and now I’m saying “You need it earlier than you thought” Some things are needed really early in a project. An example is performance testing. One day, I was asked by junior consultant to help him on a mission. He said he was swimming in so much insanity that he could bear with it anymore. He’s quite a muscular guy so he doesn’t need an axe to be damaging. So I went. “Hi, what’s up? I was told you have performance issues.” “Yes, we do.” “What kind?” “You know, usual stuff, like you know, this call here takes 15 minutes” “What?!?!?!” That’s not a batch. It is a normal interactive call. 15 minutes.
  49. When I see a number like that, I like to put it in perspective.
  50. 15 minutes is about 1.5 Trillion CPU instructions. There a lot of things that can be done by 1.5 Trillion instructions. 15 minutes. It is the equivalent of calling the guy down there in the archive room. Hi buddy, can you bring me up the file A21 please. Sure it will be right on your desk in 15 minutes, I just need to pee first. Great thanks! People need to understand how ridiculous this number is for an interactive call. And the manager I was talking too wasn’t getting it. “And so, you’ve just started performance testing heh?” “Yes, we are going in production in a month” “Humkay. How long has this project been going on” “Oh About two years”
  51. Two years. It means that during 2 years, no one ever ever had the idea to test only a tiny bit of performance of the system on a real dataset. 2 years. When I code an app, it tends to look like this.
  52. One service to retrieve cheese. Followed by
  53. One Gatling test to its performance. Because applications are never magically optimizing themselves by adding functionalities. If this single rest service is too slow, I can guarantee you that in 2 years it won’t be faster. So just test it right away. Our time together is almost over and I have one last rule for you. It is actually a question to ask yourself when making a decision
  54. How harmful is it to try? How harmful is it to try all these I just gave you? And in general, when making a decision, if you take the wrong one, how harmful will it be? Let’s see
  55. Skydiving without a parachute.
  56. Can die. Not willing to try that
  57. Can die. Not willing to try that
  58. Ok. That I can afford
  59. Convert to Junit 5
  60. Oh gosh. That’s a lot. Can’t do that right now. Maybe later
  61. Use Scala. Ok, this one is special. I don’t like scala. I don’t want to use it. But some developers on my team wants to. And I might be wrong. Maybe it will have some benefits. So I let them try and see. Being pragmatic is not about being right all the time. It’s about looking at the constraint, cost and benefits and do the most meaningful thing. Hey, you know what, I forgot finishing presenting myself.
  62. I’m Henri Tremblay, I’m also the founder of the PerfUG in Paris. I am now one of the Montreal Jug leaders, so if you ever pass by, come say hello and present something. Finally, I’m also involved in Devoxx4kids Québec. Thank you very much for attending, I hope it was useful and I hope you had fun. My favourite question after a talk so I can know if I should keep doing it, is
  63. By a raise of hand, who has learned something today? Thank you very much. To put on your nightstand, two books that are really good for the mindset.
  64. The Goal, which is about theory of constraints. This is not at all an IT book and it is written as a noveli. The other, the Phoenix Project, is the same thing but move to an IT/Ops world. They are both must read books
  65. About Ehcache, version 3 has been out for a while now. It is obviously faster, safer, nicer. Please have a look and give us feedback. This is the end, do you have any question?
  66. Stories: CAE image generator The hashmap to generate mipmap Reading a linux book to answer questions Tibco staffware Benchmarking How the hell do I put that in production? To minutes rule to trying a framework and Hibernate String 5000 15 minutes performance