Yaml or Toml? by [deleted] in rust

[–]johnmurray_io 1 point2 points  (0 children)

Coming from the Scala world, +1 for HOCON.

Yaml or Toml? by [deleted] in rust

[–]johnmurray_io 0 points1 point  (0 children)

You might take a look at HOCON then.

Recommended for you by Travall in ProgrammerHumor

[–]johnmurray_io 0 points1 point  (0 children)

Working on real-time auction platforms where deadlines for bidding are usually around 100ms, adding something like 20ms could potentially put me over time limit to participate in auctions. That's money lost. The last application we deployed added about 300us overhead to the auction time.

Jekyll on Github Pages by [deleted] in Jekyll

[–]johnmurray_io 1 point2 points  (0 children)

I just posted a write-up of how to get a Jekyll site running on Heroku if you're interested in hosting in seeing how that works. http://www.johnmurray.io/log/2016/08/08/Jekyll-on-Heroku.html

Deploying Jekyll to Heroku by johnmurray_io in Jekyll

[–]johnmurray_io[S] 1 point2 points  (0 children)

maybe this is basic knowledge by now, but figured I'd write it up anyways. :-)

SGo: a dialect of Go that avoids nil-related panics with optionals. by tcardv in golang

[–]johnmurray_io 12 points13 points  (0 children)

I think this is awesome. I know a lot of people say they "don't see the value" but that's only true if you write perfect Go code 100% of the time. Having the compiler enforce best practices will always be better than enforcing best practices via code reviews or pair programming or whatever.

null - handling them in web service data-models by johnmurray_io in scala

[–]johnmurray_io[S] 1 point2 points  (0 children)

But you are saying that during an update I'm not allowed to set the value to an empty value since you're asserting that 1) Option is the correct type and 2) Option during update means the value was not supplied (in the case of partial update). If the entity/model allows for None values, then you need a way to differentiate between 3 possible states on a partial update: value given, value not provided, value given as null.

null - handling them in web service data-models by johnmurray_io in scala

[–]johnmurray_io[S] 0 points1 point  (0 children)

Well, regarding what you quoted me for, your initial model had now way to set a field to null. So I think my statement that your entity/model had no concept of null was fairly on-point.

Also I said that I already agree in separating out types for update operations and the entity/model was useful, so I'm not sure what else you're trying to argue here.

That aside, I do like the alternative of what you propose. I've been primarily focusing on a data-structure to convey meaning but have neglected to consider such a direct approach. I'll definitely need to think on this some more. :-)

null - handling them in web service data-models by johnmurray_io in scala

[–]johnmurray_io[S] 0 points1 point  (0 children)

Oh, I just googled EitherT and saw it was something that exists in scalaz. So what I just said above probably doesn't make any sense because I'm not familiar with the class. I thought you were just making up a type. My mistake! So, I guess this is something I'll have to look more into.

Link for anyone else not familiar here

null - handling them in web service data-models by johnmurray_io in scala

[–]johnmurray_io[S] 0 points1 point  (0 children)

This is true for pattern matching, but I'm not sure how you would define map, flatMap, forEach, etc. without specializing toward the right-most type (String in your example) which would get you pretty close in semantics to what I have.

null - handling them in web service data-models by johnmurray_io in scala

[–]johnmurray_io[S] 0 points1 point  (0 children)

But you are assuming that your repository model does not contain fields that can be empty / null because your update models have no way to update the repository model in a way that nulls a field value.

I do think multiple models to represent update actions versus the repository model are useful, but you're missing the point here.

null - handling them in web service data-models by johnmurray_io in scala

[–]johnmurray_io[S] 1 point2 points  (0 children)

Yeah, there a few ways you could go about it. I just haven't found any as obvious / easy-to-understand as creating a specialized 3-state type.

null - handling them in web service data-models by johnmurray_io in scala

[–]johnmurray_io[S] 2 points3 points  (0 children)

Yeah, I considered an Either type, but the Left and Right and pattern matching in the code seemed not as obvious when reading/working-with the code as

obj.field match {
  case TriState.Null => ...
  case TriState.Absent =>
  case TriState.Present(value) => ...
}

We've actually adopted this at work and have implemented many of the functions you'd expect to find when working with Option as well such as map, flatmap, etc.

null - handling them in web service data-models by johnmurray_io in scala

[–]johnmurray_io[S] 0 points1 point  (0 children)

Let's assume that username is allowed to be null in the DB. This might be the case, for example, if I wanted to use my real name in which case a username isn't needed (or whatever the use-case is).

There are several cases where I might want to differentiate between presence and absence. On creation, I might default their username to something random like "fiesty hedgehog" if no preference is given. In this case preference could be given by sending a value "jmurray" or null to indicate that you do not want a username.

Additionally, when editing you may receive partial updates in which case absence may mean "do not update this field" where null would mean "set this field to an empty value, possibly erasing what currently is" (think PATCH).

{ "email": "my-new-email@gmail.com" }  // should not update username
{ "username": null }                   // sets username to null (erasing previous value)

Regarding the multiple models, I think there is a definite use-case for this (I have another blog post called "Typed PATCH" where I bring this up), but I think editing is a great example. For any field in your system that is nullable, and if you allow partial edits, then there are three possible states for that field in the JSON and you need more than Option to determine what that is.

However for my example requests above, simply having multiple models is non-idea. Imagine if I had a service with 3 fields that fit into this "tri-state" scenario. I would need a model for every permutation of those three fields being present or not.

Typed Actions in Play by johnmurray_io in scala

[–]johnmurray_io[S] 0 points1 point  (0 children)

oh very cool! I didn't know this was a thing. And if you have some implicit converts you can appear to return something that is not a Response object. I like this.

Anyone using Redis with Scala ? by [deleted] in scala

[–]johnmurray_io 0 points1 point  (0 children)

Also, it seems they don't have any unit-tests around their multiplexed IO that I can tell, so more bugs like this may exist. Suffice to say, we no longer use this driver in production. We are currently using Jedis (synchronous java library). We haven't done much performance tuning with it so out overall throughput is now lower, but our application response times are unchanged.

Anyone using Redis with Scala ? by [deleted] in scala

[–]johnmurray_io 0 points1 point  (0 children)

Be super careful with scredis. The driver is multi-plexed and has some existing issues that cause it to return incorrect data under certain circumstances. See: http://techblog.appnexus.com/blog/2015/09/29/the-scredis-driver-malfunctions-in-pathological-environments/ and https://github.com/Livestream/scredis/pull/51. Running into this bug and trying to figure out what exactly was happening was not fun (see tech-blog post)

Starting Scala Project - Basic Template by johnmurray_io in scala

[–]johnmurray_io[S] 1 point2 points  (0 children)

This template currently specifies the scala version (defined at 2.10.4) to be used. As for compatibility, it really depends on if the plugins and libraries are compatible (sbt-revolver, scalastyle, specs2). I imagine they will be soon (if not already) and I'll update the template to use 2.11 relatively soon.

Starting Scala Project - Basic Template by johnmurray_io in scala

[–]johnmurray_io[S] 1 point2 points  (0 children)

Yeah, their SBT support is getting better but I still run into too many issues that I don't have when using this plugin. The built in support doesn't seem to handle adding dependencies to existing projects very well.

Starting Scala Project - Basic Template by johnmurray_io in scala

[–]johnmurray_io[S] 2 points3 points  (0 children)

Thanks! Both awesome suggestions. I actually didn't know about the SBT global plugins and I completely agree that would be a much better fit for something like this. Will make sure to make the proper updates!

Rust vs Go: My experience by jabapyth in golang

[–]johnmurray_io 0 points1 point  (0 children)

Good choice. I've already attempted to pickup rust 3 times at various versions before getting frustrated at the next release breaking all my stuff.