← Back to Upcase

What do you think about the length of line


(Guirec Corbel) #1

Hi,

There is a convention that say a line should do 80 characters or less. Thoughbot does not seems to use this convention. For example, github.com/thoughtbot/learn/blob/master/app/models/video.rb#L17 do 131 charaters.

In addition, long lines are uggly in vim. Should I just don’t care?

Bye!


(Derek Prior) #2

That line should absolutely be broken up. If I needed to change that class at some point, I’d definitely change that. We do try to stay within 80 characters as not only are long lines ugly, they are difficult to parse. Here is our style guide. It’s just a guide. Sometimes things are just better on one line, but the example you cited isn’t one of those times.


(Guirec Corbel) #3

There are many lines with more than 80 characters like this one : github.com/thoughtbot/learn/blob/master/app/models/video.rb#L27 or this other one : github.com/thoughtbot/learn/blob/master/app/controllers/users_controller.rb#L32 or in this file : github.com/thoughtbot/learn/blob/master/app/controllers/follow_ups_controller.rb.

If you change the code to do smaller line, please let me know.

In my project, to do smaller lines, I do code like this :

def order_creator
@order_creator ||= OrderCreator.new(form: form,
                                    painting: painting,
                                    ip_address: ip_address)
end 

I think it’s a little bit uggly. It’s worse in views. I have code like this :

<%= f.association :painting_technic,
  input_html: { 'data-bind' => "options: availableTechnics,
                 optionsText: 'title',
                 optionsValue: 'id',
                 optionsCaption: ' ',
                 value: painting_technic_id,
                 enable: painting_category_id" } %>

How do you split this kind of code?


(Ben Orenstein) #4

I think I’d split my lines the same way you have in these examples.

If you’d like to submit a pull request to the learn app with the lines wrapped better, I’ll merge it. :slight_smile:


(Guirec Corbel) #5

I will be happy to contribute to one of your projects. If I find the time, I will do it.


(Gergely Molnar) #6

I already did it. I haven’t broke up the lines with 90/93 characters as they look ok to me. Should do those too?


(Ben Orenstein) #7

Nah, I wouldn’t worry about them too much.