Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Presentacion.
Herramientas Avanzadas para el Desarrollo de Aplicaciones
Departamento de Lenguajes y Sistemas Inform
aticos
Universidad de Alicante
1 / 44
Contenido
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Profesores
Gua Docente
Contenidos
Evaluacion
Evaluacion sin superar evaluaci
on continua
Plan de aprendizaje (I)
Plan de aprendizaje (II)
Lenguajes de practicas
Introduccion a Vala
Caractersticas de Vala
Palabras reservadas
Operadores
Hola Mundo en Vala
Compilacion
Cadenas
Entrada / Salida
Arrays
Clases
2 / 44
Profesores
Garrig
os Fernandez, Irene - (Coordinadora)
Corb Bellot, Antonio-Miguel
Mu
noz Terol, Rafael
3 / 44
Gua Docente
practicos.
4 / 44
Contenidos
5 / 44
Evaluacion
1
Evaluaci
on Contnua: Test escritorio. Se realizar
a un test para evaluar los
conocimientos de los alumnos de forma individual a mitad de curso.
Nota mnima necesaria: 4. Puntuaci
on: 30 %.
Evaluaci
on Contnua:
Evaluaci
on Contnua:
Evaluaci
on Contnua:
6 / 44
Atenci
on! En Julio, los alumnos que no superen las actividades de
Criterios de Evaluaci
on Hada.
7 / 44
Ud.
1
02
03
04
2
3
05
06
4
5
07
Control de versiones
Programaci
on dirigida por eventos y ejecuci
on diferida de c
odigo
Interfaces gr
aficas de usuario
Acceso a BBDD desde aplicaciones de
escritorio
Bibliotecas.
8 / 44
Ud.
7
8
7
7
8
8,9
14
15
1-9
Total
Desc. trab.
Pr
actica en
Pr
actica en
Pr
actica en
Pr
actica en
Pr
actica en
Pr
actica en
no pres.
grupo
grupo
grupo
grupo
grupo
grupo
Pr
actica en grupo.
Exposici
on oral.
Correcci
on pr
actica
en grupo
90
9 / 44
Lenguajes de practicas
Pr
acticas individuales Lenguaje Vala.
Pr
actica en grupo Lenguaje C# (con ASP.net).
10 / 44
Introduccion a Vala
Vala
Glib
GObject
compilador de Lenguaje C.
Es un lenguaje similar a Java y C#, m
as parecido a este u
ltimo.
11 / 44
Caractersticas de Vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Palabras reservadas
Operadores
Aritmeticos: +, -, *, /, %
Bit a bit: , &, |,, <<, >>
Relacionales: <, >, <=, >=
Igualdad: ==, !=
Logicos: !, &&, ||
Asignacion: =, +=, -=, *=, /=, %=, &=, |=,=, <<=, >>=
Incremento, Decremento: ++,
Punteros: &, *, ->, delete
Condicionales: ?:
Comparacion con null: ??
Concatenaci
on de cadenas: +
Invocacion de metodos: ()
Acceso a miembros: .
Indice: [ ]
Troceado: [ : ]
Lambda: =>
Casting: (Type), (!), as
Comprobaci
on de tipos en tiempo de ejecucion: is
Transferencia de propiedad: (owned)
Cualificador de alias de espacios de nombres: :: (currently only with
global)
Otros: new, sizeof, typeof, in
14 / 44
1
3
5
c l a s s Demo . H e l l o W o r l d : GLib . O b j e c t {
p u b l i c s t a t i c i n t main ( s t r i n g [ ] a r g s ) {
s t d o u t . p r i n t f ( " Hello , World \ n " ) ;
return 0;
}
}
15 / 44
Compilacion
16 / 44
Cadenas
https://live.gnome.org/Vala/Tutorial
2
4
6
8
int a = 6 , b = 7;
s t r i n g s = @" $a * $b = $ ( a * b ) " ;
// => 6 7 = 42
// => w o r l d
// => o r
12
//
//
//
//
//
=>
=>
=>
=>
=>
14
i f ( " ere " i n " Able was I ere I saw Elba . " )
...
10
false
52
6 . 6 7 4 2 8 E11
true
21
17 / 44
Cadenas
https://live.gnome.org/Vala/Tutorial
1
3
Tambi
en disponemos de la salida de error estandar representada por
stderr.
Podemos mostrar informaci
on en ella con printf as:
stderr.printf(...);.
18 / 44
Arrays
https://live.gnome.org/Vala/Tutorial
2
4
6
8
10
i n t [ ] a = new i n t [ 1 0 ] ;
i n t [ ] b = { 2 , 4 , 6 , 8 };
int [] c = b [1:3];
// => { 4 , 6 }
int
al = a . length ;
i n t [ , ] c = new i n t
i n t [ , ] d = {{2 , 4 ,
{3 , 5 ,
{1 , 3 ,
d [2 ,3] = 42;
int d0l = d . length
[3 ,4];
6 , 8} ,
7 , 9} ,
5 , 7}};
[0];
12
i n t [ ] e = {}; e += 1 2 ; e += 5 ; e += 3 7 ;
19 / 44
Clases
https://live.gnome.org/Vala/Tutorial
1
3
5
7
9
/ d e f i n i n g a c l a s s /
c l a s s Track : GLib . O b j e c t {
p u b l i c d o u b l e mass ;
p u b l i c d o u b l e name { g e t ; s e t ; }
p r i v a t e bool terminated = f a l s e ;
public void terminate () {
terminated = true ;
}
}
/
/
/
/
/
s u b c l a s s i n g GLib . O b j e c t /
a p u b l i c f i e l d /
a p u b l i c p r o p e r t y /
a p r i v a t e f i e l d /
a p u b l i c method /
20 / 44
int
float
i = 10;
j = ( float ) i ;
var
var
var
var
=
=
=
=
3
5
7
9
11
p
s
l
i
new P e r s o n ( ) ;
" hello " ;
new L i s t <i n t >() ;
10;
//
//
//
//
same
same
same
same
a s : P e r s o n p = new P e r s o n ( ) ;
as : s t r i n g s = h e l l o ;
a s : L i s t <i n t > l = new L i s t <i n t >() ;
as : i n t i = 10;
21 / 44
Operador ??
https://live.gnome.org/Vala/Tutorial
22 / 44
Foreach
https://live.gnome.org/Vala/Tutorial
f o r e a c h ( i n t a i n i n t a r r a y ) { s t d o u t . p r i n t f ( " %d \ n " , a ) ; }
23 / 44
1
3
5
// n o t n u l l a b l e
// n u l l a b l e
7
9
o1 = o2 ; // P r o h i b i d o
o1 = ( ! ) o2 ; // P e r m i t i d o con e l c a s t nonn u l l
e x p l i c i t o : operador !
24 / 44
Delegados
https://live.gnome.org/Vala/Tutorial
void f1 ( int a) {
s t d o u t . p r i n t f ( " %d \ n " , a ) ;
}
5
7
9
11
13
void f2 ( DelegateType d , i n t a ) {
d(a) ;
// C a l l i n g a d e l e g a t e
}
v o i d main ( ) {
f 2 ( f1 , 5) ;
// P a s s i n g a method a s d e l e g a t e argument t o a n o t h e r
method
}
25 / 44
Clausuras
https://live.gnome.org/Vala/Tutorial
d2e l e g a t e v o i d P r i n t I n t F u n c ( i n t a ) ;
4
6
8
10
v o i d main ( ) {
P r i n t I n t F u n c p1 = ( a ) => { s t d o u t . p r i n t f ( " %d \ n " , a ) ; } ;
p1 ( 1 0 ) ;
// C u r l y b r a c e s a r e o p t i o n a l i f t h e body c o n t a i n s o n l y one s t a t e m e n t
:
P r i n t I n t F u n c p2 = ( a ) => s t d o u t . p r i n t f ( " %d \ n " , a ) ;
p2 ( 2 0 ) :
}
26 / 44
Espacios de nombres
https://live.gnome.org/Vala/Tutorial
namespace Hada {
int n;
}
4
6
u s i n g Hada ;
n = 3 ; // O t a m b i e n . . .
Hada . n = 3 ;
27 / 44
Visibilidad
https://live.gnome.org/Vala/Tutorial
public
private
protected
internal
28 / 44
Constructores/Destructores
https://live.gnome.org/Vala/Tutorial
1
3
p u b l i c c l a s s Button : Object {
p u b l i c Button ( ) {
}
p u b l i c Button . w i t h l a b e l ( s t r i n g
}
label ) {
7
p u b l i c Button . f r o m s t o c k ( s t r i n g s t o c k i d ) {
}
9
}
11
13
15
c l a s s Demo : O b j e c t {
Demo ( ) {
s t d o u t . p r i n t f ( " in destructor " ) ;
}
}
29 / 44
Senales
https://live.gnome.org/Vala/Tutorial
p u b l i c c l a s s T e s t : GLib . O b j e c t {
public s i g n a l void s i g 1 ( int a) ;
p u b l i c s t a t i c i n t main ( s t r i n g [ ]
T e s t t 1 = new T e s t ( ) ;
args ) {
6
t 1 . s i g 1 . c o n n e c t ( ( t , a ) => { s t d o u t . p r i n t f ( " %d \ n " , a ) ; } ) ;
8
t1 . s i g 1 (5) ;
10
return 0;
}
12
}
30 / 44
Propiedades
https://live.gnome.org/Vala/Tutorial
c l a s s Person : Object {
private i n t age = 32;
with property
// u n d e r s c o r e p r e f i x t o a v o i d name c l a s h
3
/ P r o p e r t y /
p u b l i c i n t age {
get { return age ; }
set { age = value ; }
}
5
7
9
11
13
15
17
}
// O mas r e s u m i d o . . .
c l a s s Person : Object {
/ P r o p e r t y w i t h s t a n d a r d g e t t e r and s e t t e r and d e f a u l t v a l u e /
p u b l i c i n t age { g e t ; s e t ; d e f a u l t = 3 2 ; }
...
// De s o l o l e c t u r a
p u b l i c i n t age2 { ge t ; p r i v a t e s e t ; d e f a u l t = 3 2 ; }
}
19
21
23
P e r s o n a l i c e = new P e r s o n ;
a l i c e . n o t i f y [ " age " ] . c o n n e c t (
( s , p ) => { s t d o u t . p r i n t f ( " age has changed \ n " ) ; }
);
31 / 44
Clases abstractas
https://live.gnome.org/Vala/Tutorial
1
3
p u b l i c a b s t r a c t c l a s s Animal : Object {
public void eat () {
s t d o u t . p r i n t f ( " * chomp chomp *\ n " ) ;
}
5
public abstract void s a y h e l l o () ;
7
p u b l i c c l a s s T i g e r : Animal {
public override void s a y h e l l o () {
s t d o u t . p r i n t f ( " * roar *\ n " ) ;
}
}
11
13
15
17
19
p u b l i c c l a s s Duck : A n i m a l {
public override void s a y h e l l o () {
s t d o u t . p r i n t f ( " * quack *\ n " ) ;
}
}
32 / 44
Interfaces
https://live.gnome.org/Vala/Tutorial
1
3
5
7
9
p u b l i c i n t e r f a c e I T e s t : GLib . O b j e c t {
public abstract i n t data 1 { get ; set ; }
p u b l i c a b s t r a c t v o i d method 1 ( ) ;
}
....
p u b l i c c l a s s T e s t 1 : GLib . O b j e c t , I T e s t {
public i n t data 1 { get ; set ; }
p u b l i c v o i d method 1 ( ) {
}
}
33 / 44
2
4
c l a s s S u p e r C l a s s : GLib . O b j e c t {
p u b l i c v i r t u a l v o i d method 1 ( ) {
s t d o u t . p r i n t f ( " SuperClass . method_1 () \ n " ) ;
}
}
6
8
10
c l a s s SubClass : SuperClass {
p u b l i c o v e r r i d e v o i d method 1 ( ) {
s t d o u t . p r i n t f ( " SubClass . method_1 () \ n " ) ;
}
}
34 / 44
RTTI
https://live.gnome.org/Vala/Tutorial
1
3
5
b o o l b = o b j e c t i s SomeTypeName ;
Type t y p e = o b j e c t . g e t t y p e ( ) ;
s t d o u t . p r i n t f ( " %s \ n " , t y p e . name ( ) ) ;
Type t y p e = t y p e o f ( Foo ) ;
Foo f o o = ( Foo ) O b j e c t . new ( t y p e ) ;
35 / 44
36 / 44
Clases genericas
https://live.gnome.org/Vala/Tutorial
p u b l i c c l a s s Wrapper<G> : GLib . O b j e c t {
p r i v a t e G data ;
3
p u b l i c v o i d s e t d a t a (G d a t a ) {
t h i s . data = data ;
}
7
public G get data () {
return t h i s . data ;
}
9
11
13
15
37 / 44
1
3
5
7
d o u b l e method name ( i n t x , d o u b l e d )
r e q u i r e s ( x > 0 && x < 1 0 )
r e q u i r e s ( d >= 0 . 0 && d <= 1 . 0 )
e n s u r e s ( r e s u l t >= 0 . 0 && r e s u l t <= 1 0 . 0 )
{
return d x ;
}
38 / 44
Excepciones
https://live.gnome.org/Vala/Tutorial
errordomain IOError {
FILE NOT FOUND
v o i d my method ( ) t h r o w s I O E r r o r {
// . . .
i f ( something went wrong ) {
throw new I O E r r o r . FILE NOT FOUND (
" Requested file could not be found . " ) ;
}
}
...
try {
my method ( ) ;
} catch ( IOError e ) {
s t d o u t . p r i n t f ( " Error : %s \ n " , e . m e s s a g e ) ;
}
...
IOChannel channel ;
try {
c h a n n e l = new I O C h a n n e l . f i l e ( " / tmp / my_lock " , " w " ) ;
} catch ( F i l e E r r o r e ) {
i f ( e i s F i l e E r r o r . EXIST ) {
throw e ;
}
GLib . e r r o r ( " " , e . m e s s a g e ) ;
}
7
9
11
13
15
17
19
21
23
25
27
39 / 44
v o i d method 1 ( i n t a , out i n t b , r e f i n t c ) { . . . }
v o i d method 2 ( O b j e c t o , out O b j e c t p , r e f O b j e c t q ) { . . . }
3
5
7
9
11
int a = 1;
int b;
int c = 3;
method 1 ( a , out b , r e f c ) ;
Object
Object
Object
method
o = new O b j e c t ( ) ;
p;
q = new O b j e c t ( ) ;
2 ( o , out p , r e f q ) ;
13
15
17
// Una i m p l e m e n t a c i o n de method 1
v o i d method 1 ( i n t a , out i n t b , r e f i n t c ) {
b = a + c;
c = 3;
}
40 / 44
Colecciones (I)
41 / 44
Colecciones (II)
https://live.gnome.org/Vala/Tutorial
u s i n g Gee ;
2
4
6
8
10
12
14
16
v o i d main ( ) {
v a r l i s t = new A r r a y L i s t <i n t > ( ) ;
l i s t . add ( 1 ) ;
l i s t . add ( 2 ) ;
l i s t . add ( 5 ) ;
l i s t . add ( 4 ) ;
l i s t . i n s e r t (2 , 3) ;
l i s t . remove at (3) ;
foreach ( int i in l i s t ) {
s t d o u t . p r i n t f ( " %d \ n " , i ) ;
}
l i s t [ 2 ] = 10;
s t d o u t . p r i n t f ( " %d \ n " , l i s t [ 2 ] ) ;
}
// same a s
// same a s
l i s t . s e t (2 , 10)
l i s t . get (2)
Compilar y ejecutar:
2
42 / 44
Soporte multi-thread
https://live.gnome.org/Vala/Tutorial
2
4
6
8
10
12
14
16
18
return 0;
}
20
22
// E s t e t i p o de c o d i g o s e d e b e c o m p i l a r a s i :
> v a l a c t h r e a d t h r e a d s a m p l e . v a l a
43 / 44
Enlaces de interes
La gesti
on de memoria din
amica en Vala
Lista de
bibliotecas
live.gnome.org/Vala/FAQ
Ejemplos sencillos
ejemplos con se
nales y callbacks
video-tutorial
44 / 44