What are the basic structural aspects that should exist in Julia code I am writing? I will link some other languages' implementation of this for reference.
I am looking for officially sanctioned components for the language itself, not one's opinion on best practices.
Basic structure of a C program
Basic structure of a Java program
Structs are used to create types. It is recommended to start type names with a capital letter. In this case Point instead of point . By not specifying a type parameter, you may end up with a mix of datatypes. Consider specifying `struct Point{T} so that the point coordinates are either all integers or all floats.
Julia is a high-level, dynamic programming language, designed to give users the speed of C/C++ while remaining as easy to use as Python. This means that developers can solve problems faster and more effectively. Julia is great for computational complex problems.
Base is a module which defines many of the functions, types and macros used in the Julia language. You can view the files for everything it contains here or call whos(Base) to print a list.
The Julia standard libraries, including Base, are implemented in Julia. Julia is implemented mostly in C, with a little bit of C++ for LLVM code-gen, and FemtoLisp for the lowering and the parser.
First off, if you are new to Julia and the structure of writing a program therein, I suggest you check out the Official Julia Docs for a great explanation as to how to get started writing code in Julia.
If you are coming from a language like Java and read the documentation linked above, you may be a little confused as to where the docs on the structure of a Julia program are. To my understanding, that doc does not exist for a few reasons.
Julia as a language imposes very little on you as the programmer. This can lead to a bit of uncertainty and doubt with all of the newfound freedom. There are some basic structures that should be followed, despite the flexibility the language provides:
using
and import
statements are generally made at the very top of the file. It's also worth checking out the Julia Style Guide for things like:
Write functions, not just scripts: Writing code as a series of steps at the top level is a quick way to get started solving a problem, but you should try to divide a program into functions as soon as possible. Functions are more reusable and testable, and clarify what steps are being done and what their inputs and outputs are. Furthermore, code inside functions tends to run much faster than the top-level code, due to how Julia's compiler works.
In general, Julia is flexible. There are very few things that you have to include in your program.
It's important to designate the difference between writing a simple Julia script and creating a project in Julia.
While there are limited structural suggestions for creating a simple script, there are a number of suggestions related to how one can structure a Julia Project. In fact, many of these aspects are built into Julia itself! You can find out more about creating Julia Projects (which should have a similar if not the same structure as Julia packages) here.
Note: If you are trying to find the structure of a Package in Julia, a great resource would be PackageTemplate.jl.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With