Open VladimirAlexiev opened 1 year ago
fwiw, I prefer the latter.
I'd opt to avoid discussions on personal formatting preferences unless the chosen formatting is misleading (see my comment on PR https://github.com/w3c/N3/pull/147) or, of course, the discussion is about best practices (which we haven't done).
N3 is a free-form language (whitespace doesn't matter). However, by following some formatting rules in your N3 files, you can make them easier to read by humans, and ensure consistency.
(By "elements" below we mean RDF terms or triple patterns).
# OK
:LoisLane :believes { :Superman :can :fly } .
# NOK
:LoisLane :believes {:Superman :can :fly}.
# OK
{ :weather a :Raining }
=>
{ :weather a :Cloudy } .
# NOK
{ :weather a :Raining
} => {
:weather a :Cloudy
} .
# OK
{
:race :finalists ?finalists .
?finalists list:iterate ( ?i ?finalist ) .
( ?i ". " ?finalist "<br />" ) string:concatenation ?entry
} => {
:race :entries ?entry
}
# NOK
{ :race :finalists ?finalists .
?finalists list:iterate ( ?i ?finalist ) .
( ?i ". " ?finalist "<br />" ) string:concatenation ?entry }
=> { :race :entries ?entry }
# OK
{
?hero a :SuperHero .
(
?enemy
{ ?enemy :enemyOf ?hero ; :defeated true }
?enemies
) log:collectAllIn _:t .
}
# NOK
{
?hero a :SuperHero .
(?enemy
{
?enemy :enemyOf ?hero ;
:defeated true .
}
?enemies) log:collectAllIn _:t .
}
=>
(log:implies
) relation
# OK
{ ?slinger a :WebSlinger } => { ?slinger :locomotion :flying } .
{ ?heli a :Helicopter } => { ?heli :locomotion :flying } .
# NOK
{ ?slinger a :WebSlinger } => { ?slinger :locomotion :flying } .
{ ?heli a :Helicopter } => { ?heli :locomotion :flying } .
} => {
, or keep them on separate lines:
# OK
{
<http://example.com> log:content ?content .
(?content "<title>(.*?)</title>") string:scrape ?title .
} => {
<http://example.com> :title ?title
} .
# OK
{
<http://example.com> log:content ?content .
(?content "<title>(.*?)</title>") string:scrape ?title .
}
=>
{<http://example.com> :title ?title} .
# ALLOWED
{ ?slinger a :WebSlinger } => { ?slinger :locomotion :flying . }
# PREFERRED
{ ?slinger a :WebSlinger } => { ?slinger :locomotion :flying }
# OK
:mary-jane
:knowsIdentityOf :spiderman ;
:keepsSecrets true ;
.
@william-vw , @TallTed please comment on the principles above.
@VladimirAlexiev — Looks good to me! It would be best to make plain that the whitespace formatting described above is meant for human-focused educational examples, optimally with a single click to see a "machine optimized" version without the extra whitespace as might be found in actual deployment.
https://w3c.github.io/N3/spec/#example-23
Is this really a good way to format a rule?
Maybe change to this:
Or this
Sorry for the nitpicking, but many people (me included) learn by copy-paste :-)