Open markknol opened 8 years ago
How to type Json using typedefs
This one is quite "funny". We even have such example in the manual, but in fact, it's not really safe when it comes to arrays on static targets, e.g.:
var a:Array<Int> = haxe.Json.parse("[1,2,3]")
This compiles (because of Dynamic
) but might either fail at runtime or introduce hidden copy-casting, because haxe.Json.parse
parses arrays to Array<Dynamic>
which isn't really the same as Array<Int>
on targets like C# and C++ which try to implement arrays in an efficient way for basic types.
So nowadays I'm doubting that this is something we should promote. At least we should note that particular issue so people are aware of it.
I think @hughsando dealt with this somehow for the newer hxcpp, but this is still an issue in C# (without -D erase-generics
).
Alright, seems doable.
But I'm still waiting on someone to approve or review the Stack Overflow documentation changes I proposed! ;)
A couple more things (that I think are highly needed):
I have another request: more macro-related stuff. :+1:
As of writing I'm in the process of trying to learn them, and have found myself with tens of tabs open from various sources (manual (new and old)/blog posts/articles/libs). All of them helpful! But infos are scattered around, and I find myself jumping back and forth trying to collect the missing pieces.
The code cookbook has been particularly helpful so far, I just really wish it had more examples. Please! :stuck_out_tongue:
So... here's a little list of some of the difficulties/confusing-moments I've faced so far (hoping it can serve as hint for more enlightening snippets):
using
the various macro.*Tools
without mentioning them in comments makes it harder to understand the codeType
vs ComplexType
TAnonymous
(same name, but present in different modules)macro keyword
vs macro define
(what's the relation, when it's NEEDED to use the keyword, etc.?) (I currently use a trial&error approach: run the compiler until it works, and then analyse the output)As I said, I've just recently started to make sense of the powerful macro system, and I think that learning from useful examples is the best way.
PS: Someone may object that my points are material for StackOverflow or the MailingList. I agree, but having them explained clearly in the official cookbook is a plus (SO and ML could still link to them).
Those are helpful ideas, thanks! If you want to contribute to one of those topics,feel free to add it.
If you are in the mood for writing but don't know what, then you can use this list:
Using HXML (https://blog.onthewings.net/2013/03/04/hxml-tricks-every-haxe-user-should-know/)this is in manual nowmacro --include
to bundle external js filesBtw, these titles are suggestions. This list will get updated over time.