What are best practices for spaces? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What are best practices for spaces?

As this is my first programming language, I'm trying to figure out if I need to develop consistent habits as far as spacing goes. Overall, would it be best to use spaces between things like x = 30 What about puts 3.eql?(3.0) Should I write puts 3.eql?(3.0) as puts 3 .eql? (3.0) in order to treat it consistently, as if it were a 3 == 3.0 the .eql? is a command in the same category as the == or = or + commands, correct? Also, why is the 3.0 in parenthesis, the lesson didn't explain that I feel

14th May 2017, 11:28 PM
AJ Sellarole
AJ Sellarole - avatar
3 Answers
+ 5
In puts3.eql?(3.0) it is better to write without spaces however in 3==3.0 I would really reccomened doing 3 == 3.0 instead, it is better to look at that way. Variable declaration should always be x = 10 instead of x=10 for me
14th May 2017, 11:31 PM
Complex
Complex - avatar
+ 3
in any case when you work in a team, try and follow the style of the existing code
14th May 2017, 11:35 PM
ifl
ifl - avatar
+ 3
I'm agree with previous answer, but I want add that my habits are flexibles: - adding and retrieving blank lines spacing to better see/read code parts I'm working on, and "collapsing" those already or not at this time focussing ( less scroll to navigate from one part to another ) - often not putting spaces in between right handed side expression in affectation ( and in function arguments ), because I find that more clear since there's more than one operation inside ( too much too big lines else): var length = Math.sqrt(coord_x*coord_x+coord_y*coord_y); ... rather than: var length = Math.sqrt( coord_x * coord_x + coord_y * coord_y); By the same way, to optimize visually readabilty, I often add more space when posting code in posts, because not monospaced font collapse more characters to each others ( and empty square brackets will be less readable, for example: [ ] rather than [] )...
15th May 2017, 3:12 AM
visph
visph - avatar