What should I name variables for buttons which has specific roles - naming-conventions

In general, we should name functions in order to follow starting with verbs, and name variables in order to follow starting with nouns. But if the target object has a specific role such as a button to create something and I want to define variables related to it, I've named it like "createButtonStyles". Especially, on programming languages which have functions as first-class objects such as JavaScript, it's hard to guess a role when we read their names. For example, when we read createButtonStyles, we have to guess whether the variable has styles of a button or the variable is to create styles button.
const createButtonStyles = { color: "red" }; // Styles for a create button
function createButtonStyles { ... }; // A function to create styles of create button
What should I name them?

Either you can name your variable stylesForCreateBtns or if you have mutltiple button-style variables name them with some sort of prefix like buttonStyles~, so it will start with noun: butonStylesCreateBtn, buttonStylesDeleteBtn, buttonStylesNextBtn. Plus it will in an autocomplete tool like IntelliSense sort them next to each other.

Related

GWT Dynamic String Internationalization showcase

have anyone tried to switch from Static String Internationalization to dynamic one? I want to reduce number of permutations to one per browser but cannot find any tutorial how to implement Dynamic String Internationalization in Java. Official docs covers tutorial only for static implementation. Seeing proper example of implementation of this approach would be really helpful.
I want to reduce number of permutations to one per browser by implementing Dynamic String Internationalization in Java.
The documentation you are referring to at https://www.gwtproject.org/doc/latest/DevGuideI18n.html#DevGuideDynamicStringInternationalization in turn links to the javadoc for Dictionary, which can be found at https://www.gwtproject.org/javadoc/latest/com/google/gwt/i18n/client/Dictionary.html.
On that page, there are two code snippets that demonstrate the idea.
First, the host page (or some other JS that runs on the host page) should provide an object with keys and values that represent the data you want to access at runtime. In this example, they load theme data, rather than strings for messages:
var CurrentTheme = {
highlightColor: "#FFFFFF",
shadowColor: "#808080",
errorColor: "#FF0000",
errorIconSrc: "stopsign.gif"
};
This could also be assigned as something like window.CurrentTheme = {... instead, so long as it is attached to the global window scope in the host window.
Next, a Dictionary instance can be created and given the same name as the object was assigned to. That dictionary can then be queries for the various keys - note that the keys can even change at runtime - there's neither a requirement that the keys nor the values are constants.
Dictionary theme = Dictionary.getDictionary("CurrentTheme");
String highlightColor = theme.get("highlightColor");
String shadowColor = theme.get("shadowColor");
applyShadowStyle(highlightColor, shadowColor);
String errorColor = theme.get("errorColor");
String errorIconSrc = theme.get("errorIconSrc");
Image errorImg = new Image(errorIconSrc);
showError(errorColor, errorImg);

Array of cards within <Content>

I would like to know if there was any way I could create an array of Card objects using Nativebase, and call upon these objects to change their properties like array[1].Text = "example", although I don't know how I would change the body of an XML tag through a function like the one described above.

How to extend ScreenRender

The ScreenRender is initialised with ScreenRenderImpl in ScreenFacadeImpl.makeRender, while ScreenFacade is initialised in ExcecutionContextFactoryImpl. In some cases, I would like to add more functions in ScreenRender that can be invoked in Macro templates. Instead of overriding the ExecutionContextFactoryImpl and down to ScreenRenderImpl as well s MoquiContextListener, is there a way to simply inject a sub class of ScreenRenderImpl when ScreenFacade.makeRender?
A real case to get support of sri in macro template is:
I am trying to populate the options of select via list-options or entity-options or via manual option which return by sri.getFieldOptions(). But it is kind of bound to form fields. I want to use in non-form context. So I kind of want to extend ScreenRender to have a function like sri.getOptions().

How can I use Intellij Structural Search to find all methods that use two named classes?

Say I have two Java classes, TradeType and InstrumentType. I know that somewhere in my codebase there is a method that maps from TradeType to InstrumentType.
How can I use Structural Search in Intellij to say
"find me all methods that have a single parameter of type TradeType and which return InstrumentType"
Search template:
class $Class$ {
InstrumentType $MethodName$(TradeType $Parameter$);
}
Then click Edit variables..., and set the following for the MethodName variable:
Occurrences count: Unlimited
This variable is target of the search
Also pay attention to what the scope of the search is.

IntelliJ IDEA: how to find all instance creation of a class?

abstract class Base {}
class A extends Base
class B extends Base
How do I find all places in the code that create Base? (that is, have either new A() or new B())
UPDATE
To make it clear, the above is just and example. I'm interested in a way of searching for object creation of any class, including 3rd party classes that I don't control.
Using Structural Search (Edit -> Find -> Search Structurally):
Create a template: new $Type$($P$)
Edit Type variable: type Base in the text field, check 'Apply constraint within type hierarchy', check 'This variable is target of the search'
Edit P variable: type .* in the text field, set Minimum count to 0, check Unlimited under Maximum count.
Voila!
IttayD if I have understood correctly your latest update, what I normally do (IntelliJ 9.0.4) if I have a similar need to yours is Right click on class name and do "Find Usages" and this will list results in the form of usage categories,
Variable declaration
New Instance creation, to name a few.
As far as I'm aware I do not think there is a specific option/selection choice to fulfill such a usage search check. Thanks
You can create empty default constructor of Base and press Ctrl+Alt+H (Hierarchy Callers). Then you'll see all creations of A and B in as a tree.