Posts

Showing posts with the label good

Why JSON Won ... And Is Good As It Is

I keep seeing developers complaining about different things with JSON protocol and don't get me wrong, I've been the first one trying to implement any sort of alternative starting from JSOMON and many others ... OK? Well, after so many years of client/server development is not that I've given up on thinking " something could be better or different ", is just that I have learned on my skin all reasons JSON is damn good as it is, and here just a few of these reasons. Reliable Serialization ? No , 'cause YAGNI . There are few serialization processes I know that kinda work as expected and since ever, PHP serialize is a good example. Recursion is not a problem, is part of the serialization process to solve it, as well as classes together with protected and private properties. You can save almost any object within its state, even if this object won't be, as reference, the same you serialized .. and I would say: of course ! There are also two handy methods, _...

with: Some Good Example

OK, I have said my last post would have been the last one about the with statement ... well, before I close the argument, I would like to show a couple of common good examples. Solve References Problem This is what somebody defined a tiny masterpiece with({o:myreference}){ o.doStuff(); o.var1 = "whatever"; // etc etc ... }; Above example annihilate every blame about the not sure if that is the var I meant to use since there is an explicit reference as is, as example, in Python programming language (until version 3.11) // Python with open("x.txt") as f: data = f.read() // JavaScript equivalent with({f:/* as */open("x.txt")}) data = f.read() Memory Safe Operations Another recycled example before I show more interesting stuff ... apparently the whole problem is about write silly code inside with , as if everybody has to define variables or assign stuff inside this statement. Hilariously, I have basically never assigned anything inside a...