Dojo functions with underscore in front - function

Why do some DOJO functions have underscore in front of the function name. Are this functions any different to the other functions?

Anything beginning with an underscore is not part of the public API.
If you know java or C#, think private, protected internal/package private
The Dojo team does a pretty good job maintaining backward compatibility on the public API, but there is no such guarantee with the non-public API. So if you write a custom widget which overrides a function that begins with an underscore, it could break on an upgrade.
http://dojotoolkit.org/reference-guide/1.9/developer/styleguide.html

Sometimes, these are local variables / functions.

In addition, here is a post from SitePen about the topic. Hope this helps!
http://www.sitepen.com/blog/2013/11/05/dojofaq-underscore-module-name/

Related

What does the "_" function in Vala do?

I've seen that some projects used _ function that takes string as an argument, like _("Hello World"). But I couldn't find any manuals or articles about what is it and how to use it.
I guess this has something to do with i18n and l10n (it was mentioned in some article I found on the internet), but can you explain to me how it works and how to use it?
That is the GNU gettext localization function. You can provide language specific alternate strings for the one specified in the function call.
There is the xgettext tool, which generates a .pot file (abbreviation for portable object template) from your application code, then translators can make .po localization files for it. Then, you can bundle these with your application, and deliver a more widely usable piece of software.
I18n. See gettext example here: https://ewgeny.wordpress.com/2012/05/10/supporting-multiple-languages-in-your-application-a-simple-gettext-step-by-step-example/
Also found some info about what exactly this function do, it seems to be the macro for Glib.dgettext() function in Vala, this is from valadoc.org:
dgettext
public unowned string dgettext (string? domain, string msgid)
This function is a wrapper of dgettext which does not translate the message if the default domain as set with textdomain has no translations for the current locale.
...
Applications should normally not use this function directly, but use the _ macro for translations.

Calling functions between components in Coldfusion

Say I have a project, I have several CFC's in that project. For the sake of the example, I have a debugging function general.cfc and I want to use that function in mandrill.cfc without having to copy and paste the code into the latter cfc. I've googled this until I can google no more and I know I need to post it here.
Anyone care to take me to school?
This is how I would do it
<cfset var objGeneral = createObject("component","general")>
Then if you have a function in general.cfc called getName() you can call it by saying objGeneral.getName()
You should look at the notion of dependency injection, and you should specifically look at how ColdSpring implements it in the context of ColdFusion (or DI/1).
Basically you have an init() argument in Mandrill which would take a General object, and then you set the General object into the variables scope of the Mandrill object, using its methods via variables.general.
That said, this works best on singleton objects. If you need to do this sort of thing on a transient object, I'd just instantiate the General object as needed within your Mandrill code (ie: now Matt Busche is suggesting).
My solution was to have mandrill.cfc extend the general.cfc component:
<cfcomponent extends="general" name="mandrill" ...>
See also CreateObject

When to encode as HTML in Grails

I often see Grails sample code where the programmer has called a method called encodeAsHTML(). I figure I should probably use this in my Grails applications (for security reasons, I assume?), but I was wondering when I should use this method. What objects/properties/etc. are candidates for the encodeAsHTML() method?
Thank you!
Use encodeAsHTML() (or encodeAsJavaScript, etc) for everything that you've got from user. For every string that could be modified by user (got from input form, from request parameter, from external API call, etc)
See also:
https://en.wikipedia.org/wiki/Cross-site_scripting
https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet
I am not sure when this was introduced to Grails, but if in Config.groovy you set grails.views.default.codec="html" then encodeAsHTML() is called whenever you use ${} in GSPs.
Source: http://alwaysthecritic.typepad.com/atc/2010/06/grails-gsp-html-escaping-confusion.html

Question on class implementation with interface

I have created the following classes for sharing images. They implement an interface, but I need a way of switching between them with user interaction. I've done it the following way:
As you can see, service 1 and service 2 implement iSharingServices, and inherit from PolimorphSharing.
PolimorphSharing is simply and an abstract class that implements the methods I want public from Service 1 and Service 2. Those methods will then be overridden on the Service 1 and Service 2.
Because I need a way to switch the service in runtime, I've created a gateway class that inherits from PolimorphSharing. I can then call it the following way:
private var sharingService:PolimorphSharing = new SharingServicesGW('svc1').createService();
This all works flawlessly, and I can now switch between services with no problem whatsoever. However, I feel there's something wrong about it, so I would like to ask you guys for some advice on how to better implement this.
Any opinions here would be appreciated. I feel like I'm kind of implementing the factory pattern here the hard way.
UPDATE:
Just adding some more insight to this. Basically the idea here is for my client to be able to upload images with various different public sharing services such as imageshack, imgur etc. I want my client to be able to select the service in which the image is to be published to (hence the "switching between them with user interaction" bit of the question.
The method that does the uploading bit, is requestShareImage(), processResults() simply turns whatever gets returned to a unique format, so my client can read off it always the same way. getObject() is my accessor, and onIOError will handle exceptions with any of the public API's
Thanks all in advance,
SharingServicesGW IS a factory. However, there's no need for it to - and it shouldn't - inherit from PolimorphSharing. Also you're doing it a bit skewed. The client should be using objects of the interface type, not the abstract type.
Your interface should be defining the public API, not your abstract base class. In fact in AS3 interfaces can only define public members, while pseudo abstract classes can enforce implementation of protected members.
-- EDIT --
here's a UML diagram of how I would do it

ActionScript: Multiple public functions in one .as file?

As I've been working with AS I've developed a collection of utility functions. For example:
$ cat utils/curried.as
package utils {
public function curried(f:Function, ...boundArgs):Function {
function curriedHelper(...dynamicArgs):* {
return f.apply(null, boundArgs.concat(dynamicArgs));
}
return curriedHelper;
}
}
And I've found that, some times, I want to keep more than one public function in each file... But ActionScript restricts me to one public definition per file, if that file defines its self as being part of a package.
So, without creating a class with static methods, how could I get more than one public function in a single .as file?
simply put, you can't ... for a package level function declaration, you need one file per declared function ...
little side note: personally, i'd go Josh's way and stuff them into a class ... i think allowing function level declarations at all was simply to have a bit more backward compatibility to AS2 ... it's ok, for prototyping or things that'll never leave your hands ... but you imagine relying on 3-4 libraries, each exposing their functionality through package level functions? firstly, it completely spams your autocompletion (if your IDE offers one), and secondly, you always need to look at the imports to see which function comes from where ... the prefix you mentioned is actually of great advantage ... but ok, that's my opinion ...
greetz
back2dos