thepurpleblob Posted November 21, 2018 Share Posted November 21, 2018 There seems to be a function, somewhat bizarrely, named double underscore. Which confused the hell out of me for quite a few minutes. After a bit of digging, it seems to be to do with language translation. Why would anybody call a function __? Probably just venting... Link to comment Share on other sites More sharing options...
3fingers Posted November 21, 2018 Share Posted November 21, 2018 Here the answer to your question :) 1 Link to comment Share on other sites More sharing options...
Soma Posted November 21, 2018 Share Posted November 21, 2018 I don't know what's so confusing about it. I think it's rather this doc: https://processwire.com/api/multi-language-support/code-i18n/ 1 Link to comment Share on other sites More sharing options...
Robin S Posted November 21, 2018 Share Posted November 21, 2018 9 hours ago, thepurpleblob said: Why would anybody call a function __? [joke]You're gonna hate underscore.js then[/joke] ? 2 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted November 22, 2018 Share Posted November 22, 2018 21 hours ago, Soma said: I don't know what's so confusing about it. It could just as well be named gettext(), translate() or something long those lines and be way more descriptive and without the need to lookup docs. Link to comment Share on other sites More sharing options...
thepurpleblob Posted November 23, 2018 Author Share Posted November 23, 2018 Ok... get the idea. Thanks. I'm going to add this to the list of things that I would give one of my devs a row about, though ? Along with jQuery's '$', most uses of try..catch (rather than writing proper error handling) and anything that results in 'unknown error'. Always use descriptive function names. I don't mind typing a few extra letters. Link to comment Share on other sites More sharing options...
szabesz Posted November 23, 2018 Share Posted November 23, 2018 It is quite common to use one or two characters for "translate functions", since they are typed and used a lot. Some examples: https://codex.wordpress.org/I18n_for_WordPress_Developers https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/t/7.x https://docs.joomla.org/Making_templates_translatable Underscore appears to be a popular one. 5 Link to comment Share on other sites More sharing options...
thepurpleblob Posted November 24, 2018 Author Share Posted November 24, 2018 11 hours ago, szabesz said: It is quite common to use one or two characters for "translate functions", since they are typed and used a lot. Some examples: https://codex.wordpress.org/I18n_for_WordPress_Developers https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/t/7.x https://docs.joomla.org/Making_templates_translatable Underscore appears to be a popular one. Yeh - so I see. Now I've dug a bit more. I'd not encountered it before. I'm still horrified but as I'm not going to write my own CMS I'll just shut up now ? 1 Link to comment Share on other sites More sharing options...
teppo Posted December 8, 2018 Share Posted December 8, 2018 Old discussion, but yeah – the plus sides of this kind of naming are that 1) it's a common practice across different systems (which makes it easy for new devs to grasp), and 2) that it's a very commonly typed function – not to mention one that you often see in front-end (or "view") part of a site or an app, and thus it's good to keep it nice and short . Expanding on the second point a bit, in the view side it often makes sense to have short function names, even if they're not particularly descriptive. Think of PHP's short echo tags (<?= ... ?>) or various tags implemented by templating languages: the point is to create minimal clutter, thus keeping view files clean and easy to follow ? --- Note: this thread is not related to module development per se, so I'm moving it to the Getting Started area of the forum. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now