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

Improve samples #6454

Merged
merged 12 commits into from Dec 31, 2018
Merged

Improve samples #6454

merged 12 commits into from Dec 31, 2018

Conversation

wooster0
Copy link
Contributor

@wooster0 wooster0 commented Jul 27, 2018

This:

  • Revives dead links by updating them and using the WayBackMachine

  • Improves readability a bit by using abort "message" instead of

    puts "message"
    exit 1
  • Uses Time.measure instead of Time.now - time

  • Improves other minor things

Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this is not really useful.
Please don't just remove dead links. Either leave them as is or update to a new location.

samples/fannkuch-redux.cr Outdated Show resolved Hide resolved
samples/http_server.cr Show resolved Hide resolved
@z64
Copy link
Contributor

z64 commented Jul 27, 2018

@wooster0
Copy link
Contributor Author

@z64 Ah yeah using the waybackmachine for the links is a good idea.

@straight-shoota But I don't really see why it's a problem to replace the while trues with loop dos. It just reads better and is the prefered way to make a loop. And maybe a beginner takes some of these samples as a reference and then uses while true instead of loop do in his code..

@asterite
Copy link
Member

Thank you for the PR, but the code as it is right now is fine.
While true is better than loop in my opinion.
Using tuple instead of Array is not always better (tuple should just be used to return multiple values, or to group values, but it makes little sense to use in constants)
I could go on but I don't have much time right now.
Please don't merge this.

@hugoabonizio
Copy link
Contributor

Official samples should reflect idiomatic Crystal code and its best pratices. Although disagree with some changes (I'm included), this is a legitimate attempt to improve and bring consistency to samples code. I think we should agree on some basic changes (e.g. unifying while (true) and while true, using tuples for immutable data, etc), instead of keeping as is.

@asterite
Copy link
Member

Using tuples for immutable data is not always correct. In samples all arrays have the same type. An array should be used, not a tuple. A tuple is not an immutable array.

@asterite
Copy link
Member

Unifying code syntax is not important. The language allows for many styles, all are correct.

@straight-shoota
Copy link
Member

@r00ster91

But I don't really see why it's a problem to replace the while trues with loop dos.

And I don't see a problem with while true why that should be changed.

It just reads better and is the prefered way to make a loop.

Says who?

And maybe a beginner takes some of these samples as a reference and then uses while true instead of loop do in his code..

And that's perfectly fine. I'd even advice to do so.

Updating links to new locations is great. Code changes like content_type, too. Everything else doesn't make sense. Especially removing links and comments.

@Sija
Copy link
Contributor

Sija commented Jul 27, 2018

👍 for constants and abort.

@wooster0
Copy link
Contributor Author

wooster0 commented Jul 27, 2018

Hmmmm okay changed it back to while true.

@asterite
Copy link
Member

Also accessing constants is slower than accessing local variables. Please, there's no point to these PRs.

@wooster0
Copy link
Contributor Author

@asterite So I should revert the constants back to local variables? But at for example the SYMBOLS constant it says in the docs that theres currently a big performance problem because on every Int#times iteration a new array is created. And this is prevented by making SYMBOLS a constant. And that's also the case with SCENE I think.

But you are right with the SUDOKU string constant (I benchmarked). I'll change it.

@asterite
Copy link
Member

That's if you use an array literal inside a loop. Accessing a local variable inside a loop is fine.

@wooster0
Copy link
Contributor Author

Alright changed it.

@wooster0
Copy link
Contributor Author

I resolved the conflicts. Is anything left?

Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vielen Dank @r00ster91. That's diligent work!

@straight-shoota straight-shoota merged commit d12ce2c into crystal-lang:master Dec 31, 2018
@straight-shoota straight-shoota added this to the 0.27.1 milestone Dec 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants