Posts

quick note on scala.js, react hooks, monix, auth

quick note on scala.js, react hooks, monix, auth Reactjs hooks finally came out of preview in a recent version of React. scalajs-reaction has had support for hooks since they were in preview. React hooks seem like the hot new thing but for me the question is, do hooks help improve your code by improving maintainability, time to market, TCO, etc.? Let’s take a look using authentication as an example and employ monix , a reactive observable framework that also builds on cats . We will assume we are building a SPA. Does it improve your code and make your application & development experience better? Auth Auth processing can be complex. Many react auth examples you find in blogs like to show how to use “react-routing” and “auth” as a switch that determines which routes are protected or unprotected. Protected routes show application specific data. Unprotected routes show login content . Based on storing a “User” object in the browser session/local storage, th...

scala, kotlin, javascript, swift, dart, ...

scala, kotlin, javascript, swift, dart, ... This is a short note on programming languages (PL). In general, I do not really care about the PL as long as it is reasonably succinct and capable to solve the problem at hand. Ideally, one PL can be used to solve different problems to amortize the cost of learning a PL over multiple projects. Lately, everyone has defined their own programming language associated with their “platform.” Apple has Swift, google has dart (but uses java/js for other frameworks/platforms), Microsoft has C#, Sun had java, jetbrains has Kotlin. Some companies push their language as multi-platform, like Sun did, others evolve their PL to be multi-platform. The whole PL situation is a mess. Each language is much like the other. More or less C-like with some PLs having a few more clever features than others. A company defines their own PL to control their destiny and ensure they are not dependent on another organization to evolve their platform....

Ok, I think John was right about IO bifunctor..

Ok, I think John was right about IO bifunctor.. A while ago there a post on how IO in scalaz had both a F and an E to reflect the error type that is more specific than Throwable . Cat has MonadError and ApplicativeError that assumes the error is a Throwable . That has alot of implications all up and down the APIs. Just as F has to be everywhere, once you want to customize the error to be more specific than Throwable or not related to Throwable at all much like as described in https://typelevel.org/blog/2018/11/28/http4s-error-handling-mtl-2.html , you have to fix all the APIs all the way down. That means the post http://degoes.net/articles/bifunctor-io from John was kind of right in my eyes. Once you do the work to be anything more specific, you might as well be explicit everywhere since one the flood gates open, that’s it. You can always be less specific. I ran into this issue when creating some specialized scala HTTP client’s that have a wide variety of...

zio and scalatest

zio and scalatest If you use scalatest with zio , you need to recognize that there are a few ways to hook up scalatest. In the end, the problem is that scalatest uses exceptions to signal failure and that does not really work well with a library that models errors explicitly (or fp in general which treats errors as values). Some notes: scalatest has two async-test error channels–throwing an exception in open code and putting an exception into a Future . You can throw an exception or return an Assertion . The Assertion can be true or not true. However, a failed Assertion really just throws a TestFailedException immediately there is no “failed” Assertion value. You can get about as much debugging information from throwing an exception as you do an Assertion if you convert the zio Cause to a string. You can run async tests but you need to return a Future[Assertion]. I wanted to keep everything async so I could run this in JS when that’s available for zio. scala...

why I like scala.js

why I like scala.js scala.js is a scala compiler that compiles scala to javascript. There are many languages out there that compile to javascript. So why do I like scala.js? You’ll see that my argument could probably be made for other transpilation-capable languages as well. In no particular order: I already know scala so this allows me to re-use my skills. I was tired of JVM issue and uncertainties about its future. Although Oracle now seems to be investing in the JVM ecosystem, I am wary of historical trends. Also, the JVM is not critical in some types of program architectures. The other aspect is that scala has remnants of the JVM built into it. Life is tough, but I found that JS handles some things differently that I liked better, such as not forcing errors into a specific type (JVM only allows errors to be Throwables). Built on javascript, scala.js interop with javascript allows me to remove a large category of thorny issues that nearly all JVM language...

abstracting a react data fetcher in scala.js with cats, cats-effect

abstracting a react data fetcher in scala.js with cats, cats-effect Problem I put together a library for my small scala.js reasonreact-like facade scalajs-react that reflects the ReasonReact react component interface. When you use this facade to build web user interfaces you still need to fetch data. You have many choices for building a fetcher component including using an application state management library like redux/mobx or scala.js-based diode . The reasonreact component API includes a “reducer” built into every component so let’s just use that capability since its builtin and simple. I’ve found that with the builtin reducer, the need for global application state management is greatly reduced. If we can use a solid effects library then we should be all set. react@next has suspense and lazy loading. Unfortunately, these are not available in scala.js and may never be efficient in scala.js because scala.js cannot be easily compiled into separate “modules” wit...