7

I recently started programming in Julia for research purposes. Going through it I started loving the syntax, I positively experienced the community here in SO and now I am thinking about porting some code from other programming languages.

Working with highly computational expensive forecasting models, it would be nice to have them all in a powerful modern language as Julia.

I would like to create a project and I am wondering how I should design it. I am concerned both from a performance and a language perspective (i.e.: Would it be better to create modules – submodules – functions or something else would be preferred? Is it better off to use dictionaries or custom types?).

I have looked at different GitHub projects in my field, but I haven't really found a common standard. Therefore I am wondering: what is more in the spirit of the Julia language and philosophy?


EDIT:

It has been pointed out that this question might be too generic. Therefore, I would like to focus it on how it would be better structuring modules (i.e. separate modules for main functions and subroutines versus modules and submodules, etc.). I believe this would be enough for me to have a feel about what might be considered in the spirit of the Julia language and philosophy. Of course, additional examples and references are more than welcome.

merch
  • 945
  • 8
  • 19
  • 2
    This is a perfectly reasonable question, just like "how can I make my code more Pythonic?" is also a perfectly reasonable question. Unfortunately it's not a good _StackOverflow_ question, because it's not really concretely answerable, but an open-ended question about styles and patterns. – DSM Sep 29 '16 at 02:10
  • 3
    I've always thought the [Distributions](https://github.com/JuliaStats/Distributions.jl) package and [Distances](https://github.com/JuliaStats/Distances.jl) package are good examples of "Julian" packages... – Colin T Bowers Sep 29 '16 at 02:32
  • oh gawd, please don't let the term "Julian" propagate. Or "Juliaic" or "Julionic" or "Julianic" or "Julaic" or any of that nonsense. – Tasos Papastylianou Sep 29 '16 at 08:17
  • 2
    Though if you *must* now, as a native greek-speaking person I can tell you the correct term would be "Juliac". But don't use this either. It's bad and you should feel bad. – Tasos Papastylianou Sep 29 '16 at 08:22
  • I have changed Julian to Juliac @TasosPapastylianou – merch Sep 29 '16 at 11:42
  • 1
    NOOOOOOOOOOOOoooooooooooo............. – Tasos Papastylianou Sep 29 '16 at 12:25
  • @TasosPapastylianou I can paraphrase the term Juliac, to avoid creating a misleading word. What do you think would be more appropriate? – merch Sep 29 '16 at 12:35
  • @TasosPapastylianou "greek"? Probably Latin... :) – daycaster Sep 29 '16 at 13:47
  • 1
    I have never heard anyone use the word 'Juliac' like this before. 'Julian' is relatively common. I have no idea what being 'native greek' has to do with anything... – DNF Sep 29 '16 at 13:55
  • @DNF Juliac sounds more similar to Pythonic to me, what do you think? – merch Sep 29 '16 at 13:56
  • @merch Yes but so what? 'Europeac' also sounds more like 'Pythonic' than 'European' does. – DNF Sep 29 '16 at 13:59
  • 1
    @merch "in the spirit of the Julia language and philosophy" is fine. Dem no need no hip adjective to bling our rap. – Tasos Papastylianou Sep 29 '16 at 14:50
  • @DNF It's just etymology / linguistics. Being Greek means the correct declension is relatively obvious to me because it derives from and is built right into my language. "Julian" means "of Julia". "Juliac" (or Juliaic) means "pertaining to / characterised by Julia". Same with your Europe example: "European" means someone of / from Europe. The correct term for "characterised by Europe" would be "Europa(e)ic" ... but I guess it just didn't catch on in English. But the distinction shows clearly in its German cousin for instance: A European person: Europäer; A European product: Europäisch – Tasos Papastylianou Sep 30 '16 at 08:40
  • The equivalent for python would be "Pythonian" (e.g. a pythonian space, a space belonging to python), vs "Pythonic" (pythonic style / code, code characteristic to python). But in any case, language is fluid and sometimes it's just a matter of what term ends up being more buzzworthy and widespread. But hopefully the Julia community doesn't have any need for such buzzwords :p – Tasos Papastylianou Sep 30 '16 at 08:44
  • Well, in English, '-an' *also* means "pertaining to/characterized by". Such as in "The American way", which does not refer to a person. In English, "Julian" is in fact the correct term. And, it's not just a "buzzword", it's a useful brief term. Look at the monstrosity that is the current title of this question, and which could simply be replaced by "Julian". – DNF Sep 30 '16 at 08:48

1 Answers1

11

The most you'll find is that there is an "official" style-guide. The rest of the "Julian" style is ill-defined, but there are some ways to heuristically define it.

First of all, it means designing the software around multiple dispatch and the type system. A software which follows a Julian design philosophy usually won't be defining a bunch of functions like test_pumpkin and test_pineapple, instead it will use dispatches on test for types Pumpkin and Pineapple. This allows for clean/understandable code. It will break tasks up into small type-stable functions which will allow for good performance. It likely will also be written very generically, allowing the user to use items that are subtypes of AbstractArray or Number, and using the power of dispatch to allow their software to work on numbers they've never even heard of. (In this respect, custom types are recommended over dictionaries when you need performance. However, for a type you have to know all of the fields at the beginning, which means some things require dictionaries.)

A software which follows a Julian design philosophy may also implement a DSL (Domain-Specific Language) to allow a simpler interface to the user. Instead of requiring the user to conform to archaic standards derived from C/Fortran, or write large repetitive items and inputs, the package may provide macros to allow the user to more heuristically define the problem for the software to solve.

Other items which are part of the Julian design philosophy are up for much debate. Is proper Julia code devectorized? I would say no, and the loop fusing broadcast . is a powerful way to write MATLAB-style "vectorized" code and have it be perform like a devectorized loop. However, I have seen others prefer devectorized styles.

Also note that Julia is very different from something like Python where in Julia, you can essentially "build your own standard way of doing something". Since there's no performance penalty for functions/types declared in packages rather than Base, you can build your own Julia world if you want, using macros to define your own "function-like" objects, etc. I mean, you can re-create Java styles in Julia if you wanted.

Community
  • 1
  • 1
Chris Rackauckas
  • 18,645
  • 3
  • 50
  • 81
  • Thank you Chris, it helpful. What do you think is more efficient for designing a new package looking at the modular structure? I have seen that some GitHub projects are using two modules (main + utilities), while others prefer a module-submodules-functions structure. – merch Sep 29 '16 at 10:34
  • 1
    I think it really depends on what you need in terms of scoping. If you want to be re-using some names, put them in different modules for sure. If your names aren't overlapping, I don't really see a point. A lot of Julia projects I've looked at an learned from just use one big module, though I have seen some that use multiple modules. One good reason to use multiple modules is to allow users to export different sets of functionality independently. – Chris Rackauckas Sep 29 '16 at 15:24