by dguo · 6y ago · 0 comments
I second the sentiment though. I wouldn't choose to use plain JavaScript over TypeScript for any significant project.
You might ask why I wouldn't just use a more fully typed language like Java. My main response is that I love having the flexibility to choose how strict the types should be. Sometimes, typing something out fully is not worth the trouble. Having escape hatches lets me make that choice. While I enjoy using types to turn runtime bugs into compile time errors as much as possible, it's not the right thing to do 100% of the time.
What is an example of this in your experience? I am trying to think of one, but after 25 years of programming, I cannot say I have ever encountered a case where it was worth using ‘an escape hatch’ that did not bite us later on. Maybe it is the type of software/clients I work with, but ‘the trouble’ is not really something I have seem before I think.
It was definitely worth the effort then. I also recognize why it is a very unlikely scenario to repeat.
The other place where I used dynamic most heavily in C# was that it was really great for IronPython interop where you could have a bit of "data science" done in a Python module, build that to a .NET assembly and call into the Python module from C#. (Though the other direction was more common, using IronPython to do data science around a bulk of C# models and code.) With so much more data science since that past life of mine having moved to Python, it's almost a shame that IronPython hasn't really kept up.
Maybe I should have amended my comments for 99% of the time? Or perhaps that there are other functionalities (e.g. tuple types, reflection) to to make working with types almost as easy as without? I use reflection very frequently...
No, it does not. There is no difference between static languages and dynamic languages when parsing data at runtime.
I saw other commenter say that the benefit of using TS in the frontend and backend, then DB updates in the backend also update the frontend code: "The beauty of Gary’s setup is changes to his database update the types for the server side Code AND client side code. The value of that comes from using the same language in both platforms"
Can you get this sort of benefit with Kotlin? How?
"Don't do frontend development in anything else than JavaScript ... You will probably run in to an abstraction leak that causes problems if you do the frontend in Kotlin." https://www.reddit.com/r/webdev/comments/etzy5u/web_developm...
I ask this seriously. I would love to do full-stack Kotlin. I just don't want to take the plunge and later realize it was a big mistake.
https://www.newtonsoft.com/json/help/html/SerializationAttri...
I would avoid using dynamic (I believe underneath it is basically the same as the Dictionary<T, U> anyway, howeve r I don't really care to look it up).
Also regarding var. It is best IMO to use var when evident i.e. If the var right hand side is obvious what the type is use var, if it isn't use the Type name.
e.g.
When you should use var (it is evident from the right hand side)
var name = "Joe Bloggs";
vs when it isn't evident: var myVariables = _service.SomeMethod();
It allows the code to be better read without the IDE. However obviously it is up to you. var myVariables = _service.SomeMethod();
Sure when you write non-obvious code `var` sucks. But: var product = service.FetchProduct(productId);
If the type of var is not obvious to you then you have bigger problems to worry about.A change to the DB schema just required me to refresh our edmx from the DB schema and then build.
But type safety is a spectrum anyway. One could say that not having dependent types is like having a swimming pool without a lifeguard.
Should every swimming pool in the world have a lifeguard? Probably not.