dominikbraun / timetrace

A simple CLI for tracking your working time.
Apache License 2.0
668 stars 75 forks source link

Duplicate code found in `core/record.go` #163

Closed jwnpoh closed 3 years ago

jwnpoh commented 3 years ago

Hello! It seems like there are two functions in core/record.go that do the same thing, ListRecords and loadAllRecords.

Being new to programming, I am not sure if this is a feature or bug :confused:

dominikbraun commented 3 years ago

You're right, those two functions seem to do the exact same things. Thanks for noticing this!

ListRecords is the public method that is used by outside callers - in our case, the cli package - to get a list of records. loadAllRecords is an internal method that is used by other internal methods.

The best solution to approach this is to remove the implementation of the ListRecords function and just call loadAllRecords inside instead. That way, the public ListRecords methods remains unchanged for all outside callers.

krishnaindani commented 3 years ago

Is this issue open to work, I would like to take a stab at it?

jwnpoh commented 3 years ago

The best solution to approach this is to remove the implementation of the ListRecords function and just call loadAllRecords inside instead. That way, the public ListRecords methods remains unchanged for all outside callers.

May I ask why this is preferable to simply removing the unexported function?

dominikbraun commented 3 years ago

The best solution to approach this is to remove the implementation of the ListRecords function and just call loadAllRecords inside instead. That way, the public ListRecords methods remains unchanged for all outside callers.

May I ask why this is preferable to simply removing the unexported function?

ListRecords provides the timetrace list records feature. At the moment, it does the exact same thing as loadAllRecords and nothing more. But what if the timetrace list records command requires some additional logic or validations in the future? In that case, if you would just have removed loadAllRecords and use ListRecords instead, this additional logic and validations would be executed for every other command that somehow loads records using ListRecords!

In short, they have two different responsibilities: Providing the list record feature vs. just loading records. It is just mere coincidence that these currently are the same two things. We want to keep them separated to indicate that these are two different responsibilities.

dominikbraun commented 3 years ago

Is this issue open to work, I would like to take a stab at it?

Yes, this is a good issue for getting started - are you ok with this, @jwnpoh?

jwnpoh commented 3 years ago

ListRecords provides the timetrace list records feature. At the moment, it does the exact same thing as loadAllRecords and nothing more. But what if the timetrace list records command requires some additional logic or validations in the future? In that case, if you would just have removed loadAllRecords and use ListRecords instead, this additional logic and validations would be executed for every other command that somehow loads records using ListRecords!

In short, they have two different responsibilities: Providing the list record feature vs. just loading records. It is just mere coincidence that these currently are the same two things. We want to keep them separated to indicate that these are two different responsibilities.

So, in a sense it's about "future-proofing" with a basic architecture that will be able to support additional functionality that will be built in the future.

Yes, this is a good issue for getting started - are you ok with this, @jwnpoh?

Sure thing! Please go ahead and assign this to @krishnaindani.

krishnaindani commented 3 years ago

Thank you. I will go through this and post if I have a questions.

krishnaindani commented 3 years ago

@dominikbraun I have created the PR https://github.com/dominikbraun/timetrace/pull/164, let me know what do you think.

dominikbraun commented 3 years ago

Closed by #164. Thanks, @jwnpoh and @krishnaindani!