
DSL processing in Scala - dpapathanasiou
http://denis.papathanasiou.org/2015/07/26/dsl-processing-in-scala/
======
dpapathanasiou
I'm still a scala newbie, so any comments/suggestions are appreciated.

The full source code is here:
[https://gist.github.com/dpapathanasiou/b9d85685a0381f1deea0](https://gist.github.com/dpapathanasiou/b9d85685a0381f1deea0)

~~~
eranation
Well done on posting this! it's a great way to learn and share your experience
of learning new languages and get feedback. (just take the comments by face
value without any sentiments, you should learn from them, not make them
discourage you, ignore "my eyes are bleeding" type of comments or "Scala is
sooo complexxx" unless they have some really constructive criticism in
them...)

One tiny cosmetic suggestion that popped to my eyes since you asked for
comments :)

    
    
        def parseInputRange (s: String): Array[Int] = {
          val ab = s.split(":").map(_.toInt)
          (ab(0) to ab(1)).toArray
        }
    

the `to` method is inclusive on the end of the range, so it is the same as
until x + 1

Good luck!

------
rco8786
You should check out the Parser package in the scala standard lib. I maintain
a few DSLs using this and it's an absolute dream.

[https://wiki.scala-lang.org/display/SW/Parser+Combinators--
G...](https://wiki.scala-lang.org/display/SW/Parser+Combinators--
Getting+Started)

Code looks solid otherwise...at least where I work the style would be to favor
functional idioms over for loops but I think that's just personal preference.

~~~
kodablah
That has been removed from the Scala standard lib and is now distributed
separately. I am unsure how well it will be maintained by the community. As
the other commenter said, parboiled2 is a good choice using macros and it is
lightning fast. A lighter weight, runtime choice that was released recently is
fastparse[0].

0 -
[https://github.com/lihaoyi/fastparse](https://github.com/lihaoyi/fastparse)

~~~
rco8786
Oh wow very good to know. We're just now looking to get to 2.11(very large
codebase, upgrades are hard) so will definitely need to keep this in mind.

------
sklogic
Just for fun and to illustrate what's in my opinion is wrong with Scala
approach to DSLs, implemented the same DSL using a specialised meta-language:
[http://bit.ly/1U2PGlV](http://bit.ly/1U2PGlV)

The meta-language is available here:
[https://github.com/combinatorylogic/mbase](https://github.com/combinatorylogic/mbase)

------
tlarkworthy
For DSL implementation see string interpolation,
[http://stackoverflow.com/questions/10708136/how-to-create-
ds...](http://stackoverflow.com/questions/10708136/how-to-create-dsl-in-scala-
for-command-lines-with-minimum-extra-boilerplate)

------
birdsbolt
This doesn't seem to solve the puzzle. As much as DSL processing part is done,
the whole point of the puzzle was to make the operations sublinear in time
complexity.

------
anon3_
To anyone here who works on a large, scala codebase as a team: how do you
manage compilation times and narrowing code standards to a manageable set of
idioms?

~~~
ecopoesis
The "Scala is slow to compile" meme needs to die in a fire. At my last job we
had a large Scala codebase and it compiles faster then our similarly sized C#
project, and much faster then my current gig's much smaller Gradle based Java
8 project. We didn't do anything special: just a standard SBT project and a
few logical modules.

As for feature set, we did code reviews across the whole team to keep everyone
on the same page. That said, we used a very large part of Scala, and never
really made an attempt to keep out of parts of the language. Our biggest
battle was always with Scalaz, which we were always on the verge of adding,
but never got enough team buyin.

~~~
mavelikara
> The "Scala is slow to compile" meme needs to die in a fire.

Martin Odersky has commented many times [1] that scalac won't be as fast as
javac. The only link I could find right now is
[http://stackoverflow.com/questions/3490383/java-compile-
spee...](http://stackoverflow.com/questions/3490383/java-compile-speed-vs-
scala-compile-speed/3612212#3612212) which is rather old; but I remember
watching more recent videos (< 2 years old) where he makes the same points.

~~~
thescrewdriver
SBT uses incremental compilation. That might account for the difference
observed by parent (on incremental builds only)?

------
_pmf_
Yuck. No wonder Lispers look down on us.

