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’s int() now. Types are capitalized.
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)'
$ 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.
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.
(x in mystr)
(x in mylist)
(x in mydict)
a < b
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:
oil$ = 1 === "1"
oil$ = 1 < "2"
(it’s like Lua, the RHS is evaluated and printed)