Is this a gambiarra? [closed]

2

I'm starting on programming, I have some difficulty reading even my codes after a while.

I was one of the researched readability and came across the term "gambiarra". this has raised me a question.

What exactly defines a gambiarra and how to avoid creating one?

Codes like the one I was writing in and I ended up losing can be considered gambiarras?

class Skeleton:
def __init__(self, names_list, delimiters=",. /*"):
    self.deimiters = [char for char in delimiters]
    self.__items = {}

    for name in names_list:
        replaced_name = name
        for delimiter_char in self.deimiters:
            replaced_name = replaced_name.replace(delimiter_char, " ")
        tokens = replaced_name.split()
        for i in range(len(tokens)):
            key = " ".join(tokens[:i + 1])
            if key in self.__items:
                item = self.__items[key]
                if name not in item["shapes"]:
                    item["shapes"].append(name)
            else:
                self.__items[key] = {}
                item = self.__items[key]
                item["shapes"] = []
                item["shapes"].append(name)
    
asked by anonymous 09.06.2017 / 16:21

1 answer

1

Gambiarra can have several interpretations, but it is never the best definitive solution. It may be something temporary, but not permanent.

If it's Python, I think its philosophy is a great starting point for understanding what might be a gambiarra and how to make a great code:

  

Beautiful is better than ugly.-Explicit is better than implicit.-Simple is better than complex. Comple Complex is better than complicated. Plano Plane is better than nested. Es Sparta is better than dense

Legibility account
Special cases are not special enough to break the rules
While practicality wins purity
Mistakes should not go quietly

Unless they are explicitly silenced.
In case of ambiguity, resist the temptation to guess.
There must be one - and only one - obvious way to do it. Although such a way is not so obvious at first sight unless that you're Dutch.-Now it's better than never.-Though it's never often better than right now.-If the implementation is hard to explain, the idea is bad.-If the implementation is easy to explain, maybe the idea is good.
Namespaces are a great idea - let's f azer more of them!

    
09.06.2017 / 19:18