|
loinburger posted:I've been a Java (and to a lesser extent a C#) programmer for awhile, and about two years ago I took a job programming in Scala. I liked Scala the language, but I got frustrated with a small but extremely vocal portion of the Scala community (among which were some of my co-workers), namely Haskell programmers who wanted Scala to be exactly like Haskell. For example, we'd have a bunch of big rear end thread-local objects, and every time we updated a field we'd have to copy the entire object because Everything Must Be Immutable Just Like In Haskell, and then we'd wonder why the garbage collector was running too often. Or during a code review I'd be criticized for using classes instead of using whatever the Haskell-ish equivalent would be. Another problem is that we couldn't just use a mature Java library for something (the library might return nulls!), we had to hunt for an alpha Scala library instead. When the startup eventually went bankrupt I went back to Java. It's the same where I work, but most of the OOP guys are slowly being converted to FP. I can appreciate both sides of the argument, but in our case the existing OOP implementations are horrible, multi-layered abstractions that are incredibly obtuse. That's not to say that OOP is horrible, but holy poo poo do I hate layers...and the cake pattern. Honestly, the myriad of styles possible in Scala is it's worst attribute. There are just too many ways to write some horribly confusing code. Also, I wish Haskell people didn't talk so drat much about Haskell.
|
# ? May 7, 2015 04:14 |
|
|
# ? May 11, 2024 13:17 |
|
A couple months after I started working at the Scala shop they hired a guy who'd had prior experience with Scala, but up until then nobody really knew how to use it and my only prior FP experience was with Scheme, so I just treated it like Java with weird and inconvenient syntax.code:
|
# ? May 7, 2015 05:24 |
|
Ruzihm posted:Argh. I am trying to do a "manual install" of sbt, but it's still trying to reach out to the internet. What gives? You could try offline mode
|
# ? May 7, 2015 17:58 |
Sedro posted:SBT will check for updates to things, especially if you depend on SNAPSHOTs. I saw that and gave it a shot. SBT refused to listen to anything until it downloaded its necessary packages. I went ahead and just let it do that vv. No big deal.
|
|
# ? May 7, 2015 18:38 |
|
jpotts posted:It's the same where I work, but most of the OOP guys are slowly being converted to FP. I can appreciate both sides of the argument, but in our case the existing OOP implementations are horrible, multi-layered abstractions that are incredibly obtuse. That's not to say that OOP is horrible, but holy poo poo do I hate layers...and the cake pattern. Cake pattern is terrible. I don't understand why anyone would chose it over constructor injection.
|
# ? May 8, 2015 01:35 |
|
KernelSlanders posted:Cake pattern is terrible. I don't understand why anyone would chose it over constructor injection. Agree.
|
# ? May 8, 2015 03:28 |
|
KernelSlanders posted:Cake pattern is terrible. I don't understand why anyone would chose it over constructor injection. The rationale in Odersky's talk is that interfaces (well, traits) simply can't express the type constraints he required without casting, and he (unsurprisingly) preferred type safety. Although IIRC, Dotty's gone with a different abstraction. It is quite useful in those situations but some people decided it should be used for everything.
|
# ? May 8, 2015 07:09 |
|
I've experimented some with the cake pattern and really struggle to come up with solid justifications for doing so. Has anyone done much with macwire, or used it as outlined here? http://di-in-scala.github.io/ I have to say I like the high level idea: start with dead simple constructor injection, and then make use of more advanced techniques and tools as you need them. Sharp contrast with the cake pattern, which is more "all boilerplate all the time", and makes things often very difficult to construct dynamically based on configuration.
|
# ? May 10, 2015 04:50 |
|
I've been mucking about with the Play framework and am looking for a half decent ORM to use with it. I see it comes with Ebean, anyone have opinions on it? If it turns out to be junk I might just use spring with jpa. I also took a look at squeryl but it didn't seem that fantastic.
|
# ? Jun 4, 2015 01:49 |
|
I used Slick up until about six months ago - it may have gotten better since then, but at the time vanilla Slick was reliant on case classes and tuples and all of their attendant restrictions. However, it's got a code generation tool that lets you bypass those restrictions (generating classes instead of case classes to represent rows), and that also saved us a boatload of time in refactoring (this was a startup and so the database kept changing on us) because the code generation tool would read the metadata from the database tables and produce appropriately typed row classes. Almost all of the database writes were from JSON in POST/PUT requests, and so the code generation tool let us generate code to: 1. Validate the JSON (ensure that each key corresponded to a valid column name) 2. Loop through the JSON, convert its untyped values to the appropriate type (or throw an exception), and update the appropriate row objects 3. Update the appropriate join tables to keep the database consistent (this was done with a hand-coded Map, we were planning on automatically generating this Map using foreign key constraints but then the company more or less went bankrupt) I can give you some example code if you want. The learning curve was a bit steep, but in the end something like 25% of our back-end code was being generated by Slick.
|
# ? Jun 4, 2015 04:20 |
|
loinburger posted:I used Slick up until about six months ago - it may have gotten better since then, but at the time vanilla Slick was reliant on case classes and tuples and all of their attendant restrictions. However, it's got a code generation tool that lets you bypass those restrictions (generating classes instead of case classes to represent rows), and that also saved us a boatload of time in refactoring (this was a startup and so the database kept changing on us) because the code generation tool would read the metadata from the database tables and produce appropriately typed row classes. This is really interesting and I would definitely be interested in viewing some example code. Thanks for the option, I'll look into it. EDIT: Wait a minute, if Play and Slick are both made by TypeSafe, why the heck haven't they started using Slick with Play? Mellow_ fucked around with this message at 03:36 on Jun 5, 2015 |
# ? Jun 5, 2015 03:29 |
|
We used Slick with Play, dunno why they're not bundled - maybe because vanilla Slick is still a bit flaky Code - I've done a half-assed job of sanitizing it by replacing all instances of the company's name with "companyname" - I can provide more code if you want, this is just what I thought were the relevant parts The slick-codegen folder has all of the code generation stuff - this was run as a separate project. SlickCodeGenerator.scala is where we read all of the database metadata and generate the code. ModelTransformations.scala has all of the customizations, e.g. each table has a "blacklistedColumns" set that contains the columns that are in the database but shouldn't be in the row object. slickTemplate.scala.txt has the code template. I was responsible for ModelTransformations and the template, we hired one of the Slick developers to write SlickCodeGenerator. The store folder has some sample output in the models sub-folder; the generic sub-folder has the superclasses for the DAOs (RichTable) and the row objects (ScalatraRecord, from when we were using Scalatra instead of Play, which we never got around to renaming). The auto_generated folder has the output from slick-codegen, while the rest of the files in the models directory inherit from a file in the auto_generated directory (this is so that we can customize the auto generated classes). So inheritance goes generic -> auto_generated -> hand_coded, where we use usually only reference the hand_coded or generic classes everywhere else in the program. loinburger fucked around with this message at 15:15 on Jun 5, 2015 |
# ? Jun 5, 2015 04:36 |
|
Play does support slick. https://www.playframework.com/documentation/2.4.x/PlaySlick There's also Anorm which is a lightweight Slick.
|
# ? Jun 5, 2015 05:46 |
|
I've been pretty happy with spray for my toy web apps although serving the original html is a bit clunky.
|
# ? Jun 10, 2015 05:47 |
|
loinburger posted:stuff I'm sorry that project was so hosed up, even from the start. And it never really got much better. The codegen stuff helped with a lot of the suffering though.
|
# ? Jun 10, 2015 06:17 |
|
That was a fun project, it's just a shame we never got to finish it
|
# ? Jun 10, 2015 15:52 |
|
loinburger posted:That was a fun project, it's just a shame we never got to finish it Hey you don't have PMs, can you please email me? scott at thereceptor dot net You gotta sign your doc
|
# ? Jun 10, 2015 19:57 |
|
Running into an issue with Slick and am unsure how to troubleshoot. Have a database table with a column which is of type Time. When I attempt to query this column I receive the above error message. Has anyone encountered this issue before? I know its an issue with the type because if I change it to integer or something else the query works perfectly. error code:
code:
code:
DholmbladRU fucked around with this message at 13:20 on Jun 16, 2015 |
# ? Jun 16, 2015 01:01 |
|
DholmbladRU posted:Running into an issue with Slick and am unsure how to troubleshoot. Have a database table with a column which is of type Time. When I attempt to query this column I receive the above error message. Has anyone encountered this issue before? I know its an issue with the type because if I change it to integer or something else the query works perfectly. I see no above error message
|
# ? Jun 16, 2015 03:39 |
|
Steve French posted:I see no above error message ops. edited original content
|
# ? Jun 16, 2015 13:21 |
|
Is DateTime from joda.time? I'm pretty sure that Slick only supports the old standard library dates (util.Date, sql.Time, sql.Timestamp)
|
# ? Jun 16, 2015 18:11 |
|
loinburger posted:Is DateTime from joda.time? I'm pretty sure that Slick only supports the old standard library dates (util.Date, sql.Time, sql.Timestamp) Yes DateTime is joda
|
# ? Jun 16, 2015 18:57 |
|
Try storing a "new java.sql.Time(someDate.getMillis())" instead, at least until Slick adds support for joda.time or java.time
loinburger fucked around with this message at 19:29 on Jun 16, 2015 |
# ? Jun 16, 2015 19:16 |
|
loinburger posted:Try storing a "new java.sql.Time(someDate.getMillis())" instead, at least until Slick adds support for joda.time or java.time In the case class or in the class LU?
|
# ? Jun 16, 2015 20:15 |
|
In the case class - then you can do something like add implicit conversions for java.sql.Time <-> joda.time.DateTime to make your life easier, since java.sql.Time is a bit poo poo
|
# ? Jun 16, 2015 20:50 |
|
You can tell slick how to map types when you define your table. You can also extend the Driver and put this stuff in there.code:
|
# ? Jun 16, 2015 21:42 |
|
Has anyone had any success using Spark's DataFrame object? Am I missing something or is the whole thing just a horrendously designed API that can't possibly be useful for anything? Like in pandas you can df['c'] = df['a'] + df['b']. Is there a simple way to do that in spark Dataframes? What about df['idx'] = df.id.map(lambda x: np.where(ids == x)[0][0])?
|
# ? Jul 7, 2015 19:11 |
|
KernelSlanders posted:Has anyone had any success using Spark's DataFrame object? Am I missing something or is the whole thing just a horrendously designed API that can't possibly be useful for anything? Like in pandas you can df['c'] = df['a'] + df['b']. Is there a simple way to do that in spark Dataframes? What about df['idx'] = df.id.map(lambda x: np.where(ids == x)[0][0])? Nope. You can try something like .withColumn(), I guess, but IIRC there's no straight-forward way to do it. How many other folks in here are doing Scala and Spark work? We just launched a small test cluster recently, and my life is now figuring out how we leverage that plus our existing Vertica (please kill me) store. Also now learning Scala because I've found functional programming in Python - my primary day to day language - a bit of a hassle, especially since most Spark docs and examples and use cases happen in Scala or apparently Clojure.
|
# ? Jul 26, 2015 06:48 |
|
Why isn't ArrayBuffer[String] an Iterable[String]? Let's say I have an ArrayBuffer like this: code:
In Scala I have to import asJavaIterable to get an implicit conversion from ArrayBuffer[String] to Iterable[String] so that the same thing works: code:
I can also get it to work doing this: code:
|
# ? Aug 6, 2015 02:20 |
|
Cryolite posted:Why isn't ArrayBuffer[String] an Iterable[String]? java.lang.Iterable is not the same as scala.collection.Iterable. Scala's Iterable's iterator method collides with the Java one, so classes can only implement one of them. :_* expands the argument to fill the rest, either by converting to an Array for a variadic function, or by unpacking a tuple.
|
# ? Aug 6, 2015 03:12 |
|
Generally, you don't want to user the Java library if there's a Scala library that does the job. The interfaces just tend to be clunky in Scala code. I'm not sure why you feel String.join(",", a) is cleaner than a.mkString(",") but if you really want to do so, you can always define your own function.code:
|
# ? Aug 6, 2015 05:45 |
|
KernelSlanders posted:I'm not sure why you feel String.join(",", a) is cleaner than a.mkString(",") Oh no, I definitely like it more, I was just trying to take a technique I did know and use it as a chance to learn more about how things work.
|
# ? Aug 20, 2015 03:26 |
|
How would you generate the first 10 even fibonacci numbers in Scala? I overheard someone say they use this as an interview problem so I did it in C# by generating an IEnumerable<int>, filtering to the even ones and then taking 10 like this: code:
code:
code:
How would you do it? Also, what exactly is the fib2 function above doing? I know that #:: creates a stream with a head of 0 and a tail of fib2.scanLeft(1)(_ + _), but if it recursively calls fib2 again won't that tail start with 0, and then the next call to fib2 starts with 0, and so on? It works, but it seems like it shouldn't to me.
|
# ? Aug 20, 2015 03:26 |
|
Stream is an attempt at a functional approach to something like the C# yield return although it's probably closer to a generator comprehension in python. That's probably the closest to idiomatic of the approaches you listed. Does this example make more sense?code:
By the way, your implementation of fib2 isn't great because that scanLeft will end up recomputing the entire sequence for every element. Try this to see why: code:
|
# ? Aug 20, 2015 16:25 |
|
Fill in the blank:code:
java.util.NoSuchElementException: key not found: wut (verbatim) Steve French fucked around with this message at 03:01 on Sep 12, 2015 |
# ? Sep 12, 2015 02:58 |
|
Steve French posted:Fill in the blank: Here's a hint / secondary challenge. Same method definition, but different code in the blank and instead of the last line, this: code:
|
# ? Sep 12, 2015 03:14 |
|
Sure, just change the default valuecode:
|
# ? Sep 12, 2015 03:42 |
|
Sedro posted:Sure, just change the default value Hrm, I suppose the question was a bit underspecified, since clearly there are other ways than I had in mind to get that behavior. This came up due to some surprising behavior of mapValues, which actually creates a view under the hood, even though its type signature doesn't really indicate that (e.g. you can't call force on its result). code:
|
# ? Sep 12, 2015 03:54 |
|
That is odd. I guess I'd prefer if mapValues was eager and Map.view could be used for laziness
|
# ? Sep 12, 2015 05:05 |
|
|
# ? May 11, 2024 13:17 |
|
Real dumb question but it's been impossible to Google. Looking at the official tutorials and in this examplecode:
e: oh are those methods generics that actually take no arguments? KICK BAMA KICK fucked around with this message at 05:31 on Oct 10, 2015 |
# ? Oct 10, 2015 05:28 |