For further actions, you may consider blocking this person and/or reporting abuse
Read next
最新テクノロジーを活用した株式運用の最前線
Foged Sharp -
PacketSDK: Exploring Unique App Monetization Strategies for Success
PacketSDK -
PacketSDK: Understanding the Importance of SDKs in Modern Application Development
PacketSDK -
Beyond Break-Fix: Building Robust Systems with Modern Infrastructure Management 🛠️
Denis Jacob -
Top comments (41)
Unique and interesting, but awful
Python 2.X:
Python is full of very tricky things ! I had a lot of fun reading this README which explains them.
never know it. it looks like js nightmare. :)
Fortunately it's gone in Python 3:
:D
It's no longer an integer :)
It still is. bool is a subclass of int:
Shameful mistake, thanks for clarifying ! I meant that they had their own type now, indeed from integer.
Full explanation
That readme is excellent, thanks for posting it!
Ah!!! Looks like Python is a distant relative of Javascript!!
In Ruby we can monkeypatch to easily add functionality to any class.
For example:
I'm extending the string class so that
"hello".yell!
outputs"HELLO!!!"
And now all strings in the program have access to the
yell!
method. ❤️I'll add that this is sort of bonkers and an easy way to add some really hard-to-debug code to an app. Use with great fear and caution.
That's amazing that Ruby and other languages can extend built-in classes as well.
Anyways, to show off C#, here you go.
C# can extend any classes using extension method syntax.
Outputs
Note that you should mark the parameter with
this
Here's how this would look in Kotlin:
Another interesting use is to create an Extension Property so you can print any type to the console, like this:
Which can be used like:
Since this is also available on any other
class
, any object you create will also have this property and it will call theirtoString()
.In F# it is also easy to add functionality to existing classes.
You can also add functions to existing static classes (modules) too.
Lots of languages support that, including most obviously Javascript.
Interesting. Is that possible via class definitions (class syntax I mean) or only via the prototype syntax?
A PowerShell script to get 5 most CPU intensive processes.
PowerShell passes .NET CLI object(s) into the next pipeline (<-- this is most unique feature of all shells) so there is need to parse text as you do in other shells (using
sed
orawk
).This is pretty neat
Thanks Vinay.
Leaf stores literals (constants) as rational numbers and is type safe.
good
is assigned the value1
-- there is no precision loss on the division.err
produces a compiler error since1/3*2
is not an integer.Woah. How do rational numbers interact with irrational numbers in this case? Are they approximated prior to any sort of arithmetic or are they considered incompatible types?
π
and1/2
were my two motivating reasons for making this feature.For irrationals, and other fractions, the system will switch to a high-precision floating point mode instead of a rational -- I honestly don't remember what the trigger criteria actually is, I think size of the rational.
What this allows however is that
π
is a single constant you can define to 100 decimal places. This is high enough precision that several constant operations, basic math, can work on this value without losing precision when converting to the actual system type. It doesn't matter if you convert to a 32/64/128-bit float, it'll have the full precision for that type. No need for constants per type, or stuff likeM_PI2
.Note this precision only applies to constants. Runtime variables are limited by the standard system types. Sometime later I'll add these numbers are runtime, but they're fairly special purpose at that point. The literal folding now is enough to cover the current intended use-cases.
Kotlin has this concept of
infix
functions, which means they are an extension function that has only 1 parameter and allows us to use them without the dot (.) operator and no parentheses (but you can also do it the normal way, if you want to).Declare the
infix
functionExample
JavaScript lets you swap variables without a temporary variable.
So does C:
OK, so this is specific to numeric values, actually, but it comes in handy in cryptographic code for constant time conditional swaps and things.
Thanks Dave.
There is no end to learning.
I feel humbled :)
Same in Python
Python has been on my mind lately. That's yet another good reason ;p
Javascript... Yes, Javascript is a barrel of pure quirk. Just pick variable scope. As if it wasn't bad enough that hoisting exists, the bizarre way scopes work allows you to write some truly awe-inspiring hackery, like this Fibonacci function:
It isn't that difficult to generate the Fibonacci Spiral through Oracle SQL :)
Right - something like this is fine:
Thanks to the batshit insane way that
this
works, it's a full-blown method.This capability isn't unusual. In Python, you can also add methods to instances, but you need to ensure you handle
self
:Languages such as C++ and Java, on the other hand, have immutable types (and in the former, types aren't themselves even a type).
JavaScript