University of Nebraska Lincoln Class Meeting 1.6 Slide 1/13
Overview of A general purpose programming language Created by Guido van Rossum Overarching design goal was orthogonality Automatic memory management Support for OO programming (and other paradigms) Less cluttered grammar Many libraries and frameworks to support app development Slide 2/13
Overview of Kivy Open-source library for user interface development Provides support for mouse, keyboard, and other input devices Implements the main loop of an application Similar to the FX library for Kv language describes the user interface and user interactions Slide 3/13
Comments // A comment # A comment A comment begins with a double slash A comment begins with the hash character Slide 4/13
Naming Conventions class MyClass {... } class MyClass(object): makemove(...) make_move(...) firstnumber = 4; first_number = 4 Camel case for classes, methods, and variable names. Camel case for classes but underscores for methods and variable names. Slide 5/13
Variables int length = 5; length = 5 Names are bound to a type No type declaration names at compile time (i.e., static are bound to a type at run typing) time (i.e., dynamic typing) Slide 6/13
Literals true, false Boolean literals are lowercase True, False Boolean literals are uppercase Slide 7/13
Operators <, >, <=, >= <, >, <=, >= +, -, *, % +, -, *, % / /, //!, &&, not, and, or No distinction between floating-point and integer division Different operators for floating-point and integer division Logical operators written in symbols Logical operators written in words Slide 8/13
Assignment Statements x = 1; x = 1 x += 1; x += 1 ++x; x += 1 Semicolons terminate statements Line breaks terminate statements Increment and decrement operators available Increment and decrement operators not available Slide 9/13
If Statements if (x < 0) { if x < 0: System.out.println("<"); print("<") } else if (x == 0) { elif x == 0: System.out.println("="); print( = ) } If statements use colons, indentation, If statements use braces and the abbreviated spelling elif Strings can be written Strings are written in double in single or double quotes quotes Slide 10/13
Methods void foo(int number) { x = x + y; } Functions are not marked by a keyword Indentation is only used to improve human readability Types are specified in signatures Functions must be inside a class def foo(number): x = x + y Functions are marked by def Indentation level is significant Types are not specified in signatures Functions may exist outside of a class Slide 11/13
Methods void addx(int x) { def add_x(self, x): } pass The this parameter is The self parameter is implicit explicit and comes first Empty blocks simply pass is a placeholder for an contain no code empty block Slide 12/13
Field Access class NimApp { class NimApp(object): public int x;...... void computex() { def compute_x(self): x += 5; self.x += 5 } Instance fields must be Instance fields are not declared declared Instance fields can be Instance fields must be referenced without the this referenced with the self keyword keyword Slide 13/13