JuliaPhysics / PeriodicTable.jl

Periodic Table for Julians! :fire:
Other
111 stars 26 forks source link

return a typed struct, not a dictionary #1

Closed stevengj closed 6 years ago

stevengj commented 6 years ago

Instead of a Dict{String,Any}, it seems like it would be better to return a custom Element type with typed fields like number, name, and so on.

The basic reason for this is that defining an Element type will provide the information about the fields and their types to the Julia compiler. Otherwise you are forcing any computation that uses element data to be type-unstable.

stevengj commented 6 years ago

Oh, I was a little confused by your example, showing the ele.data dictionary. It seems that you have both a struct and a dictionary. Why keep the data dictionary around at all? Seems better to store the information in only one way.

Also, I notice that all of your element fields are untyped. Better to give them all concrete types.

stevengj commented 6 years ago

(You might want a mutable struct so that returning it doesn't need to make a copy, and can just return a pointer.)