Giter Club home page Giter Club logo

clean-code-ruby's People

Contributors

adam-szczombrowski avatar bellps avatar david-pm avatar elissonmichael avatar fanaugen avatar gesjeremie avatar guifabrin avatar herwinw avatar hubertjakubiak avatar izaiasneto4 avatar javimbk avatar lujanfernaud avatar prashantjois avatar roclv avatar sammolokanov avatar schmijos avatar stevenharman avatar szymonwlochowski avatar th0j avatar tpei avatar uohzxela avatar xkwd avatar zokioki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clean-code-ruby's Issues

Methods should do one thing - one question

Hi @uohzxela
Thanks for your good contents. It is really helpful.
But I have a question about Methods should do one thing

Bad:

def email_clients(clients)
  clients.each do |client|
    client_record = database.lookup(client)
    email(client) if client_record.active?
  end
end

email_clients(clients)

Good:

def email_clients(clients)
  clients.each { |client| email(client) }
end

def active_clients(clients)
  clients.select { |client| active_client?(client) }
end

def active_client?(client)
  client_record = database.lookup(client)
  client_record.active?
end

email_clients(active_clients(clients))

It seems Good code is more clear but if we use this code, we have to loop all clients twice.
But first Bad code only loops clients once.
So Bad code is faster than Good code.
What do you think?

Create a separate github organization for the repo?

Hi,

I really like this repo. I can see it being immensely useful when working on PR reviews in my company. Instead of explaining something I can simply link to a section in this repo.

Similarly to eg ruby-style-guide what do you think about creating a standalone github organization for this repo? The full link to this repo would be something like: https://github.com/clean-code-ruby/clean-code-ruby. I think this would be really nice and give this repo a nice, "official touch".

Testing : Ruby's own testing tool

Hi,

Under the "Test" section you write : "There's no excuse to not write tests. Ruby comes with its own testing tool (RSpec) built right in.". I guess you meant Minitest ?

Great work, thanks !

Cheers.

Spell error: double "the"

Method names should say what they do
Poorly named methods add to the code reviewer's cognitive load at best, and mislead the code reviewer at worst. Strive to capture** the the**precise intent when naming methods.

Function arguments example should have 2 arguments

The function arguments section talks about rarely using over two arguments in a single method. We should probably give an example that doesn't use four arguments.

Bad:

-def create_menu(title, body, button_text, cancellable)
+def create_menu(title, body)
  # ...
end

Good:

-def create_menu(title:, body:, button_text:, cancellable:)
+def create_menu(title:, body:)
  # ...
end

-create_menu(
-  title: 'Foo',
-  body: 'Bar',
-  button_text: 'Baz',
-  cancellable: true
-)
+create_menu(title: 'Foo', body: 'Bar')

Would be happy to push up a PR for the above :)

Function/Functions is not the right word of choice.

I've seen that you have used Functions as a term in several places, that's not really correct.

In Ruby it isn't possible to execute a piece of code that isn't defined on an object, because there is nothing in Ruby that is not an object - this way, strictly speaking, a concept of a function does not exist, there are only methods.

Better example for "Favor functional programming over imperative programming"

I don't disagree with the sentiment here, but Favor functional programming over imperative programming states that "Functional languages are cleaner and easier to test".

The test for the example doesn't change between implementations, so doesn't give the reader an indication of why functional style is easier to test.

require 'minitest/autorun'

class FunctionalVsImperativeTest < Minitest::Test
  def test_imperative
    calculator = Imperative.new
    assert_equal(calculator.calculate(test_data), 3150)
  end

  def test_functional
    calculator = Functional.new
    assert_equal(calculator.calculate(test_data), 3150)
  end

  private

  def test_data
    [ { name: 'Uncle Bobby',
        lines_of_code: 500 },
      { name: 'Suzie Q',
        lines_of_code: 1500 },
      { name: 'Jimmy Gosling',
        lines_of_code: 150 },
      { name: 'Grace Hopper',
        lines_of_code: 1000 } ]
  end
end

class Imperative
  def calculate(programmer_output)
    total_output = 0

    programmer_output.each do |output|
      total_output += output[:lines_of_code]
    end

    total_output
  end
end

class Functional
  INITIAL_VALUE = 0

  def calculate(programmer_output)
    programmer_output.sum(INITIAL_VALUE) { |output| output[:lines_of_code] }
  end
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.