home

datafuck

Ever heard about Brainf*ck language?

It’s an esoteric language that has 8 operators that programmer can use to create programs. This, for example, is “Hello World” example:

>++++++++[<+++++++++>-]<.>++++[<+++++++>-]<+.+++++++..+++.>>++++++[<+++++++>-]<++.------------.>++++++[<+++++++++>-]<+.<.+++.------.--------.>>>++++[<++++++++>-]<+.

In case Brainf*ck name is too offensive, there is also Ook! Ook! language that uses pairs of Ook., Ook? and Ook! as operators. An example operators in Ook! Ook! is Ook! Ook. or another is Ook? Ook?.

I guess you can already see that I have some experience with esoteric languages.

Today I was meditating on terse data representations and how complex ideas can be easier written down, with less operators. I was thinking about terse representations of data and that’s where Dataf*ck idea came to me.

Design main points:

  • Format should be terse when it comes to character count
  • It’s OK to use things like stacks or unorthodox single char operators
  • Format should be readable by people

From that design clarified:

  • + is used as depth designator
  • , is item prefix
  • = is assignment
  • t/f are true and false equivalent
  • # is a comment character
  • ? is null
  • "..." is a string (strings that are completely alphanumeric can be used without double quotes)

Let’s move to samples:

Simple object:

+john
++name="John"
++age=30

# Compact: +john++name="John"++age=30
# JSON:    {"john":{"age":30,"name":"John"}}

List of objects

+people,++name="John"
        ++age=30
       
       ,++name="Ann"
       ,++age=29
       
# Compact: +people,++name=John++age=30,++name=Ann,++age=29
# JSON:    {"people":[{"age":30,"name":"John"},{"name":"Ann"},{"age":29}]}

Root-level list

,
1
,
2
,
3

# Compact: ,1,2,3
# JSON:    [1,2,3]

And finally compacting showcase:

$ curl https://jsonplaceholder.typicode.com/users | datafuck from-json --compact

,++address+++city=Gwenborough+++geo++++lat="-37.3159"++++lng="81.1496"+++street="Kulas Light"+++suite="Apt. 556"+++zipcode=92998-3874++company+++bs="harness real-time e-markets"+++catchPhrase="Multi-layered client-server neural-net"+++name=Romaguera-Crona++email=Sincere@april.biz++id=1++name="Leanne Graham"++phone="1-770-736-8031 x56442"++username=Bret++website=hildegard.org,++address+++city=Wisokyburgh+++geo++++lat="-43.9509"++++lng="-34.4618"+++street="Victor Plains"+++suite="Suite 879"+++zipcode=90566-7771++company+++bs="synergize scalable supply-chains"+++catchPhrase="Proactive didactic contingency"+++name=Deckow-Crist++email=Shanna@melissa.tv++id=2++name="Ervin Howell"++phone="010-692-6593......

Is it worth using? Probably not. Pretty printed form is readable and might save maybe 5% char count on braces and brackets. With ~1h of a total design + implementation I’d say it is/was a fun microproject.

You can find code at https://github.com/exlee/datafuck

Przemysław Alexander Kamiński
vel xlii vel exlee

cb | gl | gh | li | rss

Powered by hugo and hugo-theme-nostyleplease.