Vala and Genie programming

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#441 Post by BarryK »

Double post
[url]https://bkhome.org/news/[/url]

User avatar
rarsa
Posts: 3053
Joined: Sun 29 May 2005, 20:30
Location: Kitchener, Ontario, Canada
Contact:

#442 Post by rarsa »

BarryK wrote:"anything with Basic in the name"
Yep, it was me. I'm scratching already. :D

And no, no intention to stir any debates :) . Once I understood the [indent=...] things were clear.

Its clearly a matter of preference.

Well, back to Vala/Genie
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

vala 0.7.8 pet??

#443 Post by gyro »

Hi,

Is there a .pet of vala 0.7.8 anywhere?
I wish to install it on pup-431.

There seems to be omissions in Xlib.vapi in vala 0.7.4.

gyro

Edit: It is x11.vapi not Xlib.vapi.
Last edited by gyro on Tue 17 Nov 2009, 07:36, edited 1 time in total.

User avatar
ttuuxxx
Posts: 11171
Joined: Sat 05 May 2007, 10:00
Location: Ontario Canada,Sydney Australia
Contact:

Re: vala 0.7.8 pet??

#444 Post by ttuuxxx »

gyro wrote:Hi,

Is there a .pet of vala 0.7.8 anywhere?
I wish to install it on pup-431.

There seems to be omissions in Xlib.vapi in vala 0.7.4.

gyro
here try this :)
ttuuxxx
http://audio.online-convert.com/ <-- excellent site
http://samples.mplayerhq.hu/A-codecs/ <-- Codec Test Files
http://html5games.com/ <-- excellent HTML5 games :)

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

Re: vala 0.7.8 pet - works

#445 Post by gyro »

ttuuxxx wrote:here try this :)
ttuuxxx
Thanks
The updated x11.vapi looks good
gyro

Edit: Works fine, thanks ttuuxxx

tsura
Posts: 3
Joined: Tue 01 Dec 2009, 08:25

#446 Post by tsura »

disciple wrote:Hi guys, I haven't really looked at Vala yet, but I'm wondering - does anyone have any idea how hard it would be to convert a simple-ish gtk program from c to vala? And how much easier do you think it would be to learn vala than C? Is Vala:
0. No easier than C
1. A little easier than C
2. Quite a bit easier than C
3. A lot easier than C
4. So much easier than C that there's no comparison.

Any thoughts?
Hmm. It's a whole lot easier, but I wouldn't say there's no comparison. It has its similarities, but at least you don't have to deal with header files, having to put functions in certain places, funky less-readable syntax and all that other stuff. Plus you get some nice string functions, such as up(), down(), strip() and split() out of the box. Making a GUI in Vala is easy, too, and although there's not a whole lot of extensively commented-on documentation, you can always look at Gtk documentation for other languages and often figure out the Vala method with ease.

I highly recommend learning Vala. It's worth it, I'd say.

Here are some helpful links:
http://references.valadoc.org/
http://live.gnome.org/Vala
http://www.pygtk.org/docs/pygtk/
• etc.

Anyway, other, non-Vala sites on Gtk often give information that the Vala sites don't give, so that's why I list a few others. Even the C documentation on Gtk can be quite helpful, actually. Vala is one of the few languages that seems quite easy to use documentation from other languages with.

I like to ask questions on the programming forum at Ubuntuforums. People don't always answer, but they do often enough that it's worth it.

ljfr
Posts: 176
Joined: Thu 23 Apr 2009, 08:35

JWM shortcut manager

#447 Post by ljfr »

Hi,

Note:Some objects of the bellow examples are not freed correctly, some function to do that are missing in the current libxml bindings (reported to gnome bugzilla).

following Caleb72 example, I attached a jwm shortcut manager (similar to the one in jwmconfigmgr) in vala using libxml, using xpath to find desired nodes.

To compile and run it:

Code: Select all

valac -X -Os --pkg libxml-2.0 --pkg gtk+-2.0 jwmshortcut.vala
strip --strip-unneeded jwmshortcut
./jwmshortcut
As libxml provide an easy way to handle jwm configuration files, a full jwmconfigmgr in genie/vala might not be so big and ... improved.

Regarding compilation, is there a better way to decrease executable size?

regards,
Attachments
jwmshortcut.tar.gz
(5.28 KiB) Downloaded 590 times
Last edited by ljfr on Mon 08 Mar 2010, 11:20, edited 1 time in total.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#448 Post by technosaurus »

the compile scripts that were packaged with nicoedit first generate the "C" code and then compile it
if you add this after gcc
gcc -Os -fomit-framepointer -momit-leaf-frame-pointer -fmerge-all-constants -march=i486 -mtune=i686 ... rest of stuff

then better stripping
strip --strip-all --remove-section=.comment --remove-section=.note *
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#449 Post by Lobster »

Hi rarsa :)

This is quite a technical question
- so make the answer fit for an idiot (me)

Is Vala more secure than C?
Or is it how the code is written?

As you know some languages such as javascript are very useful but insecure (so let's base the whole Cloud thing on them :oops: )

Is Vala pronounced valour
and suitable for the brave?
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

DMcCunney
Posts: 889
Joined: Tue 03 Feb 2009, 00:45

#450 Post by DMcCunney »

Lobster wrote: Is Vala more secure than C?
Or is it how the code is written?
It is always how the code is written.
As you know some languages such as javascript are very useful but insecure (so let's base the whole Cloud thing on them :oops: )
And your vast knowledge of how insecure JavaScript is comes from where, exactly?

See above about it always being how the code is written.

(And while you're at it, define just what you mean by "security".)
______
Dennis

tsura
Posts: 3
Joined: Tue 01 Dec 2009, 08:25

#451 Post by tsura »

DMcCunney wrote:(And while you're at it, define just what you mean by "security".)
I think Lobster may have security issues with web-based client-side and server-side scripting mixed up with general programming security. That's only an issue for browser-oriented client-side scripting, really (I don't know of anything besides JavaScript that would have this issue).

The client can see the JavaScript code, since it's mostly a client-side thing. If that's what you're thinking, no you won't have that problem with Vala or C. In fact, you probably don't need to worry about it at all, unless you want people to type in a password for something (on the Internet) and you don't have access to the server. You could try using encryption keys in that case.

What do you need security for?

DMcCunney
Posts: 889
Joined: Tue 03 Feb 2009, 00:45

#452 Post by DMcCunney »

tsura wrote:
DMcCunney wrote:(And while you're at it, define just what you mean by "security".)
I think Lobster may have security issues with web-based client-side and server-side scripting mixed up with general programming security.
I do too, which is why I asked.
That's only an issue for browser-oriented client-side scripting, really (I don't know of anything besides JavaScript that would have this issue).
Microsoft Active-X controls, which are fortunately confined to Internet Explorer under Windows. (Microsoft was pushing VBSript as well back when, but it thankfully remained a client side product, and never gained traction as an alternative to JavaScript on web sites.
The client can see the JavaScript code, since it's mostly a client-side thing. If that's what you're thinking, no you won't have that problem with Vala or C. In fact, you probably don't need to worry about it at all, unless you want people to type in a password for something (on the Internet) and you don't have access to the server. You could try using encryption keys in that case.
The usual security problems with compiled languages exploit things like buffer overflow, and are more examples of "how the code is written".
______
Dennis

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#453 Post by technosaurus »

Vala Releases

Vala 0.7.10
source tarball

released on February 4, 2010


Changes
Support coalescing operator ??.
Support to_string and bitwise complement with enums.
Return handler id when connecting signal handlers.
Support struct comparison.
Support constructor chaining in structs.
Enforce protected member restrictions.
Improve performance of flow analysis.
Support automatic line continuations in Genie.
Improvements to the .gir reader and writer.
Add --enable-mem-profiler commandline option.
Many bug fixes and binding updates.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
rarsa
Posts: 3053
Joined: Sun 29 May 2005, 20:30
Location: Kitchener, Ontario, Canada
Contact:

#454 Post by rarsa »

Sorry for the late response, I've been quite busy at work.
Lobster wrote:Hi rarsa :) Is Vala more secure than C?
Or is it how the code is written?
Someone responded with "Define security". But based on your question it seems to me that you meant "Safety". Quite similar words, used as synonyms in regular English but in coding terms a bit different.

Security basically means: Who has access to what and when. That applies to users as much as the calls and objects passed around inside an application.

Some languages and runtime environments provide Security mechanisms such as code level signing. To the best of my knowledge, neither C or Vala provide that, so it depends on the program itself to determine security.

Safety in this context is the syntax or mechanisms that a language has to protect from having code vulnerabilities. So in a sense depends on the language ONLY if the programmer uses such syntax and mechanisms.

In this sense C is less safe "out of the box" but there are library frameworks that provide the extra safety such as protection against memory overflow.

Vala in a sense is safer C as it implements those safety mechanisms for the programer such as proper type checking.

I haven't used Vala long enough or in programs large enough to find out if it has safety mechanisms that would help prevent for example SQL injections other than using the same libraries as C.

So responding to the question: I think Vala is safer than C mainly because Vala does the work of writing safer C.

Example of Safety lapse
Example of security lapse
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#455 Post by Lobster »

C mainly because Vala does the work of writing safer C.
That makes sense - being forced to write better code.
Many thanks :)
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

DMcCunney
Posts: 889
Joined: Tue 03 Feb 2009, 00:45

#456 Post by DMcCunney »

rarsa wrote:So responding to the question: I think Vala is safer than C mainly because Vala does the work of writing safer C.
Expanding a bit on what Rarsa said, it might help to talk a little about C.

The C language was first created by a programmer named Dennis Ritchie in the 1960s at AT&T's Bell Laboratories. At the time, system software was normally written in assembler. Each line in an assembly language program normally translates to one machine language instruction. This makes it possible to write the smallest, most efficient code, because the programmer can specify exactly what the machine is to do. But it's difficult to write and hard to maintain, because it requires the developer to look at things the way the machine does, which will have little relation to what the program is supposed to do, and assembly language programs may take thousands of lines to do what can be done in a few dozen lines in a higher level language. In addition, assembler lacks the high-level constructs programmers are used to, like IF-THEN-ELSE, DO WHILE, and CASE.

Ritchie based his efforts on an earlier language called BCPL. His goal was a language that would have the high-level constructs available in other languages, be relatively easy to port to different architectures, but be efficient enough that you didn't have to write in assembler to get performance. He wanted a language that could be used for writing things like operating systems.

At the same time Dennis Ritchie was developing C, another group of programmers under Ken Thompson and Brian Kernighan were writing a new OS. They were software developers, and wanted an environment better suited for software development than the one provided by the operating system on the DEC mini-computer they used for development. the new OS was called Unix.

Early versions of Unix were written in Macro-11, the assembly language provided with the DEC system. But around Unix Version 6, C had matured to the point where it could be used, and most of Unix was rewritten in C, with only about 10% dealing directly with the underlying hardware still in assembler.

Because C was relatively portable, it was possible to bring C up on a different machine, and then port Unix to it with a fraction of the effort working in assembler would require. Unix expanded rapidly within Bell Labs, and then throughout AT&T. C became a popular language for writing applications as well as operating systems.

Because C is fairly low-level, it requires care by the programmer writing code. Things handled automatically by other modern languages must be explicitly coded in C.

For example, the biggest problem on any system is probably memory management. When a program runs, it requests memory from the OS to hold its code and the data it will process. When it's finished with the memory, the memory used must be returned to the OS. Some modern languages attempt to handle that for you, with mechanisms like "garbage collection", where memory no longer used is automatically collected and returned to the OS for use by other things. In C, when you are finished with memory, you must explicitly free it.

This requirement leads to one common programming problem - memory leaks. The program will allocate memory for some purpose, but will not explicitly free it, so the OS may think the memory is in use and be unable to reuse it even after the program that asked for it has stopped running. And it can cause programs that are still running to have ever increasing memory requirements until the machine becomes unresponsive or even crashes. (And it's a complex issue, because even if you are careful to explicitly free memory when done with it, it's possible for other problems to cause the program to fail to reach the instruction that is intended to free the allocated memory.)

Another problem affects any language, and can be summarized as "Never trust your data". When you write a program, your program will be dealing with data, and the data will come from elsewhere. Your code will allocate a buffer in memory to hold the data is is processing. What happens if your program allocates a 5K buffer for data, and what it actually gets is 10K? What happens to the extra 5K? It overflows the memory buffer, and winds up overwriting other parts of memory, with bad results. These kinds of problems are known as "buffer overflow" errors. Most of the Critical Security patches released for Windows are intended to patch such problems, as bad guys discover buffer vulnerabilities that will let malicious code destabilize the system and crash it or leave it vulnerable to outside control.

When the code being patched was first written, it simply didn't occur to the programmers that anyone would deliberately try to overflow a buffer in memory for bad purposes. They assumed the data would be in the correct form and amount, and took no measures to handle the case where it wasn't. The problem isn't unique to Windows, either. There are regular patches released to plug such vulnerabilities in Linux code, too.

C isn't really terribly more unsafe than other languages. It's possible to write unsafe code in pretty much any language out there. But C is powerful, so "With great power comes great responsibility". Things other languages do for you you must do for yourself in C, and must be aware you must do them, and do them correctly.

Why not use something else instead of C? It depends on what you are doing. As programming languages become progressively higher level, code written in the becomes progressively larger. Things that are specified in detail by the programmer in a lower level language are handled automatically by the higher-level one, but the code that does it won't be as small and fast as the lower level language can produce. Modern hardware is fast and powerful enough that you usually don't care, and we see "bloat" because it's faster and cheaper to throw more hardware at the code than to go through the efforts needed to make it smaller and faster. Hardware is cheap. Developer time is expensive.

So when you are looking at a development effort, one question will be what to write in, and ideally, you'll use a language intended for the sort of problem you are trying to solve. If you want your code to be cross platform, and able to be built and run on Windows, Mac OS/X, and Linux, you will probably use C or C++ because they are portable. If you are writing a GUI front-end for something that will only ever be used on Windows, Visual BASIC might be the best choice, as it's well suited for that sort of task.

Every language has strengths and weaknesses, and requires developers to know what they are doing to code effectively.
______
Dennis

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#457 Post by technosaurus »

Sorry to interupt the philosophical discussion, but I got another wild idea. This time a faster, lower resource replacement for gktdialog using the new (as of 2.14) builtin gtkbuilder.

Here is an example:

Code: Select all

/*
 * compilation:
 * valac --pkg gtk+-2.0 --pkg gmodule-2.0 sample.vala
 */
using Gtk;
 
public static void on_button1_clicked (Button source) {
    source.label = "Thank you!";
}
 
public static void on_button2_clicked (Button source) {
    source.label = "Thanks!";
}
 
static int main (string[] args) {     
    Gtk.init (ref args);
 
    try {
        var builder = new Builder ();
        builder.add_from_file ("sample.ui");
        builder.connect_signals (null);
        var window = builder.get_object ("window") as Window;
        window.show_all ();
        window.destroy.connect (Gtk.main_quit);
        Gtk.main ();
    } catch (Error e) {
        stderr.printf ("Could not load UI: %s\n", e.message);
        return 1;
    } 
 
    return 0;
}
Obvious first questions:
1. need to set it up to have a variable filename (from script/command line)???
2. if variables get changed via the UI can they be accessible from the script that calls it - if so how?

There are plenty of gtkbuilder ui examples - abiword 2.8.X has quite a few

Any ideas? Or is gtkdialog fast enough if we throw enough hardware at it?
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

DMcCunney
Posts: 889
Joined: Tue 03 Feb 2009, 00:45

#458 Post by DMcCunney »

technosaurus wrote:Obvious first questions:
1. need to set it up to have a variable filename (from script/command line)???
2. if variables get changed via the UI can they be accessible from the script that calls it - if so how?

There are plenty of gtkbuilder ui examples - abiword 2.8.X has quite a few

Any ideas? Or is gtkdialog fast enough if we throw enough hardware at it?
Let me make sure I understand this.

Gtk builder is a Vala builtin. You can use it within Vala code.

But Vala is a compiled language, so your sample code will be executed in the context of compilation, and compilation requires the dev SFS installed.

Are you thinking you might be able to create a compiled Vala executable that will perform the same functions as Gtkdialog, configurable when run from command line parms, but smaller and lighter than Gtkdialog?

Gtkdialog is livable on my Puppy box (857mhz CPU, 256MB RAM, ATI Rage Pro onboard graphics), but a lot of the boxes people are using Puppy on simply don't have the hardware to throw at it.

I might go a different route, install TclTk as a default on Puppy, and use it for the purposes Gtkdialog gets applied to. It's the sort of thing it's designed to do.
______
Dennis

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#459 Post by technosaurus »

Gtkbuilder was added to gtk in 2.14 and has basically made libglade obsolete, so the only vala binding required would be gtk (and apparently gmodule?) Most active gtk software is using it now, so there are plenty of examples.

The .ui (or .xml) files are read in after compilation - much the way .glade files are. Gtkdialog can already load glade files on the fly using libglade - but it is slow & resource hungry.

There are several other programs that do something similar in various (all slow) methods ... gkt-server(builds gui line by line from script), gtkdialog(libglade slows it down), bashdiff(slows down all bash scripts)

As for adding Tcl/Tk, it does work well, its easy and I like it - maybe better than Gtk, but Gtk can't go away completely - I have looked for suitable, light non-Gtk replacements - they are pretty sparse and mostly Qt which is anything but light. A Gtkbuilder executable should only be a few kb (compared to a few MB of Tcl/Tk) and be much faster than the others.

Most glade examples can be converted to gtkbuilder with a converter so I may try converting renaming one of the sample glade files from gtkdialog to sample.ui to test it out using the above code from the valaide examples
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#460 Post by disciple »

Technosaurus, it still isn't clear whether you are suggesting writing something like Gtkdialog which uses gtkbuilder instead of glade, or if you are suggesting that it is already possible to do what we do with glade, somehow, or if you are suggesting something else...
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

Post Reply