Could a programming language work as well without statements?

As programming in JavaScript, I’ve noticed everything that can be done with statements and blocks can be done with expressions alone. Can a programming language work fine with only expressions? And, if yes, why are statements used at all?

7

Sure. The simplest way is to assign a result value to every construct that’s currently a statement and thereby turn it into an expression. That’s not necessarily useful or meaningful though. The only potential gain is a bit of conceptual simplicity. However, if you then proceed to remove things like semicolons and loops (requiring chaining via other operators and functions instead), programs heavily using statements become ugly.

A more radical but meaningful way to do this is to design the language such that almost everything has a meaningful value, and use it in a way that you almost always use an expression for that meaningful value, not for other effects. Functional programming languages do this (to some degree; for example, Haskell has declarations, which aren’t expressions).

Statements are used because in the imperative paradigm, there are many common operations which don’t have a useful result value, and because the notion of sequential instructions (rather than calculations) fits that paradigm quite well. If a large percentage of your program is mutating state, rather than calculating new values, it doesn’t make sense to require producing a value (what’s the result of a for loop?). In contrast, when your entire paradigm (FP) is built around the calculation of values, outliers that don’t have a result value don’t warrant an exception: Instead you give them a sentinel result that doesn’t mean a thing.

7

Depends on how you define “statement” and “expression”.

A very strict definition would distinguish between statements as “things that have side effects, and maybe a return value” and expressions as “things that have return values, but cannot have side effects”. With such a definition, no meaningful program can be written without at least one statement (which would have to evaluate an expression and output its return value) – pure expressions alone cannot interact with the world outside the program. A language alone can still be completely pure (i.e., not have any statements), if the impure part is moved out of the language and into the supporting ecosystem (which is exactly what Haskell does, although the language has definitions as well as expressions).

If, however, you allow for side effects in expressions, then the distinction between statements and expressions becomes arbitrary and much less interesting – of course you can invent a programming language that consists of expressions only; most Lisp dialects work much like that. In such a situation, evaluating an expression for its side effects is pretty much exactly the same as executing a statement, and one could argue that in such a language, expressions and statements are the same thing. The difference between a statement and an expression, then, is only syntactic.

Many languages still make this syntactic distinction, because it is useful not for technical reasons, but for readability. Making something an expression signals that you are interested in its return value, less so its side effects; making it a statement tells the reader that you intend it to cause side effects, and the return value may or may not be interesting.

1

ATL and Xtend are statement-less well working programming languages. Many functional languages are also statement-less. So, yes a programming language can work fine without statements. I think statements are in many languages a relict from imperative programming. They are still used because they are widely known and for some cases they make code more readable.

Yes.

Functional languages (and single assignment languages) everything is an expression. Examples are Haskal (and SISAL). Where both if statements and for loops return values.

There are other classes of languages: The easy one that springs to mind is declarative languages (I am sure there are many others that don’t depend on statements). These languages don’t even need expressions (in the same sense as you would normally think). You declare what is true and you can get multiple results backs. The easy one here is prolog.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật