Delete duplicate string characters in a array

It’s very hard to figure out what is the intended behavior of the code when it’s written partly in French. I have no idea what “mathab”, “mathab2”, “math”, “mataddpn” or “creer_et_remplacer_materiaux_habillages” is supposed to mean. Also in my experience abbreviation such as mod, mat, sel and e, although common, makes difficult to read code. If you instead write the full word model, materials, selection and entity it is much easier to understand what it refers to.

As Aerilius has already said correct indentation would also help a lot.

Computers pair up if, do, unless and certain other keywords with a corresponding end keyword to understand the hierarchy of the code. Humans rely on indentation. There is no way to read this code without first copying it into a code editor and fix the indentation.

See this example:

def method_name
  # This code runs whenever the method method_name is called.

  if some_statement
    # This code runs whenever the method is called AND some_statement evaluates to true.
  end # This ends the if.

  5.times do
    # This code runs 5 times whenever the method is called.

    if some_other statement
      # This code runs a maximum of 5 times and only while some_other_statement evaluates to true.
    end # this ends the if.
  end # This ends the do loop.
end # This ends the method definition.

If you indent the code arbitrarily it’s impossible to understand what code runs when and why, without carefully pairing up the keywords yourself.

def method_name
  # This code runs whenever the method method_name is called.

  if some_statement
    # This code runs whenever the method is called AND some_statement evaluates to true.
    end # Okay?

    5.times do
    # So when does this run? Does it depend on some_statement? How many times does it run?

    if some_other statement
      # Headache.
    end
    end # What code block ends here?

# Wait, what? Why is there an indentation level missing here?

end
2 Likes