Glad readers are paying attention :) You COULD call it weak typing â there is implicit conversion. But I think weak typing has the connotation of âfootgunsâ, and I have taken pains to avoid the footguns. Itâs supposed to give you the convenience of shell, PHP, and Perl, but without the downsides :)
Of course I welcome people to test that claim! If you find any problems we can still change it. (OSH is stable now, but Oil is not.)
There is an explicit Int('42') function now, which is just Pythonâs int() now. Types are capitalized.
I think Oilâs behavior is more predictable than Python 2, JavaScript, and arguably Python 3. The key difference is that operators arenât overloaded in Oil:
+ is always addition (itâs not also concatenation as in Python and JavaScript)
++ is always concatenation (for strings and lists)
There is no == operator as in Python and JS. You have to choose === for exact equality or ~== for type converting quality. The latter is quite useful for shell-like code.
So I wouldnât frame it in terms of âweak typingâ â I would frame it as WHEN conversions are done.
< is always numeric comparison (itâs never lexicographical comparison, which will probably be cmp() or something, akin to strcmp())
Prior to this change, Oil inherited Python 2âs comparison behavior, which was changed in Python 3. EVERY object was comparable to every other, and objects of different type were compared arbitrarily â by their type names.
$ python2 -c 'print("2" < 3)'
False
$ python3 -c 'print("2" < 3)'
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: '<' not supported between instances of 'str' and 'int'
Overall I would say Oil has more coherent and consistent data types than shell/Perl/PHP, BUT itâs also more concrete than Python.
It doesnât have Pythonâs highly overloaded object model, and extensible data types. Oil has simple JSON-like data types, more like JavaScript.
Iâve taught Python to beginners and I notice they get confused by the difference between (x in mystr), (x in mylist), and (x in mydict), as well as a < b meaning different things depending on the type, etc. Python code can be very clean and minimal, but Iâd also say there are TOO few syntactic cues in some cases.
Oil adopts weak typing. đ± I guess that makes sense for a shell language, but what about an explicit string-to-number conversion rune, like
#'1'
?Glad readers are paying attention :) You COULD call it weak typing â there is implicit conversion. But I think weak typing has the connotation of âfootgunsâ, and I have taken pains to avoid the footguns. Itâs supposed to give you the convenience of shell, PHP, and Perl, but without the downsides :)
Of course I welcome people to test that claim! If you find any problems we can still change it. (OSH is stable now, but Oil is not.)
There is an explicit
Int('42')
function now, which is just Pythonâsint()
now. Types are capitalized.I think Oilâs behavior is more predictable than Python 2, JavaScript, and arguably Python 3. The key difference is that operators arenât overloaded in Oil:
+
is always addition (itâs not also concatenation as in Python and JavaScript)++
is always concatenation (for strings and lists)==
operator as in Python and JS. You have to choose===
for exact equality or~==
for type converting quality. The latter is quite useful for shell-like code.<
is always numeric comparison (itâs never lexicographical comparison, which will probably becmp()
or something, akin tostrcmp()
)Prior to this change, Oil inherited Python 2âs comparison behavior, which was changed in Python 3. EVERY object was comparable to every other, and objects of different type were compared arbitrarily â by their type names.
Overall I would say Oil has more coherent and consistent data types than shell/Perl/PHP, BUT itâs also more concrete than Python.
It doesnât have Pythonâs highly overloaded object model, and extensible data types. Oil has simple JSON-like data types, more like JavaScript.
Iâve taught Python to beginners and I notice they get confused by the difference between
(x in mystr)
,(x in mylist)
, and(x in mydict)
, as well asa < b
meaning different things depending on the type, etc. Python code can be very clean and minimal, but Iâd also say there are TOO few syntactic cues in some cases.This doc is incomplete but contains much of this info: https://www.oilshell.org/release/latest/doc/oil-vs-python.html
Let me know what you think :) Ideally after testing. Hint, the
=
operator lets you evaluate expressions:(itâs like Lua, the RHS is evaluated and printed)