Is Julia a general purpose language?

json

#1

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:

  1. Julia has huge set of math functions, but there is no build in JSON support.
  2. Julia has excellent features to build and display vectors and matrices, but support for dicts is really disappointing.
  3. Dicts does not look like JSON.
  4. Default dict representation printent in REPL is unreadable (as you can see from example).

#2

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.


#3

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"}}

#4

What features are you missing?


#5

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.


#6

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.


#7

or

julia> JSON.print(j, 2)
{
  "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"
  }
}

#8

Hardly any language (except JS itself?) has JSON built in. You need to load a package to use it in e.g. python as well.


#9

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:

  1. 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.
  2. Default dict representation in REPL is unreadable.
  3. There is no way to serialize/deserialize JSON-like data model consisting of dicts, lists and scalars to any serialization formats (json, yaml, toml).
  4. Dicts are not ordered by default. This is a mistake finally fixed by Python.
  5. 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.


#10

I did that using two third party libraries, one of them stating, that it was never tested in production.


#11

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.


#12

No, it is not:

julia> Dict(1=>2, 2=>3, 4 => "foo")
Dict{Int64,Any} with 3 entries:
  4 => "foo"
  2 => 3
  1 => 2

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.


#13

I don’t understand this — doesn’t the JSON package do that?


#14

What Julia has for vectors and matrices I would same that https://jsonnet.org/ is something similar for json-like data model.


#15

There is no build-in serialization for mentioned formats.


#16

Why are you fixated on things being built-in?


#17
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.


#18

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.


#19

FWIW, Julia is more like Python than C++ in how it feels. More closer to C++ in terms of performance though :wink:


#20

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.