News for hackers. Stuff that matters.
Re:Yagni Exceptions (2021) by matsemann on Monday October 17, 2022 @04:17AM (#33230963)
* Having all user-facing strings in a common place.

It doesn't take much effort, but makes it so much easier in the future when you suddenly either need internationalization/translation (both tech side making the switch, but also gathering all the strings to send to some translator), or it's requested that these be managed by a cms of some sort instead of hardcoded all over the place.

Re:Yagni Exceptions (2021) by robertlagrant on Monday October 17, 2022 @04:55AM (#33231193)
True, although at least on mobile I think this is a button press in the IDE. Maybe Javascript/non-mobile native apps have it harder.
Re:Yagni Exceptions (2021) by taink on Monday October 17, 2022 @05:50AM (#33231494)
Yes, I can think of Android Studio which pushes you into using Android's string resources[0], which have out-of-the-box support for i18n and are essentially big XML files.

[0]: https://developer.android.com/guide/topics/resources/string-...

Re:Yagni Exceptions (2021) by hinkley on Monday October 17, 2022 @01:57PM (#33237363)
I haven't worked in Android, but a quick perusal at least passes my giggle test, which frankly too many languages do not.

This is essentially a refinement of the i18n support that has been in Java for ages. I probably would not have stuck with Java as long as I did if their localization support wasn't as good as it was (not to say it's perfect, because it's a bit clunky). Google has made a few of the examples into a more concrete requirement, which is nice.

Re:Yagni Exceptions (2021) by iLoveOncall on Monday October 17, 2022 @05:49AM (#33231490)
I haven't worked with a lot of i18n systems, but on the contrary I have found them to be a huge amount of work.

I have used the Angular one and the Laravel one, and both are a chore to use, because they interrupt your flow. If I'm writing the view of my component, I don't want to have to switch to another file, think of a key that identifies that text well enough and then translate the text, thinking of potential plurals and others. I just want to write my damn text.

I'd rather spend days doing the mind-numbing work when needed rather than slow down my development process and remove all enjoyment from it ad vitam aeternam because of i18n-ing on the fly.

Re:Yagni Exceptions (2021) by healsjnr1 on Monday October 17, 2022 @06:40AM (#33231768)
These patterns and practicee generally aren't intend for _you_ as the developer of the app right now.

They are intended for the poor shmuck 18 months later who has to work with a tangled mess of copy text stored in JS, server side yaml files and a CMS.

I've been that person at least 3-4 time now. I've waded through changes where having static strings got the UI would have simplified things immensely, and _none_ of these have had anything to do with internationalisation.

They have been far more prosiac (Legal request, product changes, rebranding, just general things like "where did this text under interest rate calculator come") but have still taken significantly longer than they should have.

When you are writing these apps it can feel like it's not that hard to go back later and pull out strings, just some grunt work.

But once you munge your code through three refactors and a framework change it becomes so much harder.

Re:Yagni Exceptions (2021) by samuelstros on Monday October 17, 2022 @06:36AM (#33231740)
I might have something for you that reduces context switching. I am working on an IDE extension that shows the content of a localized message inline. A screenshot can be found here https://github.com/inlang/inlang#vs-code-extension.
Re:Yagni Exceptions (2021) by matsemann on Monday October 17, 2022 @06:19AM (#33231640)
You don't need to bake in a complete i18n solution, though. Just create a simple map of keys->strings, and then a function ala

    getStringForKey(key, language) {
        return map[key]
and then whenever you actually need it, just expand on it. But at least you then have all strings in one place, and a common way of accessing them. (And easy lookup of all places using these strings)
Re:Yagni Exceptions (2021) by sonthonax on Monday October 17, 2022 @07:20AM (#33232054)
Agreed. I don’t really know what problem these i18n tools solve that this doesn’t.
Re:Yagni Exceptions (2021) by matsemann on Monday October 17, 2022 @07:24AM (#33232092)
But if you end up in a situation where i18n tools are needed, this function can be the single entry point anyways, abstracting most of it away.
Re:Yagni Exceptions (2021) by iLoveOncall on Monday October 17, 2022 @07:41AM (#33232228)
Your function doesn't solve any of the issues I mentioned, you still need to switch to another file, still need to think of a sufficiently explicit key, still need to handle plurals and masculine / feminine variations, etc.
Re:Yagni Exceptions (2021) by matsemann on Monday October 17, 2022 @08:06AM (#33232411)
YAGNI ;) You can skip all those things the first time. You don't need to have a separate file or anything. Just have a stupid function returning its input or whatever. The important part is having an entry-point, and an easy way to find all relevant uses in the future. You could then later, when i18n is needed, write a script finding those usages and automatically extract them. That's what I've done once before. And it was a thousand times easier than the time before where we had to hunt through all of frontend, backend, cms etc. to find stuff.
Re:Yagni Exceptions (2021) by iLoveOncall on Monday October 17, 2022 @08:48AM (#33232743)
> The important part is having an entry-point, and an easy way to find all relevant uses in the future.

You already have it, it's everything that's in between {{ }} and > </.

Re:Yagni Exceptions (2021) by matsemann on Monday October 17, 2022 @09:47AM (#33233414)
Do you want to translate numbers between ><? What about alt-texts not in those tags? Things passed as props multiple layers? What about strings coming from backend? Do you read some things from the environment?
Re:Yagni Exceptions (2021) by BlargMcLarg on Monday October 17, 2022 @05:58AM (#33231521)
On the other side we have the individuals inheriting such codebases and being told to add multilingualism when a bunch of other soft dependencies and assumptions exist which make this entire thing a disaster to implement.

It is fairly small and trivial to add so please, if you foresee an event where systems have to support multiple languages and odds are you won't work on it yourself, prepare the damn codebase for it.

Re:Yagni Exceptions (2021) by Izkata on Monday October 17, 2022 @09:43AM (#33233362)
> I have used the Angular one and the Laravel one, and both are a chore to use, because they interrupt your flow. If I'm writing the view of my component, I don't want to have to switch to another file, think of a key that identifies that text well enough and then translate the text, thinking of potential plurals and others. I just want to write my damn text.

In django (python), the key is just the English text (with optional extra context), and if it doesn't find a translation for the target language it dumps that text back out. You don't need to go anywhere else until actually doing the translating.

Re:Yagni Exceptions (2021) by iLoveOncall on Monday October 17, 2022 @01:06PM (#33236539)
It does the same in one of the two that I mentioned (Angular I believe), but you still need to mark plurals and other stuff like that.

Here is an example about a basic case that you will encounter multiple times per page:

  <span i18n="Pretty update timestamp|Update timestamp prettyfied accompanied by user gender@@prettyUpdateTimestamp">Updated: {minutes, plural,
    =0 {just now}
    =1 {one minute ago}
    other {{{minutes}} minutes ago by {gender, select, male {male} female {female} other {other}}}}
  </span>
Re:Yagni Exceptions (2021) by SebastianKra on Monday October 17, 2022 @07:03PM (#33240659)
Does this work well?

What happens when you need to make a change in the english version? Do you just search/replace through all the translations?

Does django do anything to make this easier, or does it work with any i18n library?

Re:Yagni Exceptions (2021) by Izkata on Tuesday October 18, 2022 @12:07AM (#33242847)
There's also "translate to English", so you can instead treat it directly as a key and use that, or treat the English text as a key and change/add to the file if it's just something like a typo.

Don't recall about the second, we only had translations on one site and it's been a few years.

Re:Yagni Exceptions (2021) by bazoom42 on Monday October 17, 2022 @06:16AM (#33231628)
Sure, but what if you never need to internationalize? Introducing a level of indirection have a cost. This is exactly why YAGNI applies.

Refactor the code to support a requirement when the need arises.

Re:Yagni Exceptions (2021) by valenterry on Monday October 17, 2022 @06:46AM (#33231813)
Exactly.

Better imo: Don't use strings but a proper datastructure/wrapper. Later, if you want to add i18n, then change `Wrapper("Hello, welcome to the future")` into `Wrapper("Hello, welcome to the future", "welcome-user")` and just look for all wrappers to find all places.

Benefits: it's easy to find the code with a simple ctrl+f from the English version of the site and you don't have any disadvantage except for having the English translation (or whatever primary language you choose) inside the code and the other translations in mapping somewhere else.

Re:Yagni Exceptions (2021) by goto11 on Monday October 17, 2022 @06:54AM (#33231875)
This is still not YAGNI enough for me. Why introduce a wrapper you don't need?

The thinking behind anti-YAGNI "future proofing" seem to be that it is cheaper to change something now than in the future. But I reject this premise. Inserting `Wrapper($string)` is exactly as much work now as in the future, but it will add additional overhead to all development going forward.

Perhaps the wrapper is even less work to introduce in the future, since you can add it with a simple search-replace, instead of inserting it manually every time you type a string.

Re:Yagni Exceptions (2021) by valenterry on Monday October 17, 2022 @07:33AM (#33232151)
I don't think so. That's just a semantic description of what you are doing. Call it `UserMessage("....")` or whatever. If you go without that and have simply plaintext for any kind of thing, you might at some point mix up passwords with user messages and stuff like that. Has nothing to do with future-proofing.

You need user-messages? Then create user-messages and not strings. You don't need translations? Then don't create them.

Or in other words: make things a simple as you can but not simpler than they inherential are.

> Perhaps the wrapper is even less work to introduce in the future, since you can add it with a simple search-replace, instead of inserting it manually every time you type a string.

No you cannot, unless literally all strings in your program must be translated.

Re:Yagni Exceptions (2021) by goto11 on Monday October 17, 2022 @07:58AM (#33232365)
Lets say I write a HTML page.

   <h1>Hello world</h1>
Is less work and complexity than:

   <h1>{{ UserMessage("Hello world") }}</h1>
Introducing this abstraction before it is needed is a waste of resources and opportunity cost. Lets say you have the first solution, and someone decides "world" should be a link. Easy, you insert an <a>-tag. In the second example such a change would be much more complicated. You have suddenly made your work much more difficult for no benefit at all.

Sure, if you discover at some point in the future that you actually need translations, then you have to work through all text and decide which strings need to be translatable. Yes, that is work, but you have done that anyway! There is no extra work. And every text which have been deleted between the abstraction was introduced and the translation became necessary, would have had an extra cost which is wasted anyway.

Re:Yagni Exceptions (2021) by valenterry on Monday October 17, 2022 @08:24AM (#33232560)
Oh, if you write HTML then you are already using semantic wrappers. I.e. you already used <h1> which clearly indicates your intend.
Re:Yagni Exceptions (2021) by sonthonax on Monday October 17, 2022 @07:17AM (#33232037)
Agreed, lots of things never need to be internationalised. Pretty much everything in institutional finance will never need it.
Re:Yagni Exceptions (2021) by hinkley on Monday October 17, 2022 @01:44PM (#33237173)
Have you done that refactor? There is no timeline you can do once people are just injecting static text everywhere in the app.

That project is 'done' when the interval between bug reports increases past some number where people decide it's done. But if you tell your boss "next month" then you're going to be proven wrong.

Re:Yagni Exceptions (2021) by bazoom42 on Tuesday October 18, 2022 @07:35AM (#33245759)
Are you asking if I have ever added internationalization/translation to an app which initially didnt have it? Yes I have done that.
Re:Yagni Exceptions (2021) by malandrew on Monday October 17, 2022 @08:07AM (#33232417)
I would go further with your idea. You should have all I/O separated and in on place. UI is just a special case of I/O for apps.

In services you also want to keep all RPC handlers in on place (or any interface with which others interact with your binary). You also want to keep any interfaces with which you make IPC calls each separate and in one place as well. I use IPC (inter process communication) as this includes service clients, database clients, disk access, peripheral access, etc as well.

Re:Yagni Exceptions (2021) by jaza on Monday October 17, 2022 @08:27AM (#33232584)
I once worked on a large app that had always tried to support translation, but that had never actually been used by clients (after more than a decade running in production) in a language other than English. Well, what do you know, after all those years, finally a big client signed on, and this client needed the whole UI not in English.

Trouble was, in practice there were gaps in the translation support all over the place, and so several rounds of patching those gaps and performing manual testing were needed, which took a lot of time and manpower. So, was it worth half-maintaining the translation support for so many years? I guess it would have been even more work had it needed to be added from scratch; but it was still a lot of work cleaning it up.

Ironically, the client in question then cancelled on us, shortly before going live, and after we'd finished all that work. Although another non-English client did go live with us the year after that, so it wasn't wasted effort in the end.

Re:Yagni Exceptions (2021) by creeble on Monday October 17, 2022 @11:51AM (#33235286)
Not too ironic I think, more common than not.

I wish I had a box of nickels for every feature that cost $100k+ to implement that ended up being a dead end (i.e., sales benefit never materialized) or, even more commonly, the benefit materialized and was less than $100k and resulted in a feature that required continued maintenance and ongoing support cost forever.

Re:Yagni Exceptions (2021) by bcrosby95 on Monday October 17, 2022 @01:00PM (#33236429)
I think this is one of the biggest problems with violating YAGNI. They're effectively dead code paths that are never truly being executed, and developers might assume they aren't full of bugs. But they oftentimes are.
Re:Yagni Exceptions (2021) by hinkley on Monday October 17, 2022 @01:51PM (#33237290)
There's hard coding strings, and then there's hard-coding sentence fragments.

If you hard code strings, you can't translate at all. If you hard-code sentence structure ("There are " + n + " copies of this book in stock") then you're going to sound like Yoda in a number of languages.

Adjectives are a particularly bad sticking point. Is it a large red book (English), a large book that is red (French), or a book that is large and red? But Verb-Object-Noun order also vary just within first world nations, so even the lame classist/racist/nationalistic excuse of "We don't need their money anyway" doesn't really fly. One of your competitors will be very happy to take Japan's money.