Hacker News new | ask | show | jobs
by kitsunesoba 2617 days ago
Indeed, Flutter would be much more compelling if I could use it with Rust or Swift instead. Dart really doesn’t interest me.
1 comments

One nice think about Dart I've found is that compile times are very fast (faster than Go) and when editing in VSCode the code intelligence is instant and 100% accurate in my experience.

Compare that to Rust where compilation speed is almost as bad as C++, RLS is slower than e.g. Qt Creator's clang lints, and has auto-completions so innaccurate that they are almost worse than nothing.

Buuut.... I wanted to make a deep copy of an object (a map of maps) in Dart, and one of the suggestions on Stackoverflow is to serialise it to JSON and then deserialise it. Eek. In C++ you just do `auto a = b;`. In Rust `let a = b.clone();`. How do they leave out such basic functionality?

https://stackoverflow.com/a/26616081/265521

> In C++ you just do `auto a = b;`.

Sure, but does it do what you want? :) If that map contains pointers or other types with "interesting" assignment semantics, then your idea of a deep copy and that author of that type's idea may not be the same. Cloning is a surprisingly hard problem.

The two languages you compare to don't have GCs and prefer value semantics. But in most GC languages, everything is by reference and "copying the bits" isn't as meaningful of an operation.

I looked up how to deep clone maps in some other GC languages:

https://stackoverflow.com/questions/4157399/how-do-i-copy-a-...

Ruby: Top suggestion is to marhsall/unmarshall it.

https://stackoverflow.com/questions/5105517/deep-copy-of-a-d...

Python: Import a separate "copy" module. May have to implement some custom methods if you use user-defined objects in the map. The module isn't thread-safe. A comment recommends converting to JSON and back.

https://stackoverflow.com/questions/28288546/how-to-copy-has...

Java: No built in solution. Have to traverse the map yourself and do element-wise copies.

As someone who uses dart everyday - it's quite nice language. All I'm missing is case / data classes, non-nullable types and pattern matching, but they're changing the language and all of those will eventually come. For now, I will use built_value and built_collections ;)
> your idea of a deep copy and that author of that type's idea may not be the same

Definitely true that they may have done something weird, but I think the idea of a deep copy is pretty easy to define: It should not be possible to modify the original object using only the deep copy. (Note that this doesn't preclude copy-on-write, etc.)

I think it is quite weird that so few languages (even GC'd ones) provide a proper solution for this. It's clearly a thing people want to do.

Surely not faster than Delphi, oh well.