Sorry, we don't support your browser.  Install a modern browser
This post is closed.

New shortcut `->ts()` method for `->toStructure()`#143

->ts() shortcut for ->toStructure() like ->kt() which is the shortcut to ->kirbytext() would be great.

4 years ago

I’m not sure to be honest. The more such shortcuts we have, the harder it becomes to keep the overview. We would also need ->tb() for ->toBlocks() and ->td for ->toDate() etc. The list of methods will be really long.

3 years ago

The purpose of the shortcut is because it is too long. Longest field method after kirbytextinline() that has kti()
I don’t think it’s necessary for toDate() :)

3 years ago

Of course, ts() may be confused with toString().

3 years ago

The reason for introducing a shortcut makes sense, but once there are too many shortcuts, it’s no longer easy to remember which methods have shortcuts and which don’t. So you are trying a shortcut that makes sense, but doesn’t exist (like in the toDate() example, which was of course an extreme example).

3 years ago

To be honest, this idea came to my mind because I used this method a lot. I use ->kt() for more practical and faster writing and I thought why we don’t have a method called ->ts(). If it will make things easier, I think it is okay to have shortcuts for long methods.

Much shorter methods have shortcuts: ->xml() > ->x() :))

https://github.com/getkirby/kirby/blob/3.5.0/src/Cms/AppPlugins.php#L649-L663

3 years ago

Of the existing ones, I basically only use kt() and kti(), because lazy. But from a point of view of making code easily understandable, the long versions are usually a better choice.

3 years ago

Downvoting: shortcuts like this sound good when you have few features (Kirby 1), but when your API surface grows (Kirby 2 then Kirby 3) it becomes very messy, and hard to learn for people who are not die-hard power users of the software.

Explicit > Implicit.
One way to do something > 2 ways because there’s some random synonym that was added years ago.

I suspect that a lot of the existing short aliases in Kirby’s API are just kept around for backwards compatibility. I would advocate for stopping documenting them (maybe a bit radical), or de-emphasizing them in docs (more sensible).

a year ago

Closing this as we won’t add more/most shorthand method names as they are pretty hard to understand.We might even slowly deprecate some of the really old ones. Since Kirby allows to add custom field methods, that’s an option for porjects where this is really needed.

a year ago
1
Changed the status to
Archived
a year ago