Any good books on refactoring?

fuzzybabybunny

Moderator<br>Digital & Video Cameras
Moderator
Jan 2, 2006
10,455
35
91
So right now my code sucks - a lot of it is brute force and explicitly defining operations through things like lots of if/else statements with only some variable names changed. I'm not used to using loops, objects, collections, etc. And I know that this is bad.

Are there any good books on refactoring in object-oriented languages that can introduce me to some common refactoring patterns? I'm using Javascript predominantly.
 

Graze

Senior member
Nov 27, 2012
468
1
0
You need a book on refactoring? Sounds like you need just need practices on the areas you are sketchy and read up on best practices on variable name etc.
That's usually not even a chapter in a programming book.

I dont mean to come off as an asshole but you did a three month bootcamp and don't feel comfortable with something as simple as loops?
 

purbeast0

No Lifer
Sep 13, 2001
52,931
5,802
126
i don't know of any books, but i just wanted to say that javascript isn't really a great language to try and learn a lot of common OO concepts from. there really isn't a true way of inheritance in js in the classical way as there are in java or c++. you can't just "extend" objects.

if you want to learn more OO stuff i'd say to start learning the server side stuff with java or groovy since they all use it.

if you give some examples of your code it would probably be easier to get some tips. things like loops, objects, and collections are very basic concepts in programming so i'm a bit confused as to what you mean when you say you aren't "used to" them.

one general concept is to never have long functions. make some arbitrary number that you don't want functions to be longer than. for instance say 50 lines or something. even that is pretty big for a function, and most of the time you can refactor that into smaller chunks. smaller functions are also easier to unit test and maintain. but of course, there are always special cases and exceptions to the rules.
 

fuzzybabybunny

Moderator<br>Digital & Video Cameras
Moderator
Jan 2, 2006
10,455
35
91
You need a book on refactoring? Sounds like you need just need practices on the areas you are sketchy and read up on best practices on variable name etc.
That's usually not even a chapter in a programming book.

I dont mean to come off as an asshole but you did a three month bootcamp and don't feel comfortable with something as simple as loops?

We never actually built anything with so much data (at least I didn't) that required loops. It was a 3-month bootcamp on web design, not hardcore coding.

i don't know of any books, but i just wanted to say that javascript isn't really a great language to try and learn a lot of common OO concepts from. there really isn't a true way of inheritance in js in the classical way as there are in java or c++. you can't just "extend" objects.

if you want to learn more OO stuff i'd say to start learning the server side stuff with java or groovy since they all use it.

if you give some examples of your code it would probably be easier to get some tips. things like loops, objects, and collections are very basic concepts in programming so i'm a bit confused as to what you mean when you say you aren't "used to" them.

one general concept is to never have long functions. make some arbitrary number that you don't want functions to be longer than. for instance say 50 lines or something. even that is pretty big for a function, and most of the time you can refactor that into smaller chunks. smaller functions are also easier to unit test and maintain. but of course, there are always special cases and exceptions to the rules.

Hmmm? I've seen plenty of inheritance in JS (I've never done it myself, but we had some JS guys come in and talk about inheritance - it was over my head at the time) and I've seen MeteorJS code where they extend things - a controller extends from another controller, for instance. But this is MeteorJS and Node, where it *is* server-side Javascript.
 

purbeast0

No Lifer
Sep 13, 2001
52,931
5,802
126
We never actually built anything with so much data (at least I didn't) that required loops. It was a 3-month bootcamp on web design, not hardcore coding.



Hmmm? I've seen plenty of inheritance in JS (I've never done it myself, but we had some JS guys come in and talk about inheritance - it was over my head at the time) and I've seen MeteorJS code where they extend things - a controller extends from another controller, for instance. But this is MeteorJS and Node, where it *is* server-side Javascript.

i didn't say it's not possible, i said it's not going to be the classical polymorphysm that you are used to with OO languages like C++ and java. it's using prototypical stuff which is just different and is fundamentally different than that you would be used to with the other languages. it is its own type of inheritance.

but you should probably learn how to use loops and collections before you even bother with a concept like inheritance. those are programming 101. inheritance is more like 201.

EDIT:

here's an explanation of why inheritance is different in js than traditional oo languages:

https://alexsexton.com/blog/2013/04/understanding-javascript-inheritance/
 

Graze

Senior member
Nov 27, 2012
468
1
0
i didn't say it's not possible, i said it's not going to be the classical polymorphysm that you are used to with OO languages like C++ and java. it's using prototypical stuff which is just different and is fundamentally different than that you would be used to with the other languages. it is its own type of inheritance.

but you should probably learn how to use loops and collections before you even bother with a concept like inheritance. those are programming 101. inheritance is more like 201.

EDIT:

here's an explanation of why inheritance is different in js than traditional oo languages:

https://alexsexton.com/blog/2013/04/understanding-javascript-inheritance/


This man speaks the truth especially in regard to JS and OO programming
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
13
81
www.markbetz.net
This is the book that really introduced it properly and solidly and its the one to read.

But it sounds to me like you are not using your language fully yet, this text might be beyond your skill level.

That's pretty much my take. It's hard to avoid writing some pretty bad code when you are first learning and applying the concepts to larger and larger problems. Refactoring is valuable when you have good code that needs to adapt to a broader view of a problem. When you have a pile of bad code the best approach from a learning perspective (at least) is probably just to rewrite and apply the lessons you've learned.
 

Cogman

Lifer
Sep 19, 2000
10,278
126
106
i don't know of any books, but i just wanted to say that javascript isn't really a great language to try and learn a lot of common OO concepts from. there really isn't a true way of inheritance in js in the classical way as there are in java or c++. you can't just "extend" objects.

Inheritance fell out of favor. It is pretty well accepted that you should prefer programming towards an interface vs building large object hierarchies. Javascript does that really well. (you don't even have to define the interface )

Composition over inheritance.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
13
81
www.markbetz.net
Inheritance fell out of favor. It is pretty well accepted that you should prefer programming towards an interface vs building large object hierarchies. Javascript does that really well. (you don't even have to define the interface )

Composition over inheritance.

Which is really a way of saying that "building large object hierarchies" fell out of favor. Inheritance is still a core mechanism, imo, it just gets applied much more simply, i.e. using a base class to establish default behaviors, or introduced the signature of an interface into a derived class scope in strongly-typed languages. As someone who was once in love with vast C++ class hierarchies I can only see this as a good thing .
 

mikegg

Golden Member
Jan 30, 2010
1,815
445
136
Pick up Javscript the Good Parts, Javascript the Definitive Guide, and Javascript Professional Web Development.

Next, read Javascript Functional Programming, Javascript Data & Algorithms, and finally, Effective Javascript.
 

Cogman

Lifer
Sep 19, 2000
10,278
126
106
Which is really a way of saying that "building large object hierarchies" fell out of favor. Inheritance is still a core mechanism, imo, it just gets applied much more simply, i.e. using a base class to establish default behaviors, or introduced the signature of an interface into a derived class scope in strongly-typed languages. As someone who was once in love with vast C++ class hierarchies I can only see this as a good thing .

Good point. It really depends on how the language approaches things. For C# and Java you will avoid "extending" things and rather just implement interfaces. What you especially want to avoid is some special magic method overload to do some special magic thing in the class in general (Java's swing ).
 

sze5003

Lifer
Aug 18, 2012
14,184
626
126
Get clean code by Robert Martin. Very good book and it will show you a lot of concepts. He teaches some classes here and then at my company and I've always enjoyed them.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |