My lead developer has commented that the code I write is hard to understand and that I "overcomplicate things". I'm willing to accept this and improve but I'm not sure if this is genuinely the case or if his personal preferences are seeping into his judgement.
A red flag for me was the following situation: We're receiving database entries in the form of an array of dictionaries called
columns. We then make HTML templating decisions based on their contents. Note that "special" types such as files or map coordinates are really text fields with an additional
type_[name] array field for validation.
columns = someDBData for column in columns: column_type = column['data_type'] isValid = Someclass.perform_some_validation(column_type) # returns a boolean isCalendar = Someclass.is_calendar(column_type) # returns true if it's a time, datetime or datetime-local data type isString = Someclass.is_string(column_type) # ditto but with text, mediumtext or varchar isHidden = True if column['hidden'] != 0 else False isReadOnly = True if (configuracion_open == "" and column['open_insert'] == 0) or (configuracion_open == "Editando_registro" and column['open_edit'] == 0) else False isFile = True if column_type == "text" and column['type_file'] is True else False isGeo = True if column_type == "text" and column['type_geo'] is True else False isGeneric = True if isCalendar or isString and not isFile else False # repeat for other validations and then do templating stuff
When reviewing my work, he claimed that using "long ternary operators such as these" would be confusing for other people maintaining the code in the future. It seems as if he'd prefer to use a more verbose if/elif/else structure for readability, even though giving the program unnecessary verticality will also result in a readability problem in the future, at least in my opinion. In summary, should I reserve ternary operators for short and simple validations?