3 ms·
> Off topic, but my new found love for Python comes from realizing that many programming tasks can be done so much faster in Python. There's a "freedom of expr
by bb88 4y ago
> Off topic, but my new found love for Python comes from realizing that many programming tasks can be done so much faster in Python.
There's a "freedom of expression" that python has that other languages such as Java/Go lacks. C++ can have similar expressive power by overloading operators, then this was of course eschewed by Java and Go. Go and Java provide a framework for writing code their way. Python doesn't insist you use OOP methodologies, if you don't want (e.g.)
I built a data conversion system in python using the ">>" operator to simplify translation of data.
temp_f = json_data["temp_c"] >> if_none(use=0) >> to_decimal() >> round(places=4) >> convert_to_f()
For large data structures this becomes tedious with if/elif/else statements and null checking for a small piece of data. Particularly if you're going to translate one large data structure to another.
- Spivak 4y agoI think you got downvoted for the operator overloading but as long as it's used with intention you're fine. Python itself abuses bitwise or for types, everyone's darling SQLAlchemy overloads all the comparators to make filter expressions. Testing libs also overload comparisons to make matchers.
- bb88 4y agoPeople dislike python these days on there, for whatever reason. HN is not the place I like to discuss programming anymore.
- pjmlp 4y agoPython is OOP to its bones, even basic types are instances of specific classes. >>> i = 12 >>> type(i) <class 'int'> >>> dir(i) ['__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__index__', '__init__', '__init_subclass__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'bit_length', 'conjugate', 'denominator', 'from_bytes', 'imag', 'numerator', 'real', 'to_bytes']
- fragmede 4y agoThat's pretty neat! Is it packaged up into a library somewhere or is it proprietary?