9 ms·
The Second Edition of “Refactoring”
- myth_buster 8y ago> When I choose a language for examples in my writing, I think primarily of the reader. I picked Java because I felt the most people would be able to understand the code examples if they were written in Java. That was the case in 1997, but how about in 2017? [...] Such a language needed to be widely popular, among the top half a dozen in language popularity surveys. It really helps to have a C-based syntax, since most programmers would recognize the basic code structure. Given that, two stood out. One was Java, still widely used and easy to understand. But I went for the alternative: __JavaScript__. [...] But the compelling reason for choosing it over Java is that isn't wholly centered on classes. There are top-level functions, and use of first-class functions is common. This makes it much easier to show refactoring out of the context of classes. This is very interesting choice of language. I wonder whether typescript could have been a candidate as well. Although not as popular as JS, I believe most of JS community has migrated to typescript (due to obvious benefits) and it is more closer to a C-based language.
- deleted 8y ago[deleted]
- azhenley 8y agoEven more interesting is that he previously came out with a Ruby edition: https://martinfowler.com/books/refactoringRubyEd.html https://martinfowler.com/books/refactoringRubyEd.html
- bdcravens 8y agoHow much of it did he write? I suspect it was much like "Agile Web Development with Rails", which up until the most recent edition, listed DHH as an author
- genieyclo 8y agoyeah the Ruby edition is full of errors so be careful.
- bdcravens 8y agoEarly on in my Ruby career, I picked it up, but really couldn't get much traction with it. Hartl's book was far better.
- genieyclo 8y agoHartl has a book on refactoring? We're going through http://refactoring.guru http://refactoring.guru at work right now, it's a nice modern version of Fowler's classic imo.
- chrisseaton 8y ago> I believe most of JS community has migrated to typescript You think the majority of JS developers have switched over to TypeScript?
- ChristianGeek 8y agoThat (quoted) is a bubble statement if I’ve ever seen one.
- myth_buster 8y ago_has_ may be incorrect but I do feel the switch is happening [0]. Angular which is the most popular client side JS framework is using Typescript. React is also moving in the same direction with typescript-react-starter and tsx support. [0] https://2018.stateofjs.com/javascript-flavors/overview/ https://2018.stateofjs.com/javascript-flavors/overview/
- BurningFrog 8y agoIn my (part of the) JS world Angular is dying and React has long since won.
- twblalock 8y agoI agree, I don't know any front end devs who would choose Angular for a new project. The current choice seems to be between React and Vue.
- Geee 8y agoAngular is not the most popular [0]. [0] https://2018.stateofjs.com/front-end-frameworks/conclusion/ https://2018.stateofjs.com/front-end-frameworks/conclusion/
- jammygit 8y agoIf you know typescript, you're familiar enough with javascript to use the book, but if you don't know typescript then its a bit tricky for those readers. It just means fewer people have to dust off their language skills to benefit from the book.
- ummonk 8y agoWell, I'm very fluent in Typescript, and often find JS code extremely difficult to understand. The types are a great aid to understanding code. It also seems to be the case that a lot of JS code does not use ES6 polyfills, unlike Typescript code, so it tends to be less clean. Edit: Upon rereading I see you are talking about the book, not actual projects, so my reply is not all that applicable. Though I'd actually say that Typescript is much more understandable than JS to someone unfamiliar with both.
- jammygit 8y ago"Typescript is much more understandable than JS to someone unfamiliar with both." From that point of view, I see what you're saying.
- sveme 8y agoSaw him in a talk just last week - he actually mentioned that typescript would have been an alternative, but considered it less well known yet.
- nullandvoid 8y agoWhilst a fan of typescript myself I think the last statement is incorrect, I'd be surprised if >20%-30% of projects started in JS this year are typescript.
- regularfry 8y agoI'd be shocked if it was higher than 10%, and that's not even the bulk of JS work: the vast majority is brownfield, existing projects, where changing the toolchain is decidedly nontrivial. TS is nice, but it's a long way from ubiquity.
- LolNoGenerics 8y ago> This is very interesting choice of language. I wonder whether typescript could have been a candidate as well. Although not as popular as JS, I believe most of JS community has migrated to typescript (due to obvious benefits) and it is more closer to a C-based language. Can you elaborate on this manipulative nonsense?
- dang 8y agoPlease keep programming language flamewars well away from HN.
- LolNoGenerics 8y agoNaive fainboyism as well
- raymondh 8y agoI think almost every programmer would benefit from reading "Refactoring". It sharpened my skills quite a bit, and I was already experienced before encountering the book. The book was an easy read and was an efficient use of my time. I expect that rewrite in Javascript will further improve the information density.
- jammygit 8y agoThe seller apparently needs my address to sell me an ebook, and it thinks my postal code is fake and locked me out. Well played, Pearson.
- kristiandupont 8y agoI bought the book ages ago and remember not really finding anything of value in it. I don't mean to sound like someone from /r/iamverysmart but I recall thinking I would benefit in the way I did from the design patterns book: by giving me terminology for things I already did. But as far as I remember, the names were really obvious ("rename parameter", "extract method", etc.) and the instructions equally so. Can you give an example of something you learned from it?
- quietbritishjim 8y agoI remember having exactly the same experience, including the anticipation that I would benefit from it the way I would from Design Patterns. For most of the refactorings in the book, a bullet point in a list would've seemed a bit excessive, never mind a step-by-step sequence of instructions. In the end I literally threw the book away – the only technical book I've ever done that to. I distinctly remember one of the things in the book, which in retrospect isn't even really a refactoring, called something like "null object". The idea was that if you were going to return null from a function (e.g. get student by ID but that ID doesn't exist) then you could instead return a concrete singleton object that represented null. That way, if you forgot to check for it then at least your program wouldn't crash. Now, the merits of this idea are debatable and I don't think I've ever used it in the years since. But I strongly remember thinking at the time that it was the only idea in the book that wasn't totally obvious. There was a good chapter early on about testing, which I think was my first exposure to that idea. It was a bit brief but that's not a surprise given it was a bit of a digression from the main topic. A whole book on that might've been quite a bit more interesting.
- azhenley 8y agoFor most people, I think his online catalog of refactorings and blog articles are sufficient. Though I think the first edition is a good book, I wouldn’t need it if I didn’t do research on refactoring tools.
- kalev 8y agoDid not know there was a online library of refactorings. Here’s the link https://refactoring.com/catalog/ https://refactoring.com/catalog/ if anyone’s interested.
- bpicolo 8y agoWhat's the target demographic for something like this? It seems like the trivial part of refactoring. I've seen a similar, entire book dedicated to database refactoring that had roughly the same pattern. Chapters named akin to "The Change Table Name Refactor" felt kind of bizarre, when what I was hoping would be contained was advice about refactoring large databases in practice (moving data to new service boundaries, etc). Practical advice on building systems to move data and such seems to be just missing
- CiaranMcNulty 8y ago> It seems like the trivial part of refactoring. Trivial after the book exists, sure The catalog misses out most of the interesting discussion
- darrenhobbs 8y agoI read the first edition when I was nearly 2 years into my professional career. I understood the basic 'what' and 'how' of software development. Refactoring helped me start to understand the 'why' and 'when'. Why is design A better than design B? When is it time to tidy up this code? Which choice will be easier to change later? That kind of thing.
- Ericson2314 8y agoRefactoring with and without types feels so different. I'm surprised the book so lightly made the switch.
- josteink 8y agoIs it really? Types just help formalize (for you and the compiler) what the code actually says. Types or not, the refactored code itself is still refactored.
- BurningFrog 8y agoIn a typed language, an IDE can make breathtakingly large refactorings that are 100% correct.
- taeric 8y agoMost common refactoring can be done in any language. If you have types, that really just means the compiler is testing many of your assertions.
- josteink 8y agoThat’s obviously true, but you seem to be conflating refactored code with tooling support for refactoring. Done by a tool or not, the refactoring in principle remains the same. The tool merely automates the transformations which defines the refactoring. And in that sense types isn’t really essential to refactoring at all.
- BurningFrog 8y agoI'm not conflating anything. Just stating a fact.
- twblalock 8y agoTypes make it much, much easier to write useful refactoring tools, and to verify that the tools did the right thing.
- jammygit 8y agoI've read and enjoyed quite a few of Fowler's articles. The things I've taken from his writings have been concretely valuable so far too. I'm not experienced enough though to evaluate how his ideas stand up in big or complicated projects. Can anybody comment?
- danmaz74 8y agoI can't comment on other articles, but I would be careful with some suggestions about mocking everything in automated tests. I've seen a couple of totally botched projects because of that approach.
- jammygit 8y agoHow did the mocks do the damage? Lack of integration tests, wasted time, or something else?
- billsix 8y agoIt results in tautological tests.
- softawre 8y agoNot really. I mean, you're still testing that the compiler works and that the memory works. ;)
- danmaz74 8y agoYes, the biggest problem was the lack of integration* tests: you can get a false confidence that everything is working, but you only know that the individual cogs are built to spec, not that the machine is working. Second problem was that refactoring became much harder, because the tests were deeply tied to the implementation (are methods X, Y and Z called with such and such arguments?). * using the definition of "integration" as "integrating components of the project", not "integrating with external services" (which is the definition I personally prefer).
- mherrmann 8y agoNo other book improved my coding style as much as the first edition of Refactoring. On a superficial level, it teaches you how to "clean up" code, according to various patterns. But what it really does is give you a feeling for why the code should be improved in the first place. Highly recommended.
- cpeterso 8y agoOnce one adopts the refactoring mindset, its lessons and approaches can also infuse new code aka "prefactoring". :) Ken Pugh wrote a 2005 book called " Prefactoring: Extreme Abstraction - Extreme Separation - Extreme Reliability 1st Edition", which won a 2006 Dr. Dobbs' Jolt award. http://www.drdobbs.com/joltawards/2006-jolt-awards/187900423?pgno=3 http://www.drdobbs.com/joltawards/2006-jolt-awards/187900423...
- clumsysmurf 8y agoDid you also read "Refactoring to Patterns"? If so, could you compare that with Prefactoring ? https://industriallogic.com/xp/refactoring/ https://industriallogic.com/xp/refactoring/
- cpeterso 8y agoSorry. I haven't read that book. :)
- lemoncucumber 8y agoCompared to the first edition of the book the second edition has the same functionality but is much better organized, which will make future editions much easier to develop.
- yazr 8y agoIs anyone aware of a birds-eye catalog of common code abstractions? e.g. linked list, hashes, lookup table, classes, counters, iterators, etc (Not referring to books such as TAOCP which cover a few topics in-depth)
- steveklabnik 8y agoSounds like you want https://en.m.wikipedia.org/wiki/Introduction_to_Algorithms https://en.m.wikipedia.org/wiki/Introduction_to_Algorithms maybe?
- yazr 8y agoWell, I can probably mine 10 tops books and come up with a good list of 100 abstractions. But i am sure someone has done a much better job than me on this..
- deleted 8y ago[deleted]
- yowlingcat 8y agoBy code abstractions, do you mean low level data structures[1]? There are those but they're different from mid level design patterns[2][3] or high level architectural patterns[4]. [1]https://en.wikipedia.org/wiki/List_of_data_structures https://en.wikipedia.org/wiki/List_of_data_structures [2]https://martinfowler.com/eaaCatalog/ https://martinfowler.com/eaaCatalog/ [3]https://sourcemaking.com/design_patterns https://sourcemaking.com/design_patterns [4]http://aosabook.org/en/index.html http://aosabook.org/en/index.html
- billsix 8y agoI thought this new book would be the third edition. https://www.amazon.com/Refactoring-Ruby-Addison-Wesley-Professional/dp/0321984137 https://www.amazon.com/Refactoring-Ruby-Addison-Wesley-Profe...
- ninjakeyboard 8y agoOh man thanks for posting this. Did not expect to see this come. I have both of them ("Refactoring" and then the "ruby edition") - it's a part of my vocabulary. Also thanks to other posters who describe their view of the updates of content.
- alasdair_ 8y agoI am a huge fan of this book. The Pragmatic Programmer and this book are the two that I recommend most. When I first read Refactoring, IntelliJ wasn't released yet and refactorings still needed to be done by hand. Automated refactorings are so incredibly useful when it comes to improving code quality over time that I don't know what it was we did without them.
- ksec 8y agoDoes anyone know if Martin Fowler still doing any Ruby? Or has he given up on it?