Magnus Holm
unread,Mar 19, 2014, 5:00:19 PM3/19/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to q-dat...@googlegroups.com
Hi,
I've been playing a bit with Q and I have a few thoughts.
Here's the context: I'm building a REST API and want to use Q to
specify all of the data types. The goal is that the system files
serves two purposes: *Validating* the input and *documenting* the data
types.
The documentation is the most important aspect here, so I want the
system files to be readable (and usable) to as wide audience as
possible. This means that anything that's Ruby-specific has to go.
However, I find the support for host-independent system a bit …
lacking. Some examples:
## ADTs depends on a constant name (so it's not actually host-independent)
ADT seems to be the intended feature when you want to use custom Ruby
classes for your data structure. However, whenever I try to use them
as such, I end up with code like this:
```
Article = .MyApp::Models::Article <article> {
…
}
```
* This requires the full constant name
* I'll have to write "article" three times
## Why can't I just hook up a tuple to a Ruby class?
An "article" in this system is just a dumb tuple; there's not multiple
possible representations (as with colors) of an article. Yet, I still
want dressing to produce instances of my Article-class.
I want to do something like this:
```
system["Article"].ruby_class = MyApp::Models::Article
```
## What exactly is the purpose of ADT?
I think ADTs (and the whole "information contract" thing) sounds
really interesting, but I'm failing to see the value. Why not just do
it like this:
```
ColorTuple = {r: Byte, g: Byte, b: Byte}
ColorHex = String
Color = ColorTuple|ColorHex
Article = {
color: Color # both are supported
background_color: ColorTuple # because of legacy reasons, you can
only pass in a tuple here
}
```
Combine this with a Ruby-level API for dressing any Q type into a Ruby
class and it gives you greater flexibility than ADTs do today.
---
Cheers,
Magnus