As I understand, Julia claims to be general purpose programming language?
Here is an example to illustrate what I’m talking about:
julia> r = HTTP.get("https://httpbin.org/json");
julia> JSON.parse(String(r.body))
Dict{String,Any} with 1 entry:
"slideshow" => Dict{String,Any}("slides"=>Any[Dict{String,Any}("title"=>"Wake up t…
Here is a list of symptoms why Julia does not look like a general purpose language:
Julia has huge set of math functions, but there is no build in JSON support.
Julia has excellent features to build and display vectors and matrices, but support for dicts is really disappointing.
Dicts does not look like JSON.
Default dict representation printent in REPL is unreadable (as you can see from example).
So “general purpose” == JSON, in your view? That’s oddly specific for a supposed “general purpose” criterion. You must think that C, C++ and Java are very poor general purpose languages then.
In general, it’s a fairly antagonistic approach to go from “I have some specific complaints” to “this language is not good enough”. Why not just ask questions or raise issues about the specific things that bother you?
The printing of nested dicts is annoying and it would be great if someone made a PR to improve upon it.
If you want to view the results you are supposed to use JSON.print
julia> JSON.print(a)
{"slideshow":{"slides":[{"title":"Wake up to WonderWidgets!","type":"all"},{"items":["Why <em>WonderWidgets</em> are great","Who <em>buys</em> WonderWidgets"],"title":"Overview","type":"all"}],"author":"Yours Truly","title":"Sample Slide Show","date":"date of publication"}}
Why “general purpose” requires builtin JSON? It make sense to me, if stdlib includes math, but make no sense to me with JSON, cuz what if I totally don’t want to use JSON? But you can’t get rid of math while programming…
This might be a nested dict printing issue? This is true indeed.
It should also perhaps be pointed out that you just downloaded a webpage in one line of Julia code and then parsed it as JSON in another line. And all of the code to implement that is written in Julia. Seems like proof positive that it’s a general purpose language.
Sorry for antagonistic approach. What I’m trying to say is that Julia has really strong support for arrays, but very poor support for dicts. Lists and dicts I think are equally important data container types.
How all this relates to JSON, is that JSON is ubiquitous and very important not as JSON serialization format, but as data model. So JSON data model has very important data types: dicts, arrays and scalars. Many serialization formats use same data model as JSON, this data model is essential for web development.
I will try to list some issues I see:
Why reinvent syntax how dicts are defined? I think {"a": {"b": "c"}} is the de facto standard. Julia has special syntax for arrays, but for equally important dict type it uses Dict("a"=>Dict("b"=>"c")) - a custom invention, looks a bit similar to PHP.
Default dict representation in REPL is unreadable.
There is no way to serialize/deserialize JSON-like data model consisting of dicts, lists and scalars to any serialization formats (json, yaml, toml).
Dicts are not ordered by default. This is a mistake finally fixed by Python.
There is no way to convert things like struct to Dict.
I like, that in Python, dicts are essential part of language and dicts are everywhere and has really good support, JSON like syntax, serialization, conversion from objects to dicts, dict magic and etc.
In a modern world, I think C/C++ are no longer general purpose, they are system languages.
I would probably could find more issues about JSON-like data model, but think is is clear, that this is not first-class citizen in Julia, making much less attractive for a huge are like web development where I coming from.
Of course everything could be done in one way or another, using third party libraries and macros. But clearly, JSON-like data model does not have some much attention as vectors and matrices.
Nested dicts are shown a bit verbose because Julia has properly typed containers and their types are shown, which is not the case for e.g. Python.
Do you mean built into the language itself? Otherwise, JSON.jl or TOML.jl does it. The package manager of Julia uses TOML for example.
There is a PR for making dicts ordered by default but it hasn’t been important enough compared to other things to get a lot of attention. The language is free to make it ordered at any point since right now, the order is undefined.
Again, you mean baked into the language? Again, there are packages that do this (with no performance penalty compared to if it was built in).
The whole point about being a general purpose language is that you can write code that do general purpose things and there is no need for all the features you want to be built in.
Also, your comments here are extremely specific considering your title “Is Julia a general purpose language?”. Julia is definitely general purpose as shown by webservers, games, apps etc written in it. The printing of nested dicts doesn’t really change that.
Dict( fld => getfield(obj,fld) for fld in fieldnames(obj) )
But I don’t think this should be needed very often; in general field names are implementation details of objects. Structs aren’t necessarily dictionaries; they might implement any sort of abstraction. If you have structs that are dictionaries, named tuples might work better.
Also, your comments here are extremely specific considering your title “Is Julia a general purpose language?”.
I agree, my title is a bit too strong. And my interpretation of what is general purpose language is influenced by Python. So I see C/C++ as not general purpose, but as system languages, while Wikipedia says they are general purpose. Sorry for my ignorance.
If Julia has build in linear algebra, so why thinks like data serialization is not built in, like in python? I just don’t understand if Julia has batteries included type standard library or just bare bones standard library.