Freemarker single = in if statement - keycloak

Keycloak uses Freemarker templates. There you find single = in if-statements.
Freemarker's documentation tells me to use == in if-statements.
Keyclaok's templates seem to work. Can anyone enlighten me?

It is allowed in expressions, but deprecated. From the "Comparison" section of the expression documentation:
To test two values for equality you use == (or = as a deprecated alternative)
See: https://freemarker.apache.org/docs/dgui_template_exp.html#dgui_template_exp_comparison

Related

How to Write a Flutter Ternary Operator with one of the conditions being null (do nothing)

The following works in Flutter, however, I have an IDE warning to avoid "unnecessary statements." I'm sure many will pipe in citing the Latin root of three in ternary and other critiques, and I appreciate that kind of fun dialog, I really do, however, sometimes in a nested sequence, this stuff comes up..not just in the simple example I'm giving.
As I said, the below works, I just get an Android Studio IDE warning. I'd probably be better off to correct it if there is something more appropriate when using a ternary operator
x == 4 ? doSomething() : null
Couldn't find any documentation on this.
Just don't use ternary.
if( x == 4 ) doSomething()
Applies to List and Map as well.
Android Studio at least has updated this check and it is now allowed without warnings. It was a common logic in validators at least, and someone saw the light. So the correct answer was: It's perfectly reasonable and good code. (at least in my opinion!)
The ternary operator is not built for such a situation. It should use where we have at least two options
condition ? doThisIfTrue() : doThisIfFalse()
If we have only one option, then simply use if
if ( condition ) {
doThis
}
The code that you wrote, is not wrong either, but that is not use of ternary operator.

Why to use := in Scala? [duplicate]

What is the difference between = and := in Scala?
I have googled extensively for "scala colon-equals", but was unable to find anything definitive.
= in scala is the actual assignment operator -- it does a handful of specific things that for the most part you don't have control over, such as
Giving a val or var a value when it's created
Changing the value of a var
Changing the value of a field on a class
Making a type alias
Probably others
:= is not a built-in operator -- anyone can overload it and define it to mean whatever they like. The reason people like to use := is because it looks very assignmenty and is used as an assignment operator in other languages.
So, if you're trying to find out what := means in the particular library you're using... my advice is look through the Scaladocs (if they exist) for a method named :=.
from Martin Odersky:
Initially we had colon-equals for assignment—just as in Pascal, Modula, and Ada—and a single equals sign for equality. A lot of programming theorists would argue that that's the right way to do it. Assignment is not equality, and you should therefore use a different symbol for assignment. But then I tried it out with some people coming from Java. The reaction I got was, "Well, this looks like an interesting language. But why do you write colon-equals? What is it?" And I explained that its like that in Pascal. They said, "Now I understand, but I don't understand why you insist on doing that." Then I realized this is not something we wanted to insist on. We didn't want to say, "We have a better language because we write colon-equals instead of equals for assignment." It's a totally minor point, and people can get used to either approach. So we decided to not fight convention in these minor things, when there were other places where we did want to make a difference.
from The Goals of Scala's Design
= performs assignment. := is not defined in the standard library or the language specification. It's a name that is free for other libraries or your code to use, if you wish.
Scala allows for operator overloading, where you can define the behaviour of an operator just like you could write a method.
As in other languages, = is an assignment operator.
The is no standard operator I'm aware of called :=, but could define one with this name. If you see an operator like this, you should check up the documentation of whatever you're looking at, or search for where that operator is defined.
There is a lot you can do with Scala operators. You can essentially make an operator out of virtually any characters you like.

Why does CoffeeScript not support `==`?

I am learning CoffeeScript and am using js2.coffee to convert my Javascript file to CoffeeScript. One some lines, it warns me that
Operator '==' is not supported in CoffeeScript, use '===' instead.
What is the rationale behind that? Why does CoffeeScript not support ==?
For the same reason that most Linters warn you against using it.
It's a strangely implemented operator with surprising side-effects.
"\n\t" == false
// => true
There are many things written on the topic, but most notably the == operator made Douglas Crockford's list of things to avoid.
Actually CoffeeScript compiles == to JavaScript's === (and != to !== as you can see in the documentation).
So bottom line yes, it doesn't support it. I guess it is because == does type conversion before checking equality if the operands are of different type. This conversion is a practice that has been frowned upon because of its unexpected results and its performance.
There is much discussion online on the issue of == vs ===. MDN docs helped me get a better understanding on the issue.

Add a new assignment operator

I started using smalltalk and I am trying to add a new assignment operator :>.
The current operator used in pharo is no selector so I started to look into the class Scanner where the underscore _ can be enabled for assignments. I've tried to do it in a similar way but it did not work.
Do you have any idea or suggestion about how I achieve that?
For a start, have a look at the Method Scanner>>#xColon. This method is called whenever a colon is encountered in the input. By adding the following snippet to the top of the method, you can make it detect your new assignment token :>:
aheadChar = $> ifTrue: [
self step.
tokenType := #leftArrow.
self step.
^ token := #':=' ]
Like this :> behaves exactly like the normal assignment. By customising tokenType and token you can pass your new assignment operator to the parser (see Parser>>#expression and Parser>>#assignment:) and build a different AST (i.e. to achieve a different execution behaviour).
If you are interested in more flexibility you might want to look at Helvetia. Helvetia is a language workbench for Pharo that allows you to modify the host language and adapt the tools in a more modular fashion. One of the examples included with the distribution (CUSwapExample) is adding two new assignment operators to Smalltalk.

What is the difference between = and := in Scala?

What is the difference between = and := in Scala?
I have googled extensively for "scala colon-equals", but was unable to find anything definitive.
= in scala is the actual assignment operator -- it does a handful of specific things that for the most part you don't have control over, such as
Giving a val or var a value when it's created
Changing the value of a var
Changing the value of a field on a class
Making a type alias
Probably others
:= is not a built-in operator -- anyone can overload it and define it to mean whatever they like. The reason people like to use := is because it looks very assignmenty and is used as an assignment operator in other languages.
So, if you're trying to find out what := means in the particular library you're using... my advice is look through the Scaladocs (if they exist) for a method named :=.
from Martin Odersky:
Initially we had colon-equals for assignment—just as in Pascal, Modula, and Ada—and a single equals sign for equality. A lot of programming theorists would argue that that's the right way to do it. Assignment is not equality, and you should therefore use a different symbol for assignment. But then I tried it out with some people coming from Java. The reaction I got was, "Well, this looks like an interesting language. But why do you write colon-equals? What is it?" And I explained that its like that in Pascal. They said, "Now I understand, but I don't understand why you insist on doing that." Then I realized this is not something we wanted to insist on. We didn't want to say, "We have a better language because we write colon-equals instead of equals for assignment." It's a totally minor point, and people can get used to either approach. So we decided to not fight convention in these minor things, when there were other places where we did want to make a difference.
from The Goals of Scala's Design
= performs assignment. := is not defined in the standard library or the language specification. It's a name that is free for other libraries or your code to use, if you wish.
Scala allows for operator overloading, where you can define the behaviour of an operator just like you could write a method.
As in other languages, = is an assignment operator.
The is no standard operator I'm aware of called :=, but could define one with this name. If you see an operator like this, you should check up the documentation of whatever you're looking at, or search for where that operator is defined.
There is a lot you can do with Scala operators. You can essentially make an operator out of virtually any characters you like.