Re:Codon: A high-performance Python-like compiler using LLVM
by jnxx on Thursday December 08, 2022 @03:17PM
(#33912748)
I have been using Python since 25 years, and never needed that one.
[ Parent
| on HN ]
Re:Codon: A high-performance Python-like compiler using LLVM
by ris on Thursday December 08, 2022 @04:49PM
(#33914059)
You've never had to read arbitrary json?
Re:Codon: A high-performance Python-like compiler using LLVM
by insanitybit on Thursday December 08, 2022 @05:20PM
(#33914536)
I just did a quick check (apparently DuckDuckGo has a built in JSON validation function lol love it) and `[1, "foo"]` does pass their JSON validation.
Not surprised but I did want to confirm.
Re:Codon: A high-performance Python-like compiler using LLVM
by okayexplainl4 on Friday December 09, 2022 @08:30AM
(#33920992)
Am I missing something, why wouldn't a non-homogeneous array literal pass?
Re:Codon: A high-performance Python-like compiler using LLVM
by insanitybit on Friday December 09, 2022 @12:23PM
(#33923931)
Because mixing types in an array is stupid enough that I thought it might just not be valid.
Re:Codon: A high-performance Python-like compiler using LLVM
by ris on Friday December 09, 2022 @02:49PM
(#33925705)
Mixing types in an array/list is not remotely stupid. How exactly would you suggest expressing the lack of a value in a series of numbers without None/null? There's your mixed types.
Don't let weird dogma get in the way of practicality.
Re:Codon: A high-performance Python-like compiler using LLVM
by qwefsdf on Friday December 09, 2022 @05:52PM
(#33927500)
That's an Optional[int]. It's not "mixed types", it's a union type.
Re:Codon: A high-performance Python-like compiler using LLVM
by ris on Sunday December 11, 2022 @08:03AM
(#33942802)
That is merely a detail of how the typing module has decided to set up convenient aliases. Treated by the language (and likely compilers) as different types.
Re:Codon: A high-performance Python-like compiler using LLVM
by insanitybit on Friday December 09, 2022 @05:35PM
(#33927310)
JSON has a `null` value already, and null is its own special case in most languages where `null` is a universal type.
Otherwise you tag your data so that it's an array of objects.
Re:Codon: A high-performance Python-like compiler using LLVM
by bombolo on Thursday December 08, 2022 @06:14PM
(#33915112)
You never implemented a quick polish notation calculator that uses this data structure? [1,2, '+']
Re:Codon: A high-performance Python-like compiler using LLVM
by chenzhekl on Friday December 09, 2022 @12:41AM
(#33917937)
I would use two stacks, one of which stores numbers and the other stores operators.
Re:Codon: A high-performance Python-like compiler using LLVM
by bombolo on Friday December 09, 2022 @05:28AM
(#33919778)
Why? Just to have no unions of types?
Re:Codon: A high-performance Python-like compiler using LLVM
by joshmaker on Thursday December 08, 2022 @03:22PM
(#33912801)
In 25 years you’ve never once created a list with more than one type of object in it?
Re:Codon: A high-performance Python-like compiler using LLVM
by throwaway894345 on Thursday December 08, 2022 @03:36PM
(#33912994)
I mean, it depends on what you mean by “type”. A list of some Protocol type (what other languages call “interfaces”) is still a homogenous list even though the concrete types are heterogeneous. This is almost always what you want when you’re thinking of “a heterogeneous list”.
Re:Codon: A high-performance Python-like compiler using LLVM
by bombolo on Thursday December 08, 2022 @06:15PM
(#33915121)
It's not unheard of to have unions and a couple of if isinstance.
In fact it's why in python they even have the | operator between types nowadays.
Re:Codon: A high-performance Python-like compiler using LLVM
by mangecoeur on Thursday December 08, 2022 @03:26PM
(#33912868)
I have also been using python a long time and i honestly can’t remember a time i used mixed type list.
Re:Codon: A high-performance Python-like compiler using LLVM
by querez on Thursday December 08, 2022 @03:37PM
(#33913001)
In my code this comes up often, e.g. when I use tuples instead of namedtuple or a dataclass.
Re:Codon: A high-performance Python-like compiler using LLVM
by bastawhiz on Thursday December 08, 2022 @03:44PM
(#33913098)
Tuples aren't lists though. Tuples are really just structs with indexes instead of names.
Re:Codon: A high-performance Python-like compiler using LLVM
by ris on Friday December 09, 2022 @02:46PM
(#33925673)
Never have to handle/forward function calls with arbitrary arguments? What do you think *args is?
Re:Codon: A high-performance Python-like compiler using LLVM
by mangecoeur on Friday December 09, 2022 @05:07PM
(#33927008)
a tuple
Re:Codon: A high-performance Python-like compiler using LLVM
by froggit on Thursday December 08, 2022 @08:48PM
(#33916370)
I use mixed lists all the time to store shit, but I'm also a total python newb that really doesn't know better.
Re:Codon: A high-performance Python-like compiler using LLVM
by cjohnson318 on Thursday December 08, 2022 @03:24PM
(#33912844)
Maybe a list with ThingObject or None, but my lists are usually homogenous.
Re:Codon: A high-performance Python-like compiler using LLVM
by mrfox321 on Thursday December 08, 2022 @05:16PM
(#33914479)
thats just homogenous Sequence[Optional[T]], though.
Re:Codon: A high-performance Python-like compiler using LLVM
by cjohnson318 on Thursday December 08, 2022 @10:22PM
(#33917027)
Yeah, that's a better way of putting it :) 90% of the time, I'm something like Sequence[T], but I'm sure I've used Sequence[Optional[T]] a couple of times. I mean, I could drive donuts in the Piggly Wiggly parking lot at 3a, I just don't, and the same for heterogenous lists.
Re:Codon: A high-performance Python-like compiler using LLVM
by agumonkey on Friday December 09, 2022 @12:04AM
(#33917668)
And everything is a subtype of Any. The usual 'static typing' of dynlangs.
Re:Codon: A high-performance Python-like compiler using LLVM
by bombolo on Thursday December 08, 2022 @06:16PM
(#33915131)
well list[int|str] is as well
Re:Codon: A high-performance Python-like compiler using LLVM
by gautamdivgi on Thursday December 08, 2022 @03:34PM
(#33912970)
I’ll second that. I’ve been doing python for a while and haven’t used the mixed type list. I’ve actively avoided doing something like that. The situation doesn’t come up often.
Re:Codon: A high-performance Python-like compiler using LLVM
by terhechte on Thursday December 08, 2022 @03:40PM
(#33913042)
Same here. If I needed that I might use a tuple.
Re:Codon: A high-performance Python-like compiler using LLVM
by amelius on Thursday December 08, 2022 @04:18PM
(#33913566)
And then it crashes when you convert it to JSON.
Re:Codon: A high-performance Python-like compiler using LLVM
by UncleEntity on Thursday December 08, 2022 @06:42PM
(#33915434)
I just use an extension wrapper around boost::property_tree for my json (and xml) needs. Way faster than the built in json support and does automagic type conversion so I don’t have to worry about it.
Now, I’m not running at Web Scale™ but pure python was slow enough to be annoying.