I have to admit that after having used the new syntax for a while now, I’m not 
a fan at all. It feels like I’m thrown back to my old C# days…

 

I’m sure there was an excellent reason for this change, but I couldn’t find the 
relevant issue on github. If someone has the relevant link handy, I would 
appreciate the link.

 

Thanks,

David

 

From: julia-users@googlegroups.com [mailto:julia-users@googlegroups.com] On 
Behalf Of Mike Innes
Sent: Wednesday, September 2, 2015 9:55 AM
To: julia-users <julia-users@googlegroups.com>
Subject: Re: [julia-users] The new Dict syntax in 0.4 is very verbose

 

You might consider creating an alias, e.g.

 

d(xs...) = Dict{Any, Any}(xs...)

 

d(:a=>1, :b=>2)

 

It's not as nice, but it's not awful either. You could also do

 

macro d(xs...)

  for x in xs

    @assert x.head == :(=>)

    isa(x.args[1], Symbol) && (x.args[1] = Expr(:quote, x.args[1]))

  end

  :(Dict{Any, Any}($(map(esc, xs)...)))

end

 

@d(a=>1, b=>2)

 

Saving on the colons might just be enough to make the lack of literal syntax 
less painful.

 

On Wed, 2 Sep 2015 at 18:45 Michael Francis <mdcfran...@gmail.com 
<mailto:mdcfran...@gmail.com> > wrote:

With the change to 0.4 happening soon I'm finding the the new Dict syntax in 
0.4 (removal of {}, []) is extremely verbose.

 

I find myself interfacing with JSON APIs frequently, for example a 
configuration dictionary :

 

data = {
        :displayrows => 20,
        :cols => [
                    { :col => "l1" },
                    { :col => "l2" },
                    { :col => "l3" },
                    { :col => "num", :display => true },
                    { :col => "sum", :display => true, :conf => { :style => 1, 
:func => { :method => "sum", :col => "num"  } } }
                ]  
       ... # Lots more   
    }

 

becomes -

 

data = Dict{Symbol,Any}(
        :displayrows => 20,
        :cols => [
                    Dict{Symbol,Any}( :col => "l1" ),
                    Dict{Symbol,Any}( :col => "l2" ),
                    Dict{Symbol,Any}( :col => "l3"   ),
                    Dict{Symbol,Any}( :col => "num", :display => true ),
                    Dict{Symbol,Any}( :col => "sum", :display => true, :conf => 
Dict{Symbol,Any}( :style => 1, 
                                                                    :func => 
Dict{Symbol,Any}( :method => "sum", :col => "num" ) ) )
                ]  
       ... # Lots more
    )

 

This feels like asking a person using arrays to write the following

 

Array{Int64,2}( Vector{Int64}( 1,2,3), Vector{Int64}( 4,5,6) )

 

vs

 

[ [ 1, 2, 3] [ 4,5,6 ] ]

 

Can we please reconsider ?

 

Reply via email to