Jsonnet Style Guide

306 views
Skip to first unread message

farer...@gmail.com

unread,
Aug 24, 2016, 4:12:34 PM8/24/16
to Jsonnet
Is there any style guide, even informal? I see this bug but it's mostly empty:

Also, the examples included in the git repo seem to have wide discrepancies in style, with a mix of camelCase, CamelCase and snake_case that I can't unravel.

 -#f

Dave Cunningham

unread,
Aug 24, 2016, 4:31:36 PM8/24/16
to farer...@gmail.com, Jsonnet
The reformatter enforces style but a lot of it is optional (and you can configure it using commandline options).  There is no enforcement of variable names, just whitespace, quoting style, comments, and stuff like that.

Often as a a Jsonnet programmer you're generating JSON according to a particular format, so you're forced to use their field names.  This can be jarring if they are not consistent in their style, or if you want to use a different style for your Jsonnet code (which contains lots of additional names that don't end up in the actual output).  So if you look at the micromanage stuff for example, a lot of that is generating JSON terraform configs which use a particular style.

I try to do the following:

classes (i.e. fields or locals containing mixins that exploit OO) are LikeThis
fields (of classes) are likeThis
local variables are otherwise like_this

It's really up to you though, I've seen a lot of variation in user code.

--
You received this message because you are subscribed to the Google Groups "Jsonnet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonnet+unsubscribe@googlegroups.com.
To post to this group, send email to jso...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsonnet/d6237d22-0ac9-4776-b8a4-3e421107afde%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

farer...@gmail.com

unread,
Aug 24, 2016, 4:46:02 PM8/24/16
to Jsonnet, farer...@gmail.com
On Wednesday, August 24, 2016 at 4:31:36 PM UTC-4, Dave Cunningham wrote:
The reformatter enforces style but a lot of it is optional (and you can configure it using commandline options).  There is no enforcement of variable names, just whitespace, quoting style, comments, and stuff like that.

Often as a a Jsonnet programmer you're generating JSON according to a particular format, so you're forced to use their field names.  This can be jarring if they are not consistent in their style, or if you want to use a different style for your Jsonnet code (which contains lots of additional names that don't end up in the actual output).  So if you look at the micromanage stuff for example, a lot of that is generating JSON terraform configs which use a particular style.

I try to do the following:

classes (i.e. fields or locals containing mixins that exploit OO) are LikeThis
fields (of classes) are likeThis
local variables are otherwise like_this

It's really up to you though, I've seen a lot of variation in user code.

I'd imagine that a style guide could require "quoted" strings as keys when fields don't follow the naming conventions, thereby clearly distinguishing data-driven names from jsonnet-driven names.

What about function docstrings? Surely, these a jsonnet-specific enough that you can't just let that driven by json.
It's probably best to adopt the rules of some existing language. But which?

-#f

Reply all
Reply to author
Forward
0 new messages