TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

From ES6 to Scala: Basics

71 pointsby manxover 3 years ago

9 comments

LAC-Techover 3 years ago
<i>Variables</i><p>ES6 wins, &#x27;val&#x27; and &#x27;var&#x27; are annoying close to each other.<p><i>Primitive Types</i><p>Scala hands down. Not even close.<p><i>Functions</i><p>Scala is more expressive (well if you ignore the types). I wish more languages would do the Haskell thing and let you write the type sig at the top. Typescript functions get so long.<p><i>Anonymous Functions</i><p>Very similar, so calling it a tie.<p><i>Default, named and rest parameters</i><p>I&#x27;ll give this one to ES6 because the spread syntax feels more intuitive than * at the end of a type.<p><i>if, while, for, match control structures</i><p>Scala, because if is an expression and the for loop syntax is so concise. Also forget how nice nested looping was.<p><i>Classes</i><p>Scala. It&#x27;s just more concise, I always liked not having to write boilerplate constructors.<p><i>Case classes</i><p>I mean I guess Scala but I still prefer polymorphism to pattern matching (please don&#x27;t hurt me 2022 programmers)<p><i>Objects</i><p>Scala is shorter and more expressive here.<p><i>Traits</i><p>Scala because I never liked mutating objects, though I guess that&#x27;s the prototype way.<p><i>Option, the type safe undefined</i><p>I mean Scala because I guess it actually has it, but worth pointing out it&#x27;s like 30 LOC to define one for JS, depending on how many convenience methods you want.<p>----<p>Pointless post but this has made me kind of nostalgic for Scala. Maybe I own a computer fast enough to compile it now..
评论 #30007786 未加载
评论 #30007205 未加载
评论 #30020146 未加载
valenterryover 3 years ago
ScalaJS is awesome. Really solid and mature project, can totally recommend. It&#x27;s especially worth if you want to write complicated business logic and prefer to use Scala and the whole ecosystem of JVM libraries to do that.<p>The only thing that can be annoying is when you want to have a typesafe interface and have to write a lot of adapters for javascript libraries.<p>Fortunately there is even a project that can make use of typescript interfaces for those libraries, so that you can use them from ScalaJS more or less automatically: <a href="https:&#x2F;&#x2F;scalablytyped.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;scalablytyped.org&#x2F;</a>
usrusrover 3 years ago
With posts like these pointing out syntactic similarities between 21st century languages I always get this funny idea that there might be one &quot;true language&quot; they all converge to. It&#x27;s a silly idea, but we do see a general trend towards less imperative, more expression, across the whole board.<p>The biggest limiter that keeps people from replacing more local scope imperativity with expression style seems to me that very practical, almost depressingly mundane topic of debuger ergonomics. Stepping through and looking at intermediates just works, and it&#x27;s so easy that the mind can remain focused on the domain problem. If there was some miracle UI paradigm that provided similar ease of understanding to deeply nested expressions we&#x27;d hardly see any local vals at all. But I doubt this miracle UI will ever happen, we do know that it hasn&#x27;t happened in decades of trying to make excel expressions more approachable, with presumably millions of dollar thrown at the problem.
评论 #30009419 未加载
评论 #30008215 未加载
评论 #30008695 未加载
udbhavsover 3 years ago
Are there any frameworks or bindings for ScalaJS that can utilize the full expressiveness of the language and encourage idiomatic code? Because I would love to use Scala, Kotlin or even Dart compiled to JS but while it might easy to interface with JS libraries, major frameworks like React, Vue or Svelte are written with JavaScript idioms in mind and it&#x27;s much harder to wrangle with those since they usually dictate the entire architecture of your project.<p>I haven&#x27;t looked into the options but I would love to see something that feels like it was meant for the language from the ground up. Eg. Blazor probably qualifies because it was written specifically for C#
评论 #30007289 未加载
评论 #30007493 未加载
评论 #30009726 未加载
评论 #30007799 未加载
评论 #30008487 未加载
danmurover 3 years ago
I tried scalajs for a few tiny personal projects and I really like it. For me it would have to be a very application-y product to use this over typescript but I really liked the experience.
wiradikusumaover 3 years ago
How&#x27;s the compilation speed for compiling Scala to JS? Eons ago I used Scala for Android development. Let say it was a traumatic experience, so now I use Scala exclusively at the server side.
评论 #30007095 未加载
cervedover 3 years ago
<i>or C# before you may have noticed that type definitions are all over the place</i><p>nitpicking but CSharp rarely requires type definition, AFAIR it&#x27;s about the same as Scala
jmakerover 3 years ago
Decided to join this conversation and share my very recent experience.<p>We recently switched from Haskell to Scala for a new project due to the scope of the JVM ecosystem, in spite of having inline-java available in Haskell and GHC‘s excellent FFI.<p>We’re a team of mathematicians and physicists working in finance (not a fintech company though). Originally we chose Haskell because it felt as the most natural fit to us to expressing our domain models and producing great EDSLs. But now it looks like we‘re going to transfer all prospective projects to Scala.<p>It took some time to get used to it. At first the syntax felt unergonomic with Scala 2.13. Scala 3 &#x2F; Dotty seems to have improved over it significantly. And the functional programming libraries come to the rescue.<p>Scala’s standard build system, the sbt, is a boon, we got to really like it.<p>Then the differences in the semantics occupied me for a while, but I managed to quickly get used to them. Except perhaps for the local type inference. However, with certain GHC extensions, the program becomes undecidable anyway, and we have to specify the types here and there despite the global HM style inference. Overall it still feels like I can more easily express type-level programs in Haskell rather than in Scala. GHC Haskell feels just more expressive and powerful. But this is likely to mostly be due to me having written Haskell for several years now.<p>However, me and my folks all have become significantly more productive in Scala 2.13, and even more so with Scala 3, than we were used to with Haskell. You can do the easy things the easy way.<p>it’s awesome that in Scala you get the benefits of both worlds, and can commit to explicitly managing effects when you’re ready, laying ground for quick prototyping and cost-efficient MVPs. You simply get the opportunity to run more experiments in your business area rather than in the programming language theory.<p>With ScalaCheck there’s a QuickCheck for Scala, there’s also a couple more for the JVM. ScalaTest is more than good enough. MUnit is also nice. Due to the different type system, we had to extend our testing. There are also great integration and end-to-end testing frameworks for Scala and the JVM. So we’ve mostly covered our implementation risks. I’m unaware of anything for which GHC would provide stronger guarantees for our services.<p>We run and maintain several services written and executed on another managed and unmanaged platforms. We benchmarked some of their aspects with almost identical implementations in Scala, trying to translate certain idioms to a more natural Scala style. Well, we were surprised to see how extraordinarily well our Scala services performed, we even outpaced a highly optimized Go service, but we couldn’t match a modern and optimized C++ service whose implementations only few folks in my team understand, more or less.<p>In other words, we’re extremely satisfied with Scala 2.13 and 3.0 through 3.1. Binary compatibility is attained through cross-compilation with a couple caveats pertaining to certain old-style macros. So we’re mostly certain that we’re sticking now with Scala.<p>For front-end development, there‘s also GHCJS which transpiles Haskell to JS and PureScript along with Elm transpilers that are great for the front end, with Elm being extremely performant but sometimes quite painful. We went with some PureScript + React and were mostly satisfied. We haven’t dealt with front ends in Scala.js yet though.
评论 #30035218 未加载
throwaway4goodover 3 years ago
Looking at the examples; I am the only one who prefers the ES6 version?
评论 #30007031 未加载
评论 #30007016 未加载
评论 #30007152 未加载