Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explanation on a point #17

Closed
agnivade opened this issue Jan 23, 2018 · 4 comments
Closed

Explanation on a point #17

agnivade opened this issue Jan 23, 2018 · 4 comments

Comments

@agnivade
Copy link
Contributor

use time.Before and time.After to compare time, avoid time.Sub

What is the reason behind this ?

@cristaloleg
Copy link
Owner

Just to make it clear.
When I see time.Sub at first I think: what you will do with a difference later?
But in most cases it's used only for comparison.
Using time.Before or time.After it makes much clear from the begging, less distractions during code review, refactoring and slightly error prone.

@agnivade
Copy link
Contributor Author

Oh I must have misunderstood. I could not imagine that people use time.Sub to compare. Do they check if the duration is greater than 0 ?

Anyways, I think the description can be worded better to indicate that it's a code improvement. Just by reading the line, it sounded that there is some performance reason behind it.

@cristaloleg
Copy link
Owner

Yeah, they use 😉
Can you make a PR with an explanation?

@agnivade
Copy link
Contributor Author

Sure.

@agnivade agnivade mentioned this issue Jan 23, 2018
yangwenmai added a commit to yangwenmai/go-advices that referenced this issue Jan 25, 2018
cristaloleg pushed a commit that referenced this issue Apr 20, 2018
* add some advices

* format go code block

* add some advices && toc

* improve advices

* remove #17

* add some advices

* add math/rand concurrency-safe advice

* update advice
cristaloleg pushed a commit that referenced this issue May 2, 2018
* add some advices

* format go code block

* add some advices && toc

* improve advices

* remove #17

* add some advices

* add math/rand concurrency-safe advice

* update advice

* add some advices
cristaloleg pushed a commit that referenced this issue May 11, 2018
* add some advices

* format go code block

* add some advices && toc

* improve advices

* remove #17

* add some advices

* add math/rand concurrency-safe advice

* update advice

* add some advices

* early bounds check to guarantee safety of writes below

* early bounds check to guarantee safety of writes below

* remove Redundant code
cristaloleg pushed a commit that referenced this issue Aug 29, 2018
* add some advices

* format go code block

* add some advices && toc

* improve advices

* remove #17

* add some advices

* add math/rand concurrency-safe advice

* update advice

* add some advices

* early bounds check to guarantee safety of writes below

* early bounds check to guarantee safety of writes below

* remove Redundant code

* update

* add go-critic

* add link to ZH

* add some advices && DEL another ZH-CN
yangwenmai added a commit to yangwenmai/go-advices that referenced this issue Nov 14, 2018
cristaloleg pushed a commit that referenced this issue Dec 6, 2019
* add some advices

* add some advices && toc

* improve advices

* remove #17

* add some advices

* update advice

* add some advices

* early bounds check to guarantee safety of writes below

* remove Redundant code

* add some advices

* chore(README_ZH): update some go advices ZH

* chore(README_ZH): update some go advices ZH
yangwenmai added a commit to yangwenmai/go-advices that referenced this issue Feb 25, 2020
cristaloleg pushed a commit that referenced this issue Feb 25, 2020
* add some advices

* chore(README_ZH): update some go advices ZH

* improve advices

* remove #17

* add some advices

* chore(README_ZH): update some go advices ZH

* docs(README_ZH): update some advices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants