Vala係一隻物件導向程式語言,由自己整嘅編譯器產生C語言代碼,仲用咗GObject系統,畀用戶喺Gnome運行嗰陣庫嘅基礎上用大量現代嘅編程技巧。通過用GLib同埋GObject,Vala提供咗動態類型系統同基於引用計數(reference counting)系統嘅內存管理嘅功能。

Vala
編程範式物件導向結構化指令式
編程員Jürg Billeter、Raffaele Sandrini
第一次出現2006年, 18年之前 (2006)
穩定版本
0.54.7 / 2022年2月14號, 2年之前 (2022-02-14)
類型系統靜態類型強類型
操作系統所有用到GLib嘅平台
軟件授權GNU寬通用公共許可證2.1+
副檔名.vala, .vapi
網站wiki.gnome.org/Projects/Vala
啟發語言
CC++C♯DJavaBOO


Vala結合咗腳本語言嘅高級編程語言建造時間性能,同低級嘅編程語言運行時間性能。相較喺用C寫成嘅應用同埋庫,佢致力喺將現代編程語言特徵帶畀GNOME開發者,而唔使強加任何額外嘅運行時間要求,並且唔使用唔同嘅ABI。Vala嘅語法同C#好似,為咗更好咁適應GObject類型系統而做咗修改[1]

歷史 編輯

版本 出嘅日期[2]
舊版本,唔再支援: 0.0.1 2006-07-15
舊版本,唔再支援: 0.1.0 2007-07-09
舊版本,唔再支援: 0.10.0 2010-09-18
舊版本,唔再支援: 0.20.0 2013-05-27
舊版本,唔再支援: 0.30.0 2015-09-18
而家嘅版本: 0.40.25 2021-01-11
舊版本,唔再支援: 0.42.0 2018-09-01
舊版本,唔再支援: 0.44.0 2019-05-09
舊版本,唔再支援: 0.46.0 2019-09-05
而家嘅版本: 0.48.23 2022-02-21
舊版本,唔再支援: 0.50.0 2020-09-11
而家嘅版本: 0.52.11 2022-02-21
而家嘅版本: 0.54.7 2022-02-14
格式:
舊版本
舊版本,仲支援緊
而家嘅版本
最新嘅預覽版
將來版本

例子 編輯

下面係Vala 嘅 Hello World程式:

void main () {
    print ("Hello World\n");
}

物件導向 編輯

下面喺更複雜啲嘅版本,表現咗Vala嘅物件導向特性:

class HelloWorld: Object {
	private uint year = 0;
	
	public HelloWorld () {
	}
	
	public HelloWorld.with_year (int year) {
		if (year>0)
			this.year = year;
	}

	public void greeting () {
		if (year == 0)
			print ("Hello World\n");
		else
			/* Strings prefixed with '@' are string templates. */
			print (@"Hello World, $(this.year)\n"); 
	}
}

void main (string[] args) {
	var helloworld = new HelloWorld.with_year (2021);
	helloworld.greeting ();
}

GObject庫入面,Vala用唔到多重繼承,但係Vala入面嘅類可以實現任何數量嘅接口,所以可以用嚟補返缺失。下面呢段代碼就係佢補返嘅方法(有時叫做mixin):

using GLib;

interface Printable {
	public abstract string print ();

	public virtual string pretty_print () {
		return "Please " + print ();
	}
}

class NormalPrint: Object, Printable {
	string print () {
		return "don't forget about me";
	}
}

class OverridePrint: Object, Printable {
	string print () {
		return "Mind the gap";
	}

	public override string pretty_print () {
		return "Override";
	}
}

void main (string[] args) {
	var normal = new NormalPrint ();
	var overridden = new OverridePrint ();

	print (normal.pretty_print ());
	print (overridden.pretty_print ());
}

工具 編輯

編輯器 編輯

Vala嘅開發工具呢幾年有咗顯著嘅改進。下面係一啲用到Vala插件嘅流行IDE同埋文本編輯器

代碼智能 編輯

依家有兩個活躍開發嘅語言服務器幫Vala整咗代碼智能英文Intelligent code completion

  • benwaffle/vala-language-server,設計用喺用到LSP嘅任何編輯器,包括VSCode、vim同埋GNOME Builder[6]
  • esodan/gvls,目前係Vala喺GNOME Builder入面嘅缺省語言伺服器,佢對喺所有用LSP嘅編輯器都用到[7]

睇埋 編輯

  • elementary OS,呢隻Linux發行版有好多功能都係用Vala寫出嚟嘅

參考 編輯

  1. "Vala· GitLab". GNOME. 喺16 March 2021搵到.
  2. "Vala Releases". Vala Project. 喺2021-03-18搵到.
  3. "Coding in Vala with Visual Studio Code". 喺2021-03-17搵到.
  4. "Coding in Vala with the Vim Text Editor". 喺2021-03-17搵到.
  5. "Enable Vala syntax highlighting and code browser support in GNU Emacs". 喺2021-03-17搵到.
  6. "benwaffle/vala-language-server on Github". GitHub. 喺2021-03-17搵到.
  7. "esodan/gvls on GitLab". 喺2021-03-17搵到.

出面網頁 編輯