BOO语言和基础 5

简介: Boo is an object-oriented, statically typed programming language for the Common Language Infrastructure (CLI) with a Python-inspired syntax and a spe...

Boo is an object-oriented, statically typed programming language for the Common

Language Infrastructure (CLI) with a Python-inspired syntax and a special focus on

language and compiler extensibility. It’s this focus on extensibility that makes it ideally

suited for building DSLs.

Boo is not just a CLR language; it’s also a JVM language–BooJay

 

http://boo.codehaus.org

特点

BooManifesto.pdf

Ø Syntactic sugar for common programming patterns

Ø Automatic variable declaration and type inference

Ø Automatic typecasting

Ø Duck typing

http://boo.codehaus.org/Language+Guide)

Boo能干哪些事的参考

http://docs.codehaus.org/display/BOO/Useful+things+about+Boo

关键特性

Boo’s language-oriented features

Ø String interpolation

name = "dear reader"

print "Hello ${name}"

Ø Is, and, not, and or

customer.CurrentPlan is null and customer.RegisteredAt>SixMonthsAgo

Ø Optional parentheses

SuggestRegisterToClub("Preferred")

SuggestRegisterToClub "Preferred"

Ø Anonymous blocks

ints = GetListOfIntegers()

ints.ForEach do(i): print i

ints.ForEach:

print "foo"

Ø Statement modifiers:turn several statements into a single sentence有:if, unless, and while.

ApplyDiscount(0.5) if customer.IsPreferred

apply_discount_of 0.5 if customer.IsPreferred

Ø Naming conventions

multiple names for a single method is to extend the Boo

compiler in such a way that it automatically translates from one naming convention to

the other

Ø Extension methods

System.String:

classStringExtensions:

[Extension]

staticdefToPascalCase(str as string):

returnchar.ToUpper(str[0]) + str.Substring(1)

使用

importStringExtensions

"some string".ToPascalCase()

Ø Extension properties

classListExtensions:

[Extension]

static Length[list as IList]:

get:

returnlist.Count

importSystem.Collections

importListExtensions

a = ArrayList()

printa.Length

Ø The IQuackFu interface

If it walks like a duck and it quacks like a duck, then it must be an IQuackFu.

Otherlanguages call it duck typing or method missing (or message not understood) and

many dynamic languages support it.

Duck typing basically means that you don’t care what the actual type of an object is.

As long as it supports the operations you need (as long as it walks like a duck), you can

treat it as a valid object (it is a duck).

Rails’ ActiveRecord:

user as User = Users.FindByNameAndPassword("foo", "bar")

That will be translated by the compiler to this:

user as User = Users.QuackInvoke("FindByNameAndPassword", "foo", "bar")

 

Boo interactive shell

Boo interactive shell by just entering booish.exe

Boo interpreter

booi test1.boo

Boo compiler

booc test1.boo

http://home.comcast.net/~brent.hughes/BooWho.htm

控制语句结构

if<BooleanExpression>:

<StatementBlock>

elif<BooleanExpression>:

<StatementBlock>

<moreelif's>

else:

<StatementBlock>

while<BooleanExpression>:

<StatementBlock>

for<Variable> in <RangeOrSequence>:

<StatementBlock>

List Array Hash

a = [4, 9.82, "Help"]

MyArray = (3, 5, 7, 9)

MyStrArray = ("one", "two", "three")

MyHash = { "Susan":3, "Melanie":9, "Cathy":27 }

 

关于DSL 可以参考前面的几个文章 

相关文章
|
程序员 编译器 Linux
V 语言
V 是一门通用的编程语言,也可以作为系统语言,其网站说它非常简单,你可以在一个周末学会,它还说 Go 程序员会对该语言非常熟悉,因为 V 语言在很多方面借鉴了 Go。
231 2
|
JavaScript 前端开发 Unix
1.C 语言简介
1.C 语言简介
181 0
|
Rust 前端开发 JavaScript
2023年语言和框架我们值得关注什么?
前端新技术一如既往的更新迭代快:前几天 Next.js 大会,邀请了 vercel 的 CEO 来讲 vercel 的认知。顺带推出了 turbopack,号称比 webpack 快 700 倍,比 vite 快 10 倍。又有很多前端同学在问,我们要学 Rust 了吗?新的内容更新迭代太快了,我们跟不上?今年的终端 D2 会有哪些内容?会不会讲 Rust?
226 0
|
C语言 C++
C 和C++语言的标准
C 和C++语言的标准
362 0
|
Rust 前端开发 JavaScript
2022年语言和框架我们值得关注什么?
前端新技术一如既往的更新迭代快:前几天Next.js大会,邀请了vercel的CEO来讲vercel的认知。顺带推出了turbopack,号称比webpack快700倍,比vite快10倍。又有很多前端同学在问,我们要学Rust了吗?新的内容更新迭代太快了,我们跟不上?今年的终端D2会有哪些内容?会不会讲Rust?
149 0
|
存储 开发框架 Cloud Native
【C#基础】初识编程语言C#
编程语言C#和.NET平台的介绍以及如何写出自己第一个C#程序。
125 0
|
算法 Linux 程序员
我为什么建议大家一定的会 C 语言
我为什么建议大家一定的会 C 语言
2127 0
|
Java 开发者
快速掌握一个语言最常用的50%
现在的开发工作要求我们能够快速掌握一门语言。一般来说应对这种挑战有两种态度:其一,粗粗看看语法,就撸起袖子开干,边查Google边学习;其二是花很多时间完整地把整个语言学习一遍,做到胸有成竹,然后再开始做实际工作。
978 0

热门文章

最新文章