Contenu connexe
Similaire à Introduction to Eqela development (20)
Introduction to Eqela development
- 2. Copyright © 2012 Job and Esther Technologies, Inc.
(1) INTRODUCTION
Industry overview
Cross platform development
Introduction to Eqela
Eqela syntax / language features
- 3. Copyright © 2012 Job and Esther Technologies, Inc.
Our world
(.. And all platforms come in various versions)
- 4. Copyright © 2012 Job and Esther Technologies, Inc.
From an application development perspective ..
While targeting only the most popular
target platforms, a developer will need to
work with 10-20 different operating system
platforms/versions, at least 3-5 different
programming languages, each with
different API libraries.
- 5. Copyright © 2012 Job and Esther Technologies, Inc.
Big problem in the industry
All software developers need to
deal with this one way or the
other
- 7. Copyright © 2012 Job and Esther Technologies, Inc.
Usual solutions
(1) Work only on one platform
(2) Create the same application several
times (once per platform)
(3) Do “cross platform development”
- 8. Copyright © 2012 Job and Esther Technologies, Inc.
Traditional ways to do cross platform development
(1) The “scripted” approach
(Adobe Air / Flex, Appcelerator, Corona, RhoMobile, ..)
(2) The “bytecode” approach
(MoSync, Mono)
(3) The “C++” approach
(Marmalade, Qt, WxWidgets, Unity)
(4) The “embed a web browser” approach
(PhoneGap)
(5) HTML5
- 9. Copyright © 2012 Job and Esther Technologies, Inc.
Five different cross
platform development
approaches
- 10. Copyright © 2012 Job and Esther Technologies, Inc.
#1: The “scripted” approach
Source code
In a scripting
language
Development
tool
Unmodified
Source code
+
Interpreter /
Virtual machine
For iOS
Unmodified
Source code
+
Interpreter /
Virtual machine
For Android
Run in
browser
Android
application
iOS
application
(JavaScript,(JavaScript,
Lua, Ruby, ..)Lua, Ruby, ..)
(Adobe Air / Flex, Appcelerator, Corona, RhoMobile, ..)
Runtime /
Virtual
machine
- 11. Copyright © 2012 Job and Esther Technologies, Inc.
The “scripted” approach: Architecture
Operating system
Language interpreter / runtime
APIs and libraries Application code
- 12. Copyright © 2012 Job and Esther Technologies, Inc.
The “scripted” approach: Architecture
Operating system
Language interpreter / runtime
APIs and libraries Application code Makes application
Installers much bigger
Increases memory
usage
Reduces runtime
Performance
Due to this approach being very popular, many consider
cross platform development to be slow, high in memory use,
and producing bigger installers.
Applications can only
Access selected
Parts of the native API
- 13. Copyright © 2012 Job and Esther Technologies, Inc.
#2: The “bytecode” approach
Source
code
Bytecode
Compiler
Android
application
Run in
browser
Class
Library
(MoSync, Mono)
iOS
application
Windows
Phone
application
Very similar to the “scripted” approach,
with the added bytecode compilation step.
Bytecode
Development
Tool
Runtime /
Virtual
machine
- 14. Copyright © 2012 Job and Esther Technologies, Inc.
The “bytecode” approach: Architecture
Operating system
Bytecode interpreter / runtime
APIs and libraries Application code Makes application
Installers much bigger
Increases memory
usage
Reduces runtime
Performance
Due to its similarity with the “interpreted” approach, the
benefits and disadvantages are very similar
Applications can only
Access selected
Parts of the native API
- 15. Copyright © 2012 Job and Esther Technologies, Inc.
#3: The “C++” approach
Source code
In a specific
Language
SDK /
compiler
Run in
browser
Android
application
iOS
application
(C++)(C++)
Cross
Platform
Class library
In the specific
language
(C++)(C++)
(Marmalade, Qt, WxWidgets, Unity)
BlackBerry
application
Windows
Phone
application
+ Truly native (100%)
+ High performance
- Limited platform support
(not really cross platform)
- 16. Copyright © 2012 Job and Esther Technologies, Inc.
#4: The “embed a web browser” approach
Source
Code in
HTML, CSS,
JavaScript
The
tool
Libraries C source code
That opens a
Browser and
Displays the
program
Java source code
That opens a
Browser and
Displays the
program
Android
SDK
Android
application
iOS
SDK
iOS
application
Run in
browser
(PhoneGap, AppGyver)
- Very poor performance
- Suitable for only “web-style” apps
- Limited access to platform APIs
- Application source code can be easily retrieved
+ Easy way to convert existing websites to
“native apps”
- 17. Copyright © 2012 Job and Esther Technologies, Inc.
#5: HTML5
+ Commonly known skillset (HTML, CSS, JavaScript)
+ Very popular, many Internet resources available
- Unfinished standard
- Fragmented, non-compatible implementations
- Extremely poor performance on mobile
- The language is poorly suited for large programs
- Applications are inherently “open source”
- 18. Copyright © 2012 Job and Esther Technologies, Inc.
Common issues
Large installer size
Excessive memory use
Low performance
Limited API access
- 19. Copyright © 2012 Job and Esther Technologies, Inc.
Cross platform development tool ..
.. Based on programming language conversion
technology
- 20. Copyright © 2012 Job and Esther Technologies, Inc.
Eqela video
http://www.youtube.com/watch?v=WcWf7SXGBv0
- 21. Copyright © 2012 Job and Esther Technologies, Inc.
How it works
Source
Code
(Eqela)
Eqela
Compiler
Libraries C
source
code
Java
source
code
Javascript
code
Android
SDK
Android
application
iOS
SDK
iOS
application
Run in
browser
- 22. Copyright © 2012 Job and Esther Technologies, Inc.
The technical benefits ..
Small installer size
Optimal memory use
Native performance
No API access limitations
- 23. Copyright © 2012 Job and Esther Technologies, Inc.
How it works: A sample application
class Main : LayerWidget
{
public void initialize() {
base.initialize();
add(LabelWidget.instance().set_text(“Hello World”));
}
}
Main.eq
Eqela
Compiler
LayerWidget,
LabelWidget
Main.java,
LayerWidget.java,
LabelWidget.java
Android
SDK
Android
application
- 24. Copyright © 2012 Job and Esther Technologies, Inc.
100% native
Main.eq
Eqela
Compiler
LayerWidget,
LabelWidget
Main.java,
LayerWidget.java,
LabelWidget.java
Android
SDK
Android
application
Only native code → “100% native”
No virtual machine added
No interpreter added
- 25. Copyright © 2012 Job and Esther Technologies, Inc.
Main.eq → Main.java
class Main : LayerWidget
{
public void initialize() {
base.initialize();
add(LabelWidget.instance().set_text(“Hello World”));
}
}
package mk.test;
public class Main extends eq.gui.LayerWidget
{
@Override
public void initialize() {
super.initialize();
((eq.gui.ContainerWidget)this).add(((eq.gui.Widget)eq.widget.LabelWidge
t.eq_widget_LabelWidget_instance().set_text(eq.api.StringStatic.eq_api_
StringStatic_for_strptr("Hello world"))));
}
public Main() {
}
}
(EQELA)
(JAVA)
- 27. Copyright © 2012 Job and Esther Technologies, Inc.
Eqela is ..
(1) A modern, object oriented
programming language
Powerful, object oriented, easy to
use, efficient to program
Designed to fit the needs of the
different target platforms
Part of the C syntax family
Instantly familiar to anyone with
experience in C, C++, Java, C#,
JavaScript
- 28. Copyright © 2012 Job and Esther Technologies, Inc.
Eqela is ..
(2) An advanced compiler /
programming language translator
Converts the source programming
language (Eqela) to other languages
(Java, C#, C, JavaScript, ..)
Generates project files / directories
be used by the development tools of
the various target platforms
Pulls in libraries to link with the
application
- 29. Copyright © 2012 Job and Esther Technologies, Inc.
Eqela is ..
(3) An application framework
A cross-platform API that works
across programming languages
All common functionalities, such as
file I/O, networking, threading, data
structures, ..
Same API on any language and
operating system
- 30. Copyright © 2012 Job and Esther Technologies, Inc.
Eqela is ..
(4) A cross platform graphical
user interface (GUI) API
A rich set of user interface
components and controls
A powerful graphics rendering API for
development of custom controls
Works the same way across all
platforms (mobile, desktop, web)
- 31. Copyright © 2012 Job and Esther Technologies, Inc.
Eqela is ..
(5) A development tool / environment
- 32. Copyright © 2012 Job and Esther Technologies, Inc.
Eqela is ..
Programming language
Compiler
Application framework
GUI toolkit
Development tool / environment
- 34. Copyright © 2012 Job and Esther Technologies, Inc.
ONLINE / WEB DOWNLOAD / INSTALL
EQELA LIVE
Target Android / HMTL5
Free of charge
No installation required
EQELA “FULL VERSION”
All supported platforms
Payment per platform
Installed per workstation
The different editions
- 35. Copyright © 2012 Job and Esther Technologies, Inc.
Supported platforms
Android, BlackBerry 10, BlackBerry 5/6/7, HTML5,
Apple iOS, J2ME, Linux, Mac OS X, Symbian,
Windows, Windows Phone
- 36. Copyright © 2012 Job and Esther Technologies, Inc.
Source files and modules
Eqela source file extension: “.eq”
Generally file is named after the class, eg. “Main.eq”
for class “Main” (convention only, not enforced)
Usually one class per file (also convention)
Directory name names the module and acts as the
“application id”
- 37. Copyright © 2012 Job and Esther Technologies, Inc.
The Eqela syntax
Belongs to the “C” syntax family:
C, C++, Objective-C, Java, C#, PHP, ..
- 38. Copyright © 2012 Job and Esther Technologies, Inc.
Eqela syntax / language features
- 39. Copyright © 2012 Job and Esther Technologies, Inc.
Eqela is a fully object oriented,
class based programming
language
- 40. Copyright © 2012 Job and Esther Technologies, Inc.
Class declarations
[modifiers] class [classname] : [basetypes]
{
[implementation]
}
public class MySampleClass : SuperClass
{
public void do_something() {
// more code here
}
}
The base class and interfaces may be mixed in the [basetypes]
section of the class declaration in any order.
- 41. Copyright © 2012 Job and Esther Technologies, Inc.
Class declarations
Class declarations can include these components:
1.Modifiers: public, private (default) or fundamental.
public – the class will be exported in the module's API
private – the class is only available for use internally
within the module
fundamental – the class will not have any base class
2.The class name, by convention in CamelCase
3.The base class (superclass) and a comma-separated list of
interfaces implemented by the class may be mixed in the
[basetypes] section of the class declaration in any order.
4.The class body surrounded by braces, { }.
- 42. Copyright © 2012 Job and Esther Technologies, Inc.
Automatic base classing
class MyClass
{
// field, constructor, and
// method declarations
}
class MyClass : Object
{
// field, constructor, and
// method declarations
}
=
fundamental class MyClass
{
// field, constructor, and
// method declarations
}
!=
- 43. Copyright © 2012 Job and Esther Technologies, Inc.
There can be no program
without a class
(no standalone functions)
- 44. Copyright © 2012 Job and Esther Technologies, Inc.
Comments
// This is a valid comment
/* This is also a valid comment */
/* This
* comment
* spans
* multiple
* lines.
*/
Comments are described in a way familiar with
many languages, using either the "//" notation or
the "/*" .. "*/" method.
- 45. Copyright © 2012 Job and Esther Technologies, Inc.
Data types
Different kinds of data types:
Primitive types
Object types
(Strings)
- 46. Copyright © 2012 Job and Esther Technologies, Inc.
Primitive types
● Built in to the language as basic building blocks, and
cannot be extended by the programmer. Passed by
value in method calls.
● strptr, ptr, void, double, bool, int, long, byte
strptr var_name = “abc”.to_strptr();
ptr var_name = null;
double var_name = 123.45;
bool var_name = true;
int var_name = 100000;
long var_name = 100000;
byte var_name = 100;
void //refers to no data type at all
- 47. Copyright © 2012 Job and Esther Technologies, Inc.
Object types
Objects = Instances of classes
Passed by reference in method calls
class MyClass
{
public int method() {
return(10);
}
}
var o = new MyClass();
- 48. Copyright © 2012 Job and Esther Technologies, Inc.
Strings
String literal = "This is a string literal";
var str = "Another string literal";
if(str is String) {
; // This is true
}
Eqela API provides a “String” class that offers a
string implementation as an object (object type).
String literals are automatically assigned as
instances of the “String” object, not as “strptr”
variables.
- 49. Copyright © 2012 Job and Esther Technologies, Inc.
String operations
// assignment
var str1 = "String 1";
// concatenation
var str2 = str1.append(" + More stuff");
// console output
Log.message(str2); // prints out "String 1 + More stuff"
// comparison
if(str1.equals(str2)) {
; // not true
}
// comparison with a literal
if("String 1".equals(str1)) {
; // true
}
- 50. Copyright © 2012 Job and Esther Technologies, Inc.
Constructing strings
var sb = StringBuffer.create().
sb.append("First");
sb.append_c(' ');
sb.append("Second");
Log.message(sb.to_string()); // prints "First Second"
Normal String objects are immutable
StringBuffer class is provided as part of the API
to efficiently construct strings
- 51. Copyright © 2012 Job and Esther Technologies, Inc.
Class constructor
What is a “constructor”?
- 52. Copyright © 2012 Job and Esther Technologies, Inc.
A method with the same name as the class name
Has no return type
A class can only have one constructor function, and the
constructor is not allowed to have any parameters.
public MyClass
{
public MyClass() {
; // implementation
}
}
Class constructor
- 53. Copyright © 2012 Job and Esther Technologies, Inc.
Supplying object parameters upon creation
public MyClass
{
private int variable = 0;
public MyClass() {
}
public static MyClass create(int value) {
var v = new MyClass();
v.variable = value;
return(v);
}
}
var o = MyClass.create(10);
(1) By using static creation methods
- 54. Copyright © 2012 Job and Esther Technologies, Inc.
public MyClass
{
property int variable = 0;
public MyClass() {
}
}
var o = new MyClass().set_variable(10);
Supplying object parameters upon creation
(2) By using properties
- 55. Copyright © 2012 Job and Esther Technologies, Inc.
Class destructor
What is a “destructor”?
- 56. Copyright © 2012 Job and Esther Technologies, Inc.
public MyClass
{
~Myclass() {
; // actions here
}
}
As is usual in all modern languages with
automatic memory management, it is highly
discouraged to use destructors in Eqela
applications. Generally the only well-known
acceptable use for a destructor is to deallocate
resources allocated manually.
Class destructor
- 57. Copyright © 2012 Job and Esther Technologies, Inc.
Member variables
[modifiers] [type] [variablename] = [initializer];
class MyClass
{
int number = 10;
public static MyClass second;
private MyClass third = null;
}
Modifiers : "private", "public", "static"
Initializer is optional
- 58. Copyright © 2012 Job and Esther Technologies, Inc.
Declaring methods
public int SomeMethod(int int_value, bool bool_value) {
// method body
return(10);
}
modifiers return
type
method
name
parameter
list
If the return type is NOT void, the method must
end in a “return” line
- 59. Copyright © 2012 Job and Esther Technologies, Inc.
Virtual methods and overriding
class BaseClass
{
public virtual void hello() {
Log.message("hello 1");
}
}
class DerivedClass : BaseClass
{
public override void hello() {
Log.message("Hello enhanced!");
}
}
If a method is declared with modifier "virtual", it becomes
a virtual function.
To override a method in a subclass, it should be declared
using the "override" modifier
- 60. Copyright © 2012 Job and Esther Technologies, Inc.
Method hiding
Eqela does NOT allow method hiding
If a method is declared in a base class, and it is not virtual, no
method of the same name may be declared in any of the
subclasses, even if the parameters would differ.
- 61. Copyright © 2012 Job and Esther Technologies, Inc.
Static methods
class MyClass
{
public static void hello() {
Log.message("MyClass hello");
}
}
class SecondClass
{
public void method() {
var mc = new MyClass();
mc.hello(); // not right
MyClass.hello(); // the correct way
}
}
Called by the name of the class they are
associated with, not through an object instance
- 62. Copyright © 2012 Job and Esther Technologies, Inc.
Abstract methods
What is an “abstract method”?
- 63. Copyright © 2012 Job and Esther Technologies, Inc.
Methods that have a method signature but no
implementation
Declared using the modifier "abstract“
If no "abstract" modifier is present, but method body is missing,
the "abstract" keyword is automatically assumed
No "override" keyword is required to override abstract methods
interface MyInterface
{
public void first_method();
public abstract void second_method();
}
Abstract methods
- 65. Copyright © 2012 Job and Esther Technologies, Inc.
Interface
interface MyInterface
{
public void method1();
public int method2();
}
A group of related methods with empty bodies
Defines a standard and public way of specifying
the behavior of the class (defines a contract)
Declared using the interface keyword
- 66. Copyright © 2012 Job and Esther Technologies, Inc.
Interfaces
To use an interface, you must implement that interface in
a class
Implementing an interface
Implement multiple interfaces
class MyClass : MyInterface
{
// class body
}
class MyClass : MyInterface, MyOtherInterface
{
// class body
}
- 67. Copyright © 2012 Job and Esther Technologies, Inc.
Prerequisites
In Eqela, an interface may not "inherit" another
interface, but it may instead have "prerequisites",
through which roughly the same functionality is
achieved
- 68. Copyright © 2012 Job and Esther Technologies, Inc.
Multiple inheritance
Multiple inheritance is not allowed – but
implementing multiple interfaces IS allowed
- 69. Copyright © 2012 Job and Esther Technologies, Inc.
Legal interface usage
interface First
{
public void method1();
}
interface Second : First
{
public void method2();
}
class MyClass : Second, First
{
public void method1() {
}
public void method2() {
}
}
- 70. Copyright © 2012 Job and Esther Technologies, Inc.
Illegal interface usage
interface First
{
public void method1();
}
interface Second : First
{
public void method2();
}
class MyClass : Second
{
public void method1() {
}
public void method2() {
}
}
- 71. Copyright © 2012 Job and Esther Technologies, Inc.
Other language features ..
- 72. Copyright © 2012 Job and Esther Technologies, Inc.
Operators and expressions
Group Operator
Unary -, !, ++, --
Logical binary ||, &&
Comparative binary ==, !=, <, <=, >, >=, is
Operative binary +, -, *, /, %
int a = 10 + 5;
int b = a / 10;
If(a == 15 || b == 7) {
}
if(a == 15 && b == 7) {
}
if(a != b) {
}
- 73. Copyright © 2012 Job and Esther Technologies, Inc.
Type casting
What is the meaning of “type casting”?
- 74. Copyright © 2012 Job and Esther Technologies, Inc.
Type casting
Static type casting
One data type can be cast into another in a fairly liberal
manner by using the "(typename)" notation.
(Fast but may lead to runtime errors)
Dynamic type casting
Uses the “as” operator to cast one data type to another.
(Slightly slower than static type casting, due to extra checking involved, but a much safer
way)
double n = 100.43;
int ni = (int)n;
var x = new MyClass();
var y = (MyOtherClass)x;
var x = new MyClass();
var y = x as MyOtherClass; // will be null if not a subclass of MyOtherClass
- 75. Copyright © 2012 Job and Esther Technologies, Inc.
Control structures
If .. Else
While
Do .. While
For
Foreach
Switch
- 76. Copyright © 2012 Job and Esther Technologies, Inc.
If .. Else
if(condition) {
; // execute if condition is true
}
else {
; // execute if condition is false
}
- 77. Copyright © 2012 Job and Esther Technologies, Inc.
While
while(condition) {
; // execute while condition is true
}
while(condition) {
if(want_to_stop) {
break;
}
continue;
; // will not reach here
}
While blocks can be interrupted
with the "break" statement or
restarted with the "continue"
statement
- 78. Copyright © 2012 Job and Esther Technologies, Inc.
Do .. While
do
{
; // execute here
}
while(condition);
- 79. Copyright © 2012 Job and Esther Technologies, Inc.
For
for(initializer; condition; execute_after) {
; // actions here
}
- 80. Copyright © 2012 Job and Esther Technologies, Inc.
Foreach
foreach(var variablename in collection) {
; // actions here
}
foreach(String variablename in collection) {
; // actions here
}
The data type of the loop
variable may be dynamically
assigned as above ("var"), or
it can be explicitly set by the
user.
- 81. Copyright © 2012 Job and Esther Technologies, Inc.
Switch
switch(expression) {
case value1: {
; // statements
}
case value2: {
; // statements
}
default: {
; // statements
}
}
•All "case" blocks must be
enclosed in curly braces "{"
and "}".
•Only one "case" statement is
allowed per block.
•No break statements are
required to terminate the case
blocks.
- 82. Copyright © 2012 Job and Esther Technologies, Inc.
Properties
class MyClass
{
property int myproperty;
}
class MyClass
{
int myproperty;
public MyClass set_myproperty(int v) {
myproperty = v;
return(this);
}
public int get_myproperty() {
return(myproperty);
}
}
- 83. Copyright © 2012 Job and Esther Technologies, Inc.
class MyClass
{
property int myproperty;
}
class AnotherClass
{
public void method() {
MyClass cl = new MyClass().set_myproperty(10);
}
}
Using properties
- 84. Copyright © 2012 Job and Esther Technologies, Inc.
Default parameters
public void my_method(int n = 0) {
// (method implementation code here)
}
obj.my_method(10);
obj.my_method();
Automatically supply parameter values where
no parameters are given
- 85. Copyright © 2012 Job and Esther Technologies, Inc.
Embedding other languages
- 86. Copyright © 2012 Job and Esther Technologies, Inc.
Embedding code
The dictionary definition of “embed” is to make
something an integral part of
In Eqela programming language, “embedding” refers
to adding other programming languages into blocks
within the Eqela code
- 87. Copyright © 2012 Job and Esther Technologies, Inc.
Embed: Syntax
embed “(language name)” {{{
// code in other language
}}}
Languages: c, c++, objc, java, js, cs, ..
int n;
embed “c” {{{
char* str = “Hello World”;
n = strlen(str);
}}}
Log.message(“Length = %d”.printf().add(n));
- 88. Copyright © 2012 Job and Esther Technologies, Inc.
Embed: Example
class Main
{
embed "c" {{{
#include <stdio.h>
}}}
public static void print() {
embed "c" {{{
printf("Hello worldn");
}}}
embed "java" {{{
System.out.println("Hello world");
}}}
}
embed "c" {{{
int main(int c, char** v) {
hello_Main_print();
return(0);
}
}}}
embed "java" {{{
public static void main(String[] args) {
hello_Main_print();
}
}}}
}