https://github.com/tolitius/scalagist
a pair of "simplify me" glasses for Scala code
https://github.com/tolitius/scalagist
Last synced: 8 months ago
JSON representation
a pair of "simplify me" glasses for Scala code
- Host: GitHub
- URL: https://github.com/tolitius/scalagist
- Owner: tolitius
- Created: 2012-04-12T19:34:17.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2021-06-11T15:49:22.000Z (over 4 years ago)
- Last Synced: 2025-01-06T13:49:53.453Z (9 months ago)
- Language: Clojure
- Homepage:
- Size: 3.91 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
# What is Scalagist?
Scalagist started as an initiative to look at Scala code through a pair of "simplify me" glasses.
It is especially useful when coming from other "cleaner" languages (e.g. clojure, python, ruby, groovy, etc..) or reading Scala source that was written by other people, or you, but some time ago (which usually is the same thing).## Why Would Anybody Need Such a Thing?
Let's look at a simple [Monad](http://www.codecommit.com/blog/ruby/monads-are-not-metaphors) (don't worry if it sounds gibberish, just look at it as a simple trait/interface/class, etc..):
```scala
trait Monad[+M[_]] {
def unit[A](a: A): M[A]
def bind[A, B](m: M[A])(f: A => M[B]): M[B]
}
```I did an experiment and surveyed several devs. Here is what I found out. We mentally comprehend the code above in several steps:
* it is a "trait"
* named "Monad"
* it has two methods "unit" and "bind"
* "unit" takes an argument and returns "something"
* "bind" takes an argument and a function and returns "something"
* ... now let's figure out what those "constraints" 'M', 'A' and 'B' are, and apply them to the above digested "trait"What is interesting that for _every_ step, besides the last one, types (e.g. constraints) absolutely do not matter, and moreover they are _constantly_ on the way to comprehend what the code is about.
Given the rich type system and a "static typing" mindset that Scala is all about, types in Scala code _are_ important. And of course it means a lot that e.g. "unit" lifts A in M[A], but.. interestingly enough => it is **secondary** to the _understanding_ what the code does from just looking at it.
## So What Can Scalagist Do?
Scalagist takes the above Monad, or any other Scala source, and makes it a lot quicker to get the "gist" of what the code does without a visual clutter. Let's look at the Monad one more time:
```bash
$ cat Monad.scala
```
```scala
trait Monad[+M[_]] {
def unit[A](a: A): M[A]
def bind[A, B](m: M[A])(f: A => M[B]): M[B]
}
```
and now through the **scalagist glasses**:```bash
$ clj psy-scalagist.clj Monad.scala
``````scala
trait Monad {
def unit(a: A): M
def bind(m: M)(f: A => M): M
}
```A "gistified" code is not runnable, it is not even compilable, however .... it is a lot more readable, and makes it a lot quicker to get the gist.
#### _of course the fact that Scalagist is written in a couple of lines of Clojure is an intended pun :)_