question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Schema] Please rethink model block syntax

See original GitHub issue

model User {
  id    Int    @id
  email String @unique
}

model User {
  id       Int    @id
  email    String @unique
  username String @unique
}

My biggest gripe with the current syntax is how spacing can change every single field in the model. See adding username changes spacing for other fields. This hurts blame for absolutely no reason. I don’t get why:

No pull requests with different spacing schemes.

was such a big deal.

Like gofmt and unlike prettier, there are no options for configurability here. There is exactly one way to format a prisma file.

I am not sure I buy this completely given I don’t know the drawbacks for Schema syntax in v1.34 (latest stable) and what this particular new syntax really adds.

(Early enter. Writing the post)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:31
  • Comments:26 (12 by maintainers)

github_iconTop GitHub Comments

32reactions
matthewmuellercommented, Jul 15, 2019

@sapkra thanks for your thoughts. I agree that for this small datamodel, no formatting is just as readable. Plus it’s simpler.

While evaluating our decision, we’ve been looking at large datamodels that you’d find in a real app:

1 Column 3 Column

I think the column alignment improves readability quite a bit.

19reactions
auderercommented, Aug 2, 2019

I notice a pattern here that I’ve noticed in many other areas of software development: separation of concerns.

The formatted version is sliced vertically.

The non-formatted version is sliced horizontally.

Which one is more useful when actually working in a large dataset? I would argue that horizontal organization is far more important. When glancing at a screenshot of code, columns look far more aesthetically pleasing; but that’s not how we actually read our data when editing, adding, or debugging.

We don’t vertically scan columns of types or tags. We scan field names, then look ahead horizontally to see which types and tags apply to that field. This is markedly more difficult in a column format, especially when there’s a large gap between the longest and shortest field names.

How does this relate to separation of concerns? It reminds me of organizing HTML/CSS/JS by file-type instead of by component. Each line in the model is like a component - it has a name, type, and decorators. These three values should be closely coupled together and independently organized; not spread out based on the position of values in other rows.

I definitely see how column formatting appears more readable, but in practice it is not. If I have to drag my cursor across the line or hold a ruler up to my screen just to see which type/decorators apply to a field, it’s a bad design. Not to mention the terrible diffs and merge conflicts that this causes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fucking Block Syntax
How Do I Declare A Block in Objective-C? As a local variable: returnType (^blockName)(parameterTypes) = ^returnType(parameters) {...}; As a property:.
Read more >
MSchema – Lars Corneliussen
So far I like the schema part of M, also called MSchema. It has a very concise (compared to XSD) c-style syntax and...
Read more >
SchemaAgent Archives - Altova Blog
XMLSpy® 2010 provides a graphical schema design interface which simplifies the development of XML Schemas, allowing XML code to be generated in real-time...
Read more >
ST. PETERSBURG COLLEGE COLLEGE OF EDUCATION The ...
This course is designed to increase understanding of early literacy development and the conditions which promote total literacy for children birth to second ......
Read more >
RETHINKING THE EMOTIONAL BRAIN - PMC - NCBI
Why Do We Need to Rethink the Relation of Emotion to Survival? ... In these models various emotions defined in terms of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found