TysonMN / tysonmn.github.io

Blog of Tyson Williams about software engineering and functional programming
https://tysonwilliams.coding.blog/
MIT License
3 stars 7 forks source link

2020-10-13_syntactic_vs_semantic_grouping #20

Closed utterances-bot closed 3 years ago

utterances-bot commented 3 years ago

Syntactic vs semantic grouping

https://tysonwilliams.coding.blog/2020-10-13_syntactic_vs_semantic_grouping

dharmaturtle commented 3 years ago

Most "3 tier" architectures group syntactically. E.g. you have a UserRepository that manages persistence with respect to a User relational database table, a UserService that contains business logic like what a user can do, and a UserController that contains WebApi endpoints that pertain to a user.

This sucks. This is precisely syntactic grouping.

A better organizational structure would be to group by feature, as you describe. This is what DDD is all about. Instead, split up by behavior, e.g. ProfileRepository, ProfileService, and ProfileController. Don't put users' profiles into a UserRepository, despite their profile living in the User table.

nathans1309 commented 3 years ago

I am wondering if semantic grouping is more apparent for front-end development where the features are more obvious while syntactic might be more appropriate for the backend where the code is more likely to be shared across the application. For example, an EmailSender isn't necessarily grouped within a single feature.

MrMattSim commented 3 years ago

Syntax vs Semantics

I encounter these terms most often in the context of semiotics. So the terms you've chosen seem overloaded to me, and feel a bit jarring. But I guess in the semiotic domain, the groupings would generally be something like…

syntactic grouping: grouped by some observed property, "what", Firstness; semantic grouping: grouped by object(ive), "why", Secondness

To complicate matters more, what I mean by semantic group, here, is what I shall call a "particularized-why" as opposed to a "collective-why". A collective-why would be pragmatics, such as choosing items to fill a box merely because they collectively fill the space, any shared property or function is precisely coincidental. Pragmatics, considered this way, is the overlap (or application) of syntax and semantics; or to put it another way: the form IS the function. Linguistically, it would be onomatopoeia. This suggests the alternate terms of form and function, in place of syntax and semantics, but for your purposes I suppose function is overloaded. Other terms to consider are external vs internal properties, or observed vs inferred (or computed) properties.

After all that, however, I think there's a bigger problem: The distinction is task-dependant. Depending on the task, what is semantic may be syntactic or vice-versa. Also, depending on the task, the solution could be grouping or not, or vice-versa.

If I need to swap-out the theming and styling of an app, searching by .css doesn't help me swap-out the whole lot into each component folder. Additionally, a .xaml search doesn't magically identify which XAML contains theme data. Perhaps an alternate solution would be to have a naming convention with sufficient syntactic and semantic parts. Then the remaining question becomes: what is the essential purpose of a folder? Which I suggest is: movement and permissions. Neither of these have any obvious correlation to syntax or semantics. Any additional purpose would, most sensibly, be essential to — and therefor depend upon — a given task.

As for your analogous examples:

Shoes

Sorting by Left or Right is sorting by "how they are used" and therefor semantic, using your paradigm, but you identify it as a syntactic grouping.

In Peircean semiotics left-right sorting would be closest to Secondness; being indicative, or related to cause-effect, purpose, intention. Or alternatively, it could be considered as sorting by similarity to some external rule or pattern, and therefor Thirdness.

Matching by pairs however, would be determined by similarity - based on intrinsic properties of the shoes themselves - and therefor syntactic; or semiotically: Firstness, iconicity. This similarity-sort would only fail if all pairs are identical, as in the gloves example.

Gloves

We can make the task easier for users by reducing cognitive tasks to pre-attentive tasks. Presently the exhibit is doing this by spatial mapping; separating left-right into separate bins. This requires the tasks of both creating and maintaining the spatial sort (And probably also requires always placing the left-bin left-of the right-bin).

But we can also map left-right onto other pre-attentive properties such as color. (Although color-mapping should typically be used sparingly). By color-mapping, sorting only needs to be done once, rather maintained throughout the activity. Also, the labelling of L/R on each glove is the worse possible solution, marginally better or worse than doing nothing. If the gloves are so similar then they are probably reversible and adding letters is a needless distraction; if they are not so similar then the letters are just replacing one shape-check for a different shape-check.

This is what I would do: Assuming all the gloves are some neutral greyish color, they should dye all left-gloves some other color, like blue. Dying a bin of gloves is also way faster and easier than labelling each with L or R. Then make a Big Clear Sign over the pickup bin by stapling one of each glove, and cartoon hands reaching up into each. And since the gloves are always used in pairs, we can be confident the bin will have 50% of each glove at any time, so that users will never need to dig for either.

Notice how the dying is subverting the syntactic-similarity between left-right by breaking similarity of the most apparent property, color. And the sign restores the syntactic-similarity, but this time left-left, and right-right.

TysonMN commented 3 years ago

This suggests the alternate terms of form and function, in place of syntax and semantics, but for your purposes I suppose function is overloaded.

Ah, yes. I do like the terms form and function. The overload is indeed unfortunate.

Additionally, a .xaml search doesn't magically identify which XAML contains theme data. Perhaps an alternate solution would be to have a naming convention with sufficient syntactic and semantic parts.

Certainly. The file extension is just a simple example that applies in many cases. The rest of the file name should give more information about both the form and function. For example, in our project, we can group the XAML files in two form-based groups: (1) those ending with .style.xaml and (2) those not ending with .style.xaml.

Sorting by Left or Right is sorting by "how they are used" and therefor semantic, using your paradigm, but you identify it as a syntactic grouping. ... Matching by pairs however, would be determined by similarity - based on intrinsic properties of the shoes themselves - and therefor syntactic; or semiotically: Firstness, iconicity.

I was thinking of it as a syntactic grouping because the curvature of left shoes and right shoes is an intrinsic property of shoes, but I see what you mean.

Notice how the dying is subverting the syntactic-similarity between left-right by breaking similarity of the most apparent property, color. And the sign restores the syntactic-similarity, but this time left-left, and right-right.

I love it! This is how to nerd snipe a UX engineer ;) I will absolutely remember this next time I attend the Minnesota State Fair, and I will mention this idea to them.


@MrMattSim also explained Peircean semiotics to me verbally. Here is my (very limited) understanding.

  1. Firstness is mostly like my syntactic or form properties. It is about something intrinsic to the items being grouped.
  2. Secondness is mostly like my semantic or function properties. It requires additional understanding that is generally obtainable.
  3. Thirdness is cannot be exactly computed in general because it is too particular or specific.

Let's revisit some of my examples in light of this theory.

Shoes

I can see how the left vs right and pairs are both examples of firstness. Grouping shoes by type (such as running, sandals, and boots) would be secondness. Grouping shoes by owner is thirdness. Of course I can perfectly group the shoes in my house into mine vs not mine, but not everyone could. And as I pointed out in the post, doing this for my children is even harder. There is essentially no amount of general study you could do to become prefect at organizing by owner. You essentially need to ask the owner for the answer...much like an oracle in theoretical computer science.

Netflix

Whether a movie includes dialog in English is firstness. The genre is secondness. Whether I like a movie or not is thirdness. It is impossible for Netflix to perfectly compute that last grouping, but it seems to be doing a great job approximating it (and not just for me).