-
Notifications
You must be signed in to change notification settings - Fork 80
Syntax and coding style
Paolo Angeli edited this page Sep 22, 2019
·
27 revisions
At the very first beginning, the Jay language was somewhat similar to C with some funny constructs. Now that is more mature a lot of weird syntaxes started to appear so as a first impact you can get a bit confused.
// Simple one line comment
/* Multi line comment */
/* A strange /* nested */ comment */
RED :: 0x04586;
PI :: 3.14;
PLAYER :: "Unnamed";
Style: prefer using all upper case naming convention;
// Unassigned declarations will be initialized to default values unless specified
counter : int; // Signed 32 bit integer
key : s64; // Signed 64 bit integer
flags : u8; // Unsigned 8 bit integer
// Declarations and assignements
mode :- 10; // Type int automatically inferred by the compiler
area : float - r * r * PI; // Single precision 32 bit floating point
temp : string - "Convert to:"; // A standard native string
Style: Prefer using all lower case naming convention;
// Define a procedure with arguments
do_something :: (what: string){
printf("I'm doing: %", what);
}
// Another procedure without arguments
main_loop :: (){
while !should_exit {
get_user_input();
simulate();
render();
post_process();
}
}
Style: prefer using snake case naming convention for all the compound terms
// Define a simple function
square :: (val: float) -> float {
return val * val;
}
// Define a function with multiple results
circle_area:: (radious: float) -> float, bool {
return square(radious) * PI, radious > 0 ;
}
// define a new struct type
Spring :: struct {
relaxed_length : float; // millimeters
theta : float; // N/m
force : float; // N
current_length : float; // mm
}
Style: prefer using capitalization for the first letter of the user-defined type.
// declare a new spring allocate it on the stack and initialize to zeroes
a_spring : Spring;
// use dot notation to access the fields
a_spring.relaxed_length - 100;
// or use the using keyword
using a_spring {
theta - 1000.0;
force - 25;
current_length - theta / relaxed_length * force + relaxed_lenght;
}
These documents were verified using Grammarly free browser plugin for Chrome. Please use some spell checker before submitting new content.
- Variables and assignments
- Language data types
- Simple user-defined data types
- Expressions and operators
- Type-casting
- Pointers
- Declarations
- Arguments / Parameters
- Return values
- Overloading / Polymorhism
- Advanced features
- Lambdas
- Arrays
- Strings
- Composition of Structs
- Metaprogramming
- Templates / Generics