On 10/27/2026 7:35 PM, Arne Vajhøj wrote:
> If you want to go the simpler route, then I will suggest an
> unusual tech stack.
>
> JSP with JSTL as view. That mean all tags no script snippets
> in view - tags is also some sort of code but very structured.
>
> Groovy grovelets as backend code. It is just another script
> language, but:
> * most of the easiness you expect from a script language
> * no funkyness with ==
> * optional typing but if a type is specified then it is enforced - it
> is not just a hint
Here comes a little comparison with Python and PHP.
Tested with:
* Python 3.10
* PHP 8.1
* Groovy 4.0
Not latest and greatest but what I have on my 9.2-3 system.
Let us look at simple assignment.
$ type asg.py
iv = 123
sv = 'ABC'
print('%s : %d, %s : %s' % (type(iv), iv, type(sv), sv))
iv = 'DEF'
sv = 456
print('%s : %s, %s : %d' % (type(iv), iv, type(sv), sv))
$ python asg.py
<class 'int'> : 123, <class 'str'> : ABC
<class 'str'> : DEF, <class 'int'> : 456
$ type asgtyp.py
iv: int = 123
sv: str = 'ABC'
print('%s : %d, %s : %s' % (type(iv), iv, type(sv), sv))
iv = 'DEF'
sv = 456
print('%s : %s, %s : %d' % (type(iv), iv, type(sv), sv))
$ python asgtyp.py
<class 'int'> : 123, <class 'str'> : ABC
<class 'str'> : DEF, <class 'int'> : 456
$ type asg.php
<?php
$iv = 123;
$sv = "ABC";
echo sprintf("%s : %d, %s : %s\n", gettype($iv), $iv, gettype($sv), $sv);
$iv = "DEF";
$sv = 456;
echo sprintf("%s : %s, %s : %d\n", gettype($iv), $iv, gettype($sv),$sv);
?>
$ php asg.php
integer : 123, string : ABC
string : DEF, integer : 456
$ type asg.groovy
iv = 123
sv = "ABC"
printf("%s : %d, %s : %s\n", iv.getClass().name, iv, sv.getClass().name, sv)
iv = "DEF"
sv = 456
printf("%s : %s, %s : %d\n", iv.getClass().name, iv, sv.getClass().name, sv)
$ groovy asg.groovy
java.lang.Integer : 123, java.lang.String : ABC
java.lang.String : DEF, java.lang.Integer : 456
$ type asgtyp.groovy
int iv = 123
String sv = "ABC"
printf("%s : %d, %s : %s\n", iv.getClass().name, iv, sv.getClass().name, sv)
iv = "DEF"
sv = 456
printf("%s : %s, %s : %d\n", iv.getClass().name, iv, sv.getClass().name, sv)
$ groovy asgtyp.groovy
java.lang.Integer : 123, java.lang.String : ABC
Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'DEF' with class 'java.lang.String' to class 'int'
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'DEF' with class 'java.lang.String' to class 'int'
at ASGTYP.run(ASGTYP.GROOVY:4)
We see that:
* Python without type hint, Python with type hint, PHP and Groovy without type
happily allows variables changing type with assignment [BAD]
* Groovy with type gives an error when assigning a wrong type [GOOD]
Let us look at function call.
$ type fc.py
def f(v):
vtyp = type(v)
print(f"{vtyp} : {v}")
f(123)
f("123")
f("ABC")
$ python fc.py
<class 'int'> : 123
<class 'str'> : 123
<class 'str'> : ABC
$ type fctyp.py
def f(v: int):
vtyp = type(v)
print(f"{vtyp} : {v}")
f(123)
f("123")
f("ABC")
$ python fctyp.py
<class 'int'> : 123
<class 'str'> : 123
<class 'str'> : ABC
$ type fc.php
<?php
function f($v) {
$vtyp = gettype($v);
echo "$vtyp : $v\r\n";
}
f(123);
f("123");
f("ABC");
?>
$ php fc.php
integer : 123
string : 123
string : ABC
$ type fctyp.php
<?php
function f(int $v) {
$vtyp = gettype($v);
echo "$vtyp : $v\r\n";
}
f(123);
f("123");
f("ABC");
?>
$ php fctyp.php
integer : 123
integer : 123
PHP Fatal error: Uncaught TypeError: f(): Argument #1 ($v) must be of type int, string given, called in /disk2/arne/typ/fctyp.php on line 10 and defined in /disk2/arne/typ/fctyp.php:3
Stack trace:
#0 /disk2/arne/typ/fctyp.php(10): f('ABC')
#1 {main}
thrown in /disk2/arne/typ/fctyp.php on line 3
Fatal error: Uncaught TypeError: f(): Argument #1 ($v) must be of type int, string given, called in /disk2/arne/typ/fctyp.php on line 10 and defined in /disk2/arne/typ/fctyp.php:3
Stack trace:
#0 /disk2/arne/typ/fctyp.php(10): f('ABC')
#1 {main}
thrown in /disk2/arne/typ/fctyp.php on line 3
$ type fctypx.php
<?php
declare(strict_types=1);
function f(int $v) {
$vtyp = gettype($v);
echo "$vtyp : $v\r\n";
}
f(123);
f("123");
f("ABC");
?>
$ php fctypx.php
integer : 123
PHP Fatal error: Uncaught TypeError: f(): Argument #1 ($v) must be of type int, string given, called in /disk2/arne/typ/fctypx.php on line 11 and defined in /disk2/arne/typ/fctypx.php:5
Stack trace:
#0 /disk2/arne/typ/fctypx.php(11): f('123')
#1 {main}
thrown in /disk2/arne/typ/fctypx.php on line 5
Fatal error: Uncaught TypeError: f(): Argument #1 ($v) must be of type int, string given, called in /disk2/arne/typ/fctypx.php on line 11 and defined in /disk2/arne/typ/fctypx.php:5
Stack trace:
#0 /disk2/arne/typ/fctypx.php(11): f('123')
#1 {main}
thrown in /disk2/arne/typ/fctypx.php on line 5
$ type fc.groovy
def f(v) {
vtyp = v.getClass().name
println("$vtyp : $v")
}
f(123)
f("123")
f("ABC")
$ groovy fc.groovy
java.lang.Integer : 123
java.lang.String : 123
java.lang.String : ABC
$ type fctyp.groovy
def f(int v) {
vtyp = v.getClass().name
println("$vtyp : $v")
}
f(123)
f("123")
f("ABC")
$ groovy fctyp.groovy
java.lang.Integer : 123
Caught: groovy.lang.MissingMethodException: No signature of method: FCTYP.f() is applicable for argument types: (String) values: [123]
Possible solutions: f(int), is(java.lang.Object), NV(java.lang.Object), SV([Ljava.lang.Object;), run(), run()
groovy.lang.MissingMethodException: No signature of method: FCTYP.f() is applicable for argument types: (String) values: [123]
Possible solutions: f(int), is(java.lang.Object), NV(java.lang.Object), SV([Ljava.lang.Object;), run(), run()
at FCTYP.run(FCTYP.GROOVY:7)
We see that:
* Python without type hint, Python with type hint, PHP without type hint and
Groovy without type happily allows calls with any data type [BAD]
* PHP with type hint but no strict_types=1 gives an error when called with a
value that cannot be converted to correct type but does automatic conversion
when called with a value that can be converted to correct type [QUESTIONABLE]
* PHP with type hint plus strict_types=1 and Groovy with type gives an error
when called with wrong type [GOOD]
Let us look at function overload.
$ type fol.py
def f(v: int):
print(f"int : {v}")
def f(v: str):
print(f"str : {v}")
f(123)
f("ABC")
$ python fol.py
str : 123
str : ABC
$ type fol.php
<?php
function f(int $v) {
echo "int : $v\r\n";
}
function f(string $v) {
echo "string : $v\r\n";
}
f(123);
f("ABC");
?>
$ php fol.php
PHP Fatal error: Cannot redeclare f() (previously declared in /disk2/arne/typ/fol.php:3) in /disk2/arne/typ/fol.php on line 8
Fatal error: Cannot redeclare f() (previously declared in /disk2/arne/typ/fol.php:3) in /disk2/arne/typ/fol.php on line 8
$ type fol.groovy
def f(int v) {
println("int : $v")
}
def f(String v) {
println("String : $v")
}
f(123)
f("ABC")
$ groovy fol.groovy
int : 123
String : ABC
We see that:
* Python just let the last function overwrite the previous one and ignores type
hints [BAD]
* PHP gives an error [ACCEPTABLE]
* Groovy it works [GOOD]
So if you want a script language with type safety, then:
Python - definitely avoid
PHP - getting better with newer features
Groovy - use types and you got what you want
And I know you can code in Groovy. :-)
Arne