Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Mobile

Different styles for writing Hello World program in the Ring programming language

5.00/5 (4 votes)
28 Dec 2017CPOL2 min read 9.2K   20  
A quick look around the different styles in the Ring programming language!

 

Introduction

When we look at a new programming language, we start with the "Hello, World!" program. In Ring we can write this simple program with different styles that reflect the general scope of the language! The language documentation comes with three styles in the begining, In this article I will try to present all of the styles that we can use after learning the different aspects of the language!

Background

The Ring programming language is a dynamic programming language for Windows, Linux and macOS. Very similar to Python and Ruby, but brings a lot of features from BASIC too!, The new ideas in the language are related to domain-specific languages and using declarative and natural programming. It's free open source language.

Scripting

In Ring 1.0

(1)

C++
see "Hello, World!"

(2) Using nl we can print new line!

C++
see "Hello, World" + nl

(3) The language is not case-sensitive!

C++
SEE "Hello, World!"

(4) Using nl we can print new line!

C++
SEE "Hello, World" + nl

(5)

C++
See "Hello, World!"

(6) Using nl we can print new line!

C++
See "Hello, World" + nl

In Ring 1.1

(7)

C++
put "Hello, World!"

(8)

C++
put "Hello, World!" + nl

(9)

C++
PUT "Hello, World!"

(10)

C++
PUT "Hello, World!" + nl

(11)

C++
Put "Hello, World!"

(12)

C++
Put "Hello, World!" + nl

(13) Using the Standard Library "stdlib.ring"

C++
load "stdlib.ring"
print("Hello, World!")

(14) Using the Standard Library "stdlib.ring" and \n for new lines!

C++
load "stdlib.ring"
print("Hello, World!\n")

(15)

C++
LOAD "stdlib.ring"
PRINT("Hello, World!")

(16)

C++
LOAD "stdlib.ring"
PRINT("Hello, World!\n")

(17)

C++
Load "stdlib.ring"
Print("Hello, World!")

(18)

C++
Load "stdlib.ring"
Print("Hello, World!\n")

(19) In Ring 1.6 we can use ? as see <expr> + nl

C++
? "Hello, World!"

(20) We can write multiline strings

C++
? "
    Hello, World!
"

Procedural

We can use functions|procedures, the main function will be executed in the start of the program.

(1) First Style

C++
func main
   see "Hello, World!"

(2) Second Style

C++
def main
   put "Hello, World!"
end

(3) Third Style

C++
load "stdlib.ring"
func main() {
    print("Hello, World!") 
}

Classes

We can define a class, then create an object for this class!

(1) First Style

C++
new MyApp { main() }
class MyApp
   func main
      see "Hello, World!"

(2) Second Style

C++
new MyApp { main() }
class MyApp
   def main
      put "Hello, World!"
   end 
end

(3) Third Style

C++
load "stdlib.ring"
new MyApp { main() }
class MyApp {
   func main() {
       print("Hello, World!") 
   }
}

Web

The web library can be used from weblib.ring

We have the package System.web

This packages contains many classes that we can use for web development.

#!ring -cgi 
load "weblib.ring" 
import System.Web 
new page { 
	text("Hello, World!") 
}

Games

Games are based on Allegro and LibSDL

To use these libraries through the game engine, We have gameengine.ring

load "gameengine.ring" 
func main    
	oGame = new game {
    		title = "Hello, World!"    
	}

GUI (Desktop|Mobile) - using Qt

Desktop and mobile development are based on the Qt framework

To use this framework we will load the guilib.ring

load "guilib.ring" 
new qApp { 
	new qWidget() { 
		setwindowtitle("Hello World") 
		move(100,100) resize(400,400) 
		show() 
	}
	exec() 
} 

Natural

We can define new statments in the language, then use classes to implement our definition

The next example define Hello World as a new command!

new natural {
      Hello World
}
class natural 
         hello world
         func getHello ? "Hello"
         func getWorld ? "World!"

Points of Interest

Pros:

(1) Different styles that match programmers with different backgrounds

(2) The language could be used in different domains

Cons:

(1) All of these styles could be mixed in the same project!

(2) The language still new, A lot of libraries need more work!

History

Ring is a new programming language (just released in 2016)

The current version is Ring 1.6 (free open source - MIT License)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)