Vala:陷阱、提示和技巧

发布于 2024-08-19 20:46:14 字数 45 浏览 6 评论 0原文

作为一名刚接触 Vala 的程序员,您对刚接触该语言的人的第一条建议是什么?

As a programmer who is new to Vala, what is your number one piece of advice to someone who is new to the language?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

小霸王臭丫头 2024-08-26 20:46:14

这很大程度上取决于您来自什么背景。如果您来自 C/C++/Java,最好的建议是学习函数式编程。 Vala 支持真正的闭包,因此您应该(深入)学习如何使用 lambda 表达式。最好的资源是 Abelson 和 Sussman 的《计算机程序的结构和解释》。多年来,它一直是 MIT 的计算机科学入门教材。可在 http://mitpress.mit.edu 在线免费获取/sicp/full-text/book/book.html,但纸质版本更具可读性。视频讲座可在 http://groups.csail.mit .edu/mac/classes/6.001/abelson-sussman-lectures/。问题集可在 http://icampustutor.csail.mit.edu/6.001-public/ 上免费获取

除此之外,我通常只是尝试学好 C# 编程风格。它与 Vala 类似,但有很多关于该主题的书籍。

问题:

  • 请注意 Vala 没有垃圾收集功能。它进行引用计数。
  • 请注意,Vala 仍在开发中。它是一种相当新的语言,还没有达到 1.0。您现在编写的代码将来可能会崩溃。
  • 如果选择学习 Vala,请注意,就编程语言概念而言,它有点过时了。它对多核编程没有任何帮助。它不会做任何事情来帮助内存管理(代码性能主要基于缓存一致性——好的垃圾收集语言可以重新组织内存来帮助这里)。它是 C 的包装,并且具有许多 C 的限制(尽管它确实添加了闭包)。

另外,其中一张海报推荐了tinycc。对于开发来说这是一个合理的选择,但是您应该使用 gcc 等优化编译器(或者如果支持,则使用英特尔编译器)进行部署。

It largely depends on what background you are coming from. If you're coming from C/C++/Java, the best bit of advice is to learn functional programming. Vala supports true closures, and so you should learn (deeply) how to use lambda expressions. The best resource for this is Structure and Interpretation of Computer Programs by Abelson and Sussman. It was the introductory textbook for CS at MIT for many years. It is available free on-line at http://mitpress.mit.edu/sicp/full-text/book/book.html, but the paper version is more readable. Video lectures are available at http://groups.csail.mit.edu/mac/classes/6.001/abelson-sussman-lectures/. Problem sets are available free at http://icampustutor.csail.mit.edu/6.001-public/.

Aside from that, I'd generally just try to learn the C# programming style well. It is similar to Vala, but there are many books on that topic.

Catches:

  • Be aware Vala doesn't have garbage collection. It does reference counting.
  • Be aware that Vala is still being developed. It is a rather new language, and it has not reached 1.0. Code you write now may break in the future.
  • If choosing to learn Vala, be aware that it is slightly obsolete, as far as programming language concepts go. It does not do anything to help with multicore programming. It does not do anything to help with memory management (code performance is based largely on cache coherency -- good garbage collected languages can reorganize memory to help here). It is a wrapper around C, and comes with many of C's limitations (although it does add closures).

Also, one of the posters recommended tinycc. This is a reasonable choice for development, but you should use an optimized compiler like gcc (or if supported, Intel's compiler) for deployment.

酒儿 2024-08-26 20:46:14

我的第一条建议是了解 GObjects。它们是 Vala 强大功能和灵活性的支柱,学习如何用 GObject 包装各种库可以让您的 Vala 程序访问 c 可以链接的所有内容(数量很多!)。

以下是一些您可能感兴趣的链接:
* http://library.gnome.org/devel/gobject/stable/< br>
* http://fosswire.com/post/2009/7/gobject-vala/< /a>
*
http://developer.gnome.org/doc/tutorials/#gobject< br>
* http://en.wikipedia.org/wiki/GObject

My #1 piece of advice is to learn about GObjects. They are the backbone of Vala's power and flexibility, and learning how to wrap various libraries with GObject gives your Vala programs access to everything c can link against (which is a lot!).

Here are a few links that might be of interest:
* http://library.gnome.org/devel/gobject/stable/
* http://fosswire.com/post/2009/7/gobject-vala/
* http://developer.gnome.org/doc/tutorials/#gobject
* http://en.wikipedia.org/wiki/GObject

超可爱的懒熊 2024-08-26 20:46:14
  1. 对于多个资源,这将是一个通用资源:Vala - GNOME Live!
  2. 要近距离接触 GObject:GObject 参考手册
  3. 我不知道您来自什么背景,但您会发现这很有帮助:Vala 快速介绍C# 程序员

无论如何,C 知识都会很有用。我们的团队实际上正在考虑进行渐进式改造并移植到 Vala。我们的成员在 C#/C++ 方面具有深厚的背景,这种方向的改变(随着时间的推移)将有利于我们产品的性能和灵活性。

  1. For multiple resources, this will be a general resource for a bit: Vala - GNOME Live!.
  2. To get up close and personal with GObject: GObject Reference Manual.
  3. I don't know what background you're coming from, but you will find this helpful: Vala Quick Intro for C# Programmers

In any event, knowledge of C will be of great use. Our team is actually considering a progressive revamp and porting to Vala. We have members with strong backgrounds in C#/C++ and this change in direction (over time) will be beneficial to the performance and flexibility of our products.

我是男神闪亮亮 2024-08-26 20:46:14

提示:通过使用 TinyCC 而不是 gcc 进行开发,您可以显着加快构建时间。 Vala 使用 CC 环境变量来选择后端编译器,因此“export CC=tcc”就可以了。

Tip: You can speed up your build time significantly by using TinyCC instead of gcc for development. Vala uses CC env variable for selecting backend compiler, so "export CC=tcc" will do the trick.

不念旧人 2024-08-26 20:46:14

这是我给你的提示:阅读官方文档。 :)

Here's my tip for you: Read the official documentation. :)

等你爱我 2024-08-26 20:46:14

一般来说,Vala 非常优秀,但我发现的一个大问题是,与该语言的其他部分相比,它对数组的处理非常原始,或者它的文档中有一个很大的漏洞。

尽管通过文档、教程和 Google 进行了长时间的艰苦研究,我得出的结论是:

  • 连接两个数组的唯一方法是 退回到 C 风格技巧 或使用 foreach+=手动将一个数组逐个元素添加到另一个数组。
  • 你可以做像 argv[1:-1] 这样的切片,但似乎没有相当于 Python 的 argv[1:] 的语法,所以你必须回退一些更程序化
  • Libgee 对我来说毫无用处,因为虽然 Gee 对象具有类似 add_all,它们都不采用C风格数组,所以我又开始使用 addforeach+=

Generally, Vala is excellent, but the one big gotcha I've found is that either its handling of arrays is very primitive compared to the rest of the language or its documentation has a very gaping hole in it.

Despite a long, hard look through the documentation, tutorials, and Google, I've concluded that:

  • The only way to concatenate two arrays is either to fall back to C-style tricks or use foreach and += to manually add one array to the other element-by-element.
  • You can do a slice like argv[1:-1] but there seems to be no syntax for equivalent to Python's argv[1:], so you have to fall back to something more procedural for that.
  • Libgee is useless to me because, while Gee objects have methods like add_all, none of them take C-style arrays, so I'm back to using add with foreach and +=.
三岁铭 2024-08-26 20:46:14

警告:我不熟悉 Vala,但希望我的答案适用于学习任何新语言。我只是想提供一些想法,以防它们有所帮助......我绝对不应该因为我的答案而获得赏金。

底线:这取决于您学习它的原因...

如果您因为它是一门很酷的新语言而感兴趣,但您不确定如何在实践中使用它,请尝试重新创建/移植您非常熟悉的东西看看比较如何。

如果您学习它是因为您相信它可以解决您面临的特定问题,请确保它值得前期投资,因为学习任何新语言都可能非常耗时,并且在更熟悉的语言中可能有合理的解决方案语言。

否则,一切都取决于你如何学得最好。您是需要了解语言内部原理,还是只是需要快速完成工作的人? (或者,像我一样,介于两者之间?)对于完成工作的方法,我只是寻找简单的教程,并尝试让一些基本的东西启动并运行,看看感觉如何。如果我喜欢这门语言,那么我将开始阅读有关该语言的更深入的信息并了解其幕后情况。

无论您采取什么方法,祝您好运!

Caveat: I am not familiar with Vala, but hopefully my answer applies to learning any new language. I just want to offer some thoughts in case they help...I should definitely not get the bounty for my answer.

Bottom line: It depends on why you are learning it...

If you are intrigued because it is a cool new language, but you are not sure how you might use it in practice, try recreating/porting something with which you are deeply familiar to see how it compares.

If you are learning it because you believe it solves a specific problem you are facing, make sure it is worth the up-front investment, since learning any new language can be incredibly time consuming, and there may be a reasonable solution in a more familiar language.

Otherwise, it's all about how you learn best. Are you someone who needs to understand the internals of the language, or just get things done quickly? (Or, like me, somewhere in the middle?) For the getting things done approach, I just look for simple tutorials and try to get something basic up and running to see how it feels. If I am enjoying the language, then I'll start to read more in-depth information about the language and understand what's going on under the hood.

Whatever your approach, best of luck!

月亮坠入山谷 2024-08-26 20:46:14

我的建议是阅读文档,但我个人是通过查看 vala 代码示例来学习该语言的:

官方 vala 教程

一些文档

vala 教程对我帮助很大,文档页面包含很多有用的例子,但对我帮助最大的一个网站是 valadoc.org:

valadoc.org

valadoc 会给你很多帮助其他库也具有不同的类和函数。

vala 与 C# 非常相似,但您也会经常看到类似 java 的接口。任何使用 C 的经验都是好的,因为 vala 周围的所有库都是用 C 编写的,并且在调用函数时,您几乎可以看到表面之下的所有 C 代码。

对于那些说 vala 太年轻的人:vala 将继续像现在一样年轻,直到有人制作一个非常大的文档或启动一个像 QT 这样大的项目,每天都有成千上万的人提出问题。

由于文档不好,vala 一开始有点难学,但不要放弃!当你学习了它的基础知识后,它就是一门很棒的语言。祝你好运!
抱歉英语不好:)

my advice would be to read the documentation but i personally learned the language by looking at vala code examples:

The official vala tutorial

some documentation

the vala tutorial helped me alot and the documentation page contains alot of useful examples but the one site that helped me most was and still is valadoc.org:

valadoc.org

valadoc will help you alot with the different classes and functions also other librarys.

vala is very c# alike but you will often see java like interfaces too. any experince with C is good because all the librarys around vala is written in C and when calling functions you can almost see all the C code that is right under the surface.

for those people that say vala is too young: vala will continue to bee as young as it is now until somebody makes a VERY big documentation or starts a project as big as QT where thousands of people ask questions everyday.

vala is a little hard to learn in the start because of the bad documentation but don't give up! it's a great language when you have learned it's basics. good luck!
and sorry for the bad english :)

满天都是小星星 2024-08-26 20:46:14

如果您正在考虑使用 Vala 编写服务器应用程序,那么您可能会喜欢 Aroop 中的一些对象池功能(对象令牌功能) 。 Aroop 是一个 Vala 分支,负责内存池。它有引用计数垃圾收集器。您可以在此处找到功能列表。让我在列表中列出一些目标,

If you are considering Vala to write a server application then you may like some object pooling features(object token feature) in Aroop. Aroop is a Vala fork that does memory pooling. And it has reference counted garbage collector. You may find a list of features here. Let me name some of the goals here in list,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文