Live data from Hacker News

Confessions of a Ruby Developer Whose Heart was Stolen by Scala

speakerdeck.com

41–50 of 74 posts

Re: Confessions of a Ruby Developer Whose Heart was Stolen by Scala

#41

Can someone comment on the current state of tooling in the Scala world. Last I had tried (some months back), SBT was extremely slow. Googling about SBT came back with a lot of complaints about the state of scala tooling back then.

I've been using Scala on Android + Intellij IDEA for about the past month after wanting to try something new[1]. Other than having to run it through proguard first, the compile process in Intellij is comparable to how it is with just Java. Scala plays nicely with Android and I have loved using it so far. Makes Android development a bit more fun than with just plain old Java. [1] https://github.com/yareally/android-sc…

ah - "Using proguard lets you build Scala without any extra plugins and sbt fiddling".

Seems like the tooling is still one of the more painful aspects of Scala. Kudos to Intellij, -1 to Scala.

Re: Confessions of a Ruby Developer Whose Heart was Stolen by Scala

#43
post #26

Earlier quoted context omitted.

As a Scala programmer I find Ruby syntax complex and inscrutable, almost like Perl.

As a Python programmer, I agree. Here's a Ruby snippet. I don't want to pick on this particular project [1], rather, I've found that this is typical of Ruby code: state_machine :state, initial: :active do after_transition any => :blocked do |user, transition| # Remove user from all projects and user.users_projects.find_each do |membership| return false unless membership.destroy end end My conclusion? Ruby's syntax is…

To be honest to understand those needs only the most basic understanding of Ruby. And I suspect you wouldn't be saying that if they'd used C style syntax for blocks, you'd understand it because that syntax is so prevalent in major languages.

I think you're making the mistake that because Ruby isn't a C-style language, the equivalent of a Latin script language, it's not understandable. It's just disadvantaged that you can't immediately make some assumptions about what the operators do based on previous experience.

Re: Confessions of a Ruby Developer Whose Heart was Stolen by Scala

#44
post #5

As a Ruby developer, I can't get through these sorts of slides. My other languages are C, Go and JavaScript, and the Scala syntax is totally inscrutable to me. Isn't the point of slides presenting something that can be easily absorbed? And I can't just quickly look up these declarations either — Scala is too complex for that given my experience level. Is there a gentle introduction talk for Scala around so I can eval…

As other posters have noted, there are some advance Scala features being used here. It's almost important to note that this talk was given at Scala Days, a conference for Scala programmers, so presumably the target audience is all ready expected to be familiar with Scala (and its syntax). Additionally, given that the speaker appears to be giving reasons why Scala can be a better choice than Ruby, his intended audience may be even smaller: Scala enthusiasts working at a Ruby shop who are trying to convince their coworkers/management to transition from Ruby to Scala... :P

Re: Confessions of a Ruby Developer Whose Heart was Stolen by Scala

#45
post #28

Earlier quoted context omitted.

Attention to syntax is what ruby is good at. Scala, Haskell treat syntax as a chore.

You don't know Haskell. > take 8 $ cycle [1,2,3]

  cycleM x = x `mplus` (cycleM x)

  take 8 $ cycleM [1,2,3]
might be more generic?

Re: Confessions of a Ruby Developer Whose Heart was Stolen by Scala

#46
post #35
post #4

Earlier quoted context omitted.

Why do microsoft and google insist on static compiled languages?

I've been thinking about private fields lately. In Python, a private field starts with an underscore, and someone who knows the culture of Python knows that the initial underscore encodes the notion "This field is not considered to be part of this library's public API, and it may go away or change behavior at any time, not necessarily a major version bump of this library, and if you look at it or change it, you'll be…

Java does not allow using reflection to access private fields !? Dude, just use C#.

Re: Confessions of a Ruby Developer Whose Heart was Stolen by Scala

#47
post #26

Earlier quoted context omitted.

As a Scala programmer I find Ruby syntax complex and inscrutable, almost like Perl.

As a Python programmer, I agree. Here's a Ruby snippet. I don't want to pick on this particular project [1], rather, I've found that this is typical of Ruby code: state_machine :state, initial: :active do after_transition any => :blocked do |user, transition| # Remove user from all projects and user.users_projects.find_each do |membership| return false unless membership.destroy end end My conclusion? Ruby's syntax is…

I'm a professional ruby programmer and your comments opened my eyes. If you don't know what's going on, then that does look like really icky code.

First off, parenthesis in ruby are optional. So calling a method can be done without parenthesis. The following two lines are the same:

    print()
    print
As are these:

    print(1, 2, 3)
    print 1, 2, 3
Here's some bits that might explain better what stuff does:

    :state
If you prefix a word with a colon that creates an object of type Symbol, with value "state", which is a bit like the string "state". The difference is that every mention of :state is a reference to the same object, while if you create a string "state", and a bit further do it again, those are two different objects. We use symbols because it runs faster for conditionals etc: to compare two symbols the interpreter only needs to check the reference, while to compare two strings, every character needs to be checked.

    initial: :active
This creates a Hash with one key-value, with key :initial, and value :active, both symbols. This is equivalent to typing :initial => :active which you encounter a bit further up.

    do |var1, var2| .... end
This creates a block, which is like a closure. The variable names between pipes are the arguments this block takes. Any code inside the block is only run when the block is called. In Ruby, every function can have a block passed by adding do ... end to it. Inside this function, the block can be called using the keyword yield, e.g. yield(1,2) to call the block with arguments 1 and 2. The find_each method will loop through every value of the Array it is called on, and run the block once for every value.

    project.users.present?
The question mark is a valid character for a method name, there's nothing special happening here, present? is just the name of a method. This could easily have been called is_present, or just present.

    a ? b : c
The ternary operator, the same in any language. It translates to "if a, return b, else return c".

    ->(arg1, arg2) { ... }
This creates a lambda, with arguments arg1 and arg2. A lambda is almost the same as a block, so this is almost the same as typing do |arg1, arg2| ... end

Re: Confessions of a Ruby Developer Whose Heart was Stolen by Scala

#48

Scala is a fantastic language, but my heart seems to resist due to things like this (slide 27/42): implicit class RichSeq[A, C[A]

The same thing in Haskell: cycle seq = circular where circular = seq ++ circular (or if you want to really golf it) cycle = fix . (++) Ok, to be fair the Scala code is a bit more generic as it works for any abstract sequence, but still, Scala's syntax is awfully heavy compared to Haskell. That's one reason I still prefer Haskell even though Scala is easier to sneak into enterprise projects thanks to JVM. Not to menti…

oo. I'd forgotten about fix.

  cycleM = fix . mplus
gives a nice generic version that works on Lists & Sequences but falls afoul of the monomorphism restriction, so it needs a type:

  cycleM :: (MonadPlus m) => m a -> m a
  cycleM = fix . mplus

Re: Confessions of a Ruby Developer Whose Heart was Stolen by Scala

#49
post #35

Earlier quoted context omitted.

I've been thinking about private fields lately. In Python, a private field starts with an underscore, and someone who knows the culture of Python knows that the initial underscore encodes the notion "This field is not considered to be part of this library's public API, and it may go away or change behavior at any time, not necessarily a major version bump of this library, and if you look at it or change it, you'll be…

Java does not allow using reflection to access private fields !? Dude, just use C#.

You might be able to do it if you replace the SecurityManager or something.

We may laugh now, but it actually seemed like a good idea at the time.

Remember, a big part of Java's early use case was running untrusted remote code ("Applets") in the browesr without prompting the user (a niche now filled by JavaScript [1] and a declining Flash). Which means you really don't want that code to be able to bypass all your security by using the reflection API to read and write things it's not supposed to.

Applets never really caught on, but now the language features are constrained by backward compatibility.

Also, C# isn't supported on Android AFAIK.

[1] Mostly unrelated to Java despite its name; see http://en.wikipedia.org/wiki/Javascript#JavaScript_and_Java

Post reply on HN