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

README showing "old style" init-based StringSpec #177

Closed
russel opened this issue May 7, 2017 · 6 comments
Closed

README showing "old style" init-based StringSpec #177

russel opened this issue May 7, 2017 · 6 comments

Comments

@russel
Copy link

russel commented May 7, 2017

Should the README show the newer style of StringSpec where the block is in the superclass constructor rather than an explicit init block?

@sksamuel
Copy link
Member

sksamuel commented May 7, 2017

It's just a matter of preference rather than one being better I think. Personally I prefer the init block.

@russel
Copy link
Author

russel commented May 7, 2017

OK, no problem. Can you tell us the reason for your preference for init over construction? (I want to present the most idiomatic KotlinTest code possible at DevoxxUK 2017 on Thursday.)

@russel
Copy link
Author

russel commented May 8, 2017

@sksamuel I just reread https://discuss.kotlinlang.org/t/init-block-for-constructor-body/1703 does the above comment mean you have changed your position on the superclass constructor and init blocks? Fine if yes, I am just worrying about showing the most idiomatic code – but I already said that above I guess.

@sksamuel
Copy link
Member

sksamuel commented May 8, 2017

In that discussion I was arguing we should just be able to do,

class MyClass {
  val writer = new Writer
  writer.write("start")
  fun foo = ...
}

and dispense with the init block entirely.

But as to your question, we don't have a position on which is clearer. I'm not even sure which style most people use. I use the init block purely because that's just the way I've always done it. If we had to pick I'd say the init block was the idiomatic way. @helmbold may have a stronger opinion.

@helmbold
Copy link
Contributor

helmbold commented May 8, 2017

@sksamuel :-)
@russel If I had to define what most idiomatic, or "kotlinic", code would look like in this case, I'd say init. Actually I consider the block-passed-to-super-class-constructor-style a hack to come close to Scala syntax. Technically the test definition is part of the initialization and this is exactly the purpose of the init block.

@russel
Copy link
Author

russel commented May 8, 2017

Thanks. That works for me. I shall switch back to init blocks.

@russel russel closed this as completed May 8, 2017
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

3 participants