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

Scala API - please review #51

Closed
wants to merge 66 commits into from
Closed

Conversation

Narigo
Copy link
Member

@Narigo Narigo commented Sep 18, 2013

Please do not integrate, just review and send me notes about it :)

It should have the complete Java API now, but there are some things
about it:

  1. The event bus is hard to do as handlers which get implicitly
    converted create new objects. That means that these new objects won't be
    able to be unregistered later. I've added two methods that should be
    able to deal with it, but maybe you have a better idea how to handle this.

  2. I've copy & pasted most of the JavaDoc into the Scala stuff. I guess
    there'll be some comments that don't work out very well.

  3. I did not implement any(!) tests and actually deleted what was there
    before. Mostly because there is no testtools for Scala yet and using the
    Java API to test the Scala API is not really nice to do. Is someone
    working on testtools already? Would be very nice to use it then and test
    everything with it.

As I've done quite a bit of work now during the nights, I'd really like
to see other people working on it - I'd be really happy if someone else
would be able to implement the tests and fix what's wrong with the code.

  1. There are a lot of methods like this, to have a fluent API:
class SomeWrappedJavaClass {
  def doStuff(someParameter: String, doneHandler: String => Unit): SomeWrappedJavaClass = ...
}

I'm not sure what would be better: The one posted above or def doStuff(someParameter: String)(doneHandler: String => Unit)= ... to be
able to call it like this: doStuff("hello") { answer => println("got a reply: " + answer) }

  1. RouteMatcher - I'd like to kick this out of the API completely. As a
    replacement we could add a real idiomatic RouteMatcher, which might look
    like this:
class MyRequestHandler extends RouteMatcherTrait {
  def requestHandler(request: HttpServerRequest) = {
    case Get("/") => SendFile("index.html")
    case Post("/login") =>
      if (checkLoginPostData(request)) {
        SendFile("logged_in.html")
      } else {
        SendFile("error.html")
      }
  }
}
  1. Using Futures and Promises, maybe we could use one of them as a
    replacement for AsyncResult...? It would also be extremely nice to have
    them as a return value of functions, so working with the file system
    could look like this:
for {
  firstFile <- fs.open("some_file.txt")
  secondFile <- fs.open("some_other_file.txt")
  firstText <- fs.read(firstFile)
  secondText <- fs.read(secondFile)
} yield {
  firstText + secondText
}

That's not a good example, but think about "scripting" in this style -
open file, read it, transform it, write the output somewhere else.

@galderz
Copy link
Contributor

galderz commented Sep 18, 2013

@Narigo Looking into this, looks very good at first glance :)

I'll work on the Scala testtools stuff once I've finished getting Scala scripts to run as well as Scala classes.

*
* @return The internal type instance.
*/
def toJava(): InternalType = internal
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make this package private for org.vertx.scala? This way we'd avoid exposing it to end users.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure about this, actually. We could use it whenever the Java API adds new functionality and needs some Java type...

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's more important users don't get somehow attached to the Java API. I'd rather keep it private and if people complain, maybe open it up. The opposite move, having it public and then wanting to make it private it's more problematic. IOW, if it doubt, leave it out. Let's expose as little as possible that gets the job done.

Plus, even if the Java API adds new functionality, we probably wanna wrap it somehow and we probably don't want people to use it as is in the Java world.

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed in IRC, I'd private[scala] trait VertxWrapper and let def toJava() stay public. This way developers can get the internal Java value, if they need it for other APIs (like includeable modules).

/**
* Create a new {@code Pump} with the given {@code ReadStream} and {@code WriteStream}
*/
def createPump[A <: ReadStream, B <: WriteStream](rs: ReadStream, ws: WriteStream) = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not name these createPump methods apply?

Copy link
Member Author

Choose a reason for hiding this comment

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

To be consistent with the Java API - I guess that would make it easier for devs coming from other languages to use it. Shall we provide both?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for both

@galderz galderz closed this Sep 18, 2013
@galderz galderz reopened this Sep 18, 2013
@galderz
Copy link
Contributor

galderz commented Sep 18, 2013

Sorry guys, closed by mistake :)

@Narigo
Copy link
Member Author

Narigo commented Oct 1, 2013

Here is another batch of additions for the Scala API. We've fixed various bugs and added a lot of tests (thanks @SaschaSchmidt !). Before you ask: Yes, he has signed the Eclipse CLA ;)

After we fixed the classloading issues with @purplefox , we have trouble doing the scripting tests. I've added another script to run like the integration_tests scripts from the gradle template, but that didn't work either. Please someone have a look - I have no clue what we'd have to change to get them running again.

Thanks for reviewing!

@Narigo
Copy link
Member Author

Narigo commented Oct 2, 2013

@raniejade println is used only in the ScalaInterpreter right now. We can kick them out as soon as it works... Could you have a look into it? The only failing tests are for the ScalaInterpreter right now and if they are ok, we should be able to merge this quite soon.

@raniejade
Copy link
Contributor

Sure thing, I'll check on it right away after I have the time.

On Wed, Oct 2, 2013 at 8:49 PM, Joern Bernhardt notifications@github.comwrote:

@raniejade https://github.com/raniejade println is used only in the
ScalaInterpreter right now. We can kick them out as soon as it works...
Could you have a look into it? The only failing tests are for the
ScalaInterpreter right now and if they are ok, we should be able to merge
this quite soon.


Reply to this email directly or view it on GitHubhttps://github.com//pull/51#issuecomment-25529738
.

Ranie Jade Ramiso
Software Engineer | Open Source Enthusiast | Professional Slacker
Philippines

w: raniejaderamiso.com
e: raniejaderamiso@gmail.com

@Narigo
Copy link
Member Author

Narigo commented Oct 14, 2013

Did you manage to have a look at the interpreter stuff @raniejade ?

@raniejade
Copy link
Contributor

No, sorry my I'm currently out of the country (business trip, sigh). No
laptop too :(, probably gonna buy one next week :D.

On Tue, Oct 15, 2013 at 9:24 AM, Joern Bernhardt
notifications@github.comwrote:

Did you manage to have a look at the interpreter stuff @raniejadehttps://github.com/raniejade?


Reply to this email directly or view it on GitHubhttps://github.com//pull/51#issuecomment-26293977
.

Ranie Jade Ramiso
Software Engineer | Open Source Enthusiast | Professional Slacker
Philippines

w: raniejaderamiso.com
e: raniejaderamiso@gmail.com

@Narigo Narigo mentioned this pull request Oct 14, 2013
@Narigo
Copy link
Member Author

Narigo commented Oct 15, 2013

tests are still missing, but DnsClient is included now. Next up: Datagram stuff...

@galderz
Copy link
Contributor

galderz commented Oct 17, 2013

Closing. I've fixed the ScalaInterpreterTest and squashed commits a bit for easier management in #63

@galderz galderz closed this Oct 17, 2013
@galderz
Copy link
Contributor

galderz commented Oct 17, 2013

Everyone, comment on #63 ASAP :)

@galderz
Copy link
Contributor

galderz commented Oct 17, 2013

FYI @raniejade no need to look at the interpreter stuff any more :)

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

Successfully merging this pull request may close these issues.

None yet

6 participants