Clean Ruby by Carleton DiLeo

Clean Ruby by Carleton DiLeo

Author:Carleton DiLeo
Language: eng
Format: epub
ISBN: 9781484255469
Publisher: Apress


Chaining method calls using this syntax is easier to follow since each call is on its on line.

Comments

Much thought goes into writing a line of code. In an ideal world, our code expresses these thoughts concisely. That isn’t always the case. Existing code and third-party libraries can introduce hacks and workarounds that are hard to communicate with code alone. After solving a difficult problem, we don’t want to lose the gained knowledge. This is where code comments are helpful. A comment provides more information and communicates assumptions for one or more lines of code. When another developer reads the comment, they won’t have to rediscover and solve the problems you encountered.

Comments sound great, so why not use them everywhere? While comments are helpful, it’s possible to overuse them: 1 def change_role(user_id, new_role)

2 # find a user by id

3 user = User.find(user_id)

4

5 # check that current role does not equal the new role

6 if user.role != new_role

7 # assign new role to the user

8 user.role = new_role

9 end

10 # end of method

11 end



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.