zig语言把自己的竞争对手定为了C语言,注意不是C++,而就是最基础的C。
下面就体验一把这个语言:
1、安装snap
cat@lubancat:~$ sudo apt install snap
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
accountsservice-ubuntu-schemas activity-log-manager apg aptdaemon aptdaemon-data
cracklib-runtime gedit gedit-common gir1.2-accountsservice-1.0 gir1.2-adw-1 gir1.2-gck-1
gir1.2-gcr-3 gir1.2-gdesktopenums-3.0 gir1.2-gdm-1.0 gir1.2-geoclue-2.0
gir1.2-gnomebluetooth-3.0 gir1.2-gnomedesktop-3.0 gir1.2-graphene-1.0 gir1.2-gtk-4.0
gir1.2-gtksource-4 gir1.2-gweather-3.0 gir1.2-javascriptcoregtk-4.0 gir1.2-json-1.0
gir1.2-mutter-10 gir1.2-nma-1.0 gir1.2-peas-1.0 gir1.2-rsvg-2.0 gir1.2-soup-2.4
gir1.2-upowerglib-1.0 gir1.2-vte-2.91 gkbd-capplet gnome-bluetooth-3-common
gnome-bluetooth-common gnome-control-center-data gnome-control-center-faces gnome-menus
gnome-remote-desktop gnome-settings-daemon gnome-shell-common gsfonts imagemagick-6-common
language-selector-gnome libabsl20210324 libadwaita-1-0 libcolord-gtk1 libcrack2 libdca0
libdee-1.0-4 libdjvulibre-text libdjvulibre21 libebackend-1.2-10 libebook-1.2-20
libebook-contacts-1.2-3 libedata-book-1.2-26 libedata-cal-2.0-1 libfaad2 libfftw3-double3
libfluidsynth3 libfreeaptx0 libfreerdp-client2-2 libfreerdp-server2-2 libfreerdp2-2 libgdm1
libgeoclue-2-0 libgeocode-glib0 libgeonames-common libgeonames0 libgjs0g
libgnome-autoar-0-0 libgnome-bluetooth-3.0-13 libgnome-bluetooth13 libgnome-menu-3-0
libgnomekbd8 libgsound0 libgspell-1-2 libgspell-1-common libgssdp-1.2-0
libgtksourceview-4-0 libgtksourceview-4-common libgupnp-1.2-1 libgupnp-av-1.0-3
libgupnp-igd-1.0-4 libgweather-3-16 libgweather-common libinstpatch-1.0-2 libjxr-tools
libjxr0 libkate1 liblqr-1-0 libltc11 libmagickcore-6.q16-6 libmagickcore-6.q16-6-extra
libmagickwand-6.q16-6 libmediaart-2.0-0 libmjpegutils-2.1-0 libmodplug1 libmozjs-102-0
libmpcdec6 libmpeg2encpp-2.1-0 libmplex2-2.1-0 libmutter-10-0 libnice10 libopenh264-6
libopenni2-0 libpeas-1.0-0 libpeas-common libphonenumber8 libpulsedsp libpwquality-common
libpwquality1 libqrencode4 libqt5multimedia5 libqt5multimediaquick5
libqt5multimediawidgets5 librest-0.7-0 librygel-core-2.6-2 librygel-db-2.6-2
librygel-renderer-2.6-2 librygel-server-2.6-2 libsoundtouch1 libsoup-gnome2.4-1 libspandsp2
libspeexdsp1 libsrtp2-1 libtimezonemap-data libtimezonemap1 libtumbler-1-0
libunity-control-center1 libvncserver1 libvo-aacenc0 libvo-amrwbenc0
libwhoopsie-preferences0 libwildmidi2 libwinpr2-2 libwmflite-0.2-7 libxcb-xv0 libxcvt0
libzbar0 libzeitgeist-2.0-0 libzxingcore1 mutter-common power-profiles-daemon
pulseaudio-utils python3-aptdaemon python3-aptdaemon.gtk3widgets python3-defer
python3-macaroonbakery python3-nacl python3-protobuf python3-pymacaroons python3-requests
python3-rfc3339 qml-module-qtmultimedia switcheroo-control timgm6mb-soundfont
tumbler-common ubuntu-wallpapers ubuntu-wallpapers-jammy whoopsie whoopsie-preferences
xwayland yaru-theme-gnome-shell zeitgeist-core zenity-common
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
snap
0 upgraded, 1 newly installed, 0 to remove and 71 not upgraded.
Need to get 370 kB of archives.
After this operation, 2719 kB of additional disk space will be used.
Get:1 http://mirrors.ustc.edu.cn/ubuntu-ports jammy/universe arm64 snap arm64 2013-11-29-11 [370 kB]
Fetched 370 kB in 1s (627 kB/s)
Selecting previously unselected package snap.
(Reading database ... 188061 files and directories currently installed.)
Preparing to unpack .../snap_2013-11-29-11_arm64.deb ...
Unpacking snap (2013-11-29-11) ...
Setting up snap (2013-11-29-11) ...
Processing triggers for man-db (2.10.2-1) ...
2、安装zig:
cat@lubancat:~$ sudo snap install zig --classic --beta
Setup snap "snapd" (18600) security profiles |
2023-04-07T22:56:27+08:00 INFO Waiting for automatic snapd restart...
zig (beta) 0.10.1 from Jay Petacat (jayschwa) installed
3、快速体验:
创建:
cat@lubancat:~$ mkdir hello-world
cat@lubancat:~$ cd hello-world/
cat@lubancat:~/hello-world$ zig init-exe
info: Created build.zig
info: Created src/main.zig
info: Next, try `zig build --help` or `zig build run`
cat@lubancat:~/hello-world$ zig build run
Semantic Analysis [3577] stripOptionalOrErrorUnionSpec... Semantic Analysis [1181] normalize...All your codebase are belong to us.
Run `zig build test` to run the tests.
运行:
cat@lubancat:~/hello-world$ zig build run
Semantic Analysis [3577] stripOptionalOrErrorUnionSpec... Semantic Analysis [1181] normalize...All your codebase are belong to us.
3、修改代码,输出hello world:
sudo vim src/main.zig
然后再运行:
4、感受:编译、运行速度非常快,安装也方便呀。
|