---------------------------------------------------------------
-- compare this Euphoria code with the c code which follows! --
---------------------------------------------------------------
include GtkEngine.e as gtk
constant window = create(GtkWindow)
set(window,"position",GTK_WIN_POS_CENTER)
set(window,"default size",250,200)
set(window,"title","Menu")
connect(window,"destroy",quit)
constant vbox = create(GtkVBox)
add(window,vbox)
constant menubar = create(GtkMenuBar),
filemenu = create(GtkMenu),
file = create(GtkMenuItem,"_File"),
new = create(GtkImageMenuItem,"gtk-new"),
open = create(GtkImageMenuItem,"gtk-open"),
sep = create(GtkSeparatorMenuItem),
accels = create(GtkAccelGroup),
quit = create(GtkImageMenuItem,"gtk-quit",accels)
set(window,"add accel group",accels)
set(file,"submenu",filemenu)
set(filemenu,"append",new)
set(filemenu,"append",open)
set(filemenu,"append",sep)
set(filemenu,"append",quit)
set(menubar,"append",file)
set(quit,"add accelerator","activate",accels,#71,GDK_CONTROL_MASK,GTK_ACCEL_VISIBLE)
pack(vbox,menubar)
connect(quit,"activate",gtk:quit)
show_all(window)
main()
-------------------------------------------------------
-- below is the c code required for the same results --
-------------------------------------------------------
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
int main( int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *menubar;
GtkWidget *filemenu;
GtkWidget *file;
GtkWidget *new;
GtkWidget *open;
GtkWidget *quit;
GtkWidget *sep;
GtkAccelGroup *accel_group = NULL;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 250, 200);
gtk_window_set_title(GTK_WINDOW(window), "menu");
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
menubar = gtk_menu_bar_new();
filemenu = gtk_menu_new();
accel_group = gtk_accel_group_new();
gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);
file = gtk_menu_item_new_with_mnemonic("_File");
new = gtk_image_menu_item_new_from_stock(GTK_STOCK_NEW, NULL);
open = gtk_image_menu_item_new_from_stock(GTK_STOCK_OPEN, NULL);
sep = gtk_separator_menu_item_new();
quit = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, accel_group);
gtk_widget_add_accelerator(quit, "activate", accel_group,
GDK_q, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), new);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), sep);
gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 3);
g_signal_connect_swapped(G_OBJECT(window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(G_OBJECT(quit), "activate",
G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
Once you have written all this C code, next you must figure out how to compile it, and find the correct headers, etc.
Using Euphoria, you just run the code, and it works! No compiling needed.
As shown above, Euphoria programs often may be translated from C programs - almost line-for-line. However, the Euphoria version is clean and easy to read, while the C code is littered with all sorts of type castings and other "noise", which just gets in the way of finding typos and other programming errors.
In most instances, there is no perceivable different in speed when running Euphoria programs and C programs. However, there is a huge difference in speed and ease of development.