Good way to organize constants?

86 views
Skip to first unread message

FANG Colin

unread,
Nov 16, 2016, 7:18:35 AM11/16/16
to julia-users
Say, I have a few constants

const VTYPE_BINARY = 'B'
const VTYPE_INTEGER = 'I'
const VTYPE_CONTINUOUS = 'C'

What's a good way to have a namespace on it?

So that I can use Vtype.BINARY, Vtype.INTEGER, Vtype.CONTINUOUS

Should I put those in a separator module? or create a type and get an instance of it?

module Vtype
    const ....
end

immutable Vtype
    BINARY::Char
    INTEGER::Char
    CONTINUOUS::Char
end

const vtype = Vtype('B','I','C')?

Mauro

unread,
Nov 16, 2016, 7:48:14 AM11/16/16
to julia...@googlegroups.com
Checkout my package: https://github.com/mauro3/Parameters.jl. Maybe of
use.

Milan Bouchet-Valat

unread,
Nov 16, 2016, 8:31:42 AM11/16/16
to julia...@googlegroups.com
Putting it in a module is fine if you want to regroup these under the
same namespace. That's the standard practice with enums too (when
constants correspond to integer codes, which isn't the case here).


Regards

FANG Colin

unread,
Nov 16, 2016, 8:38:15 AM11/16/16
to julia...@googlegroups.com
Is there going to be overhead if I create constant group modules and use them via module_name.abc?

Milan Bouchet-Valat

unread,
Nov 16, 2016, 9:55:06 AM11/16/16
to julia...@googlegroups.com
Le mercredi 16 novembre 2016 à 13:38 +0000, FANG Colin a écrit :
> Is there going to be overhead if I create constant group modules and
> use them via module_name.abc?
Not that I know of.


Regards
Reply all
Reply to author
Forward
0 new messages