Skip to content

Wollok v1.3 Confucius

Matías Freyre edited this page Jan 21, 2016 · 22 revisions

Upgrades

We have upgraded versions of many underlying core technologies used by wollok

  • Java from 1.7 to 1.8: so beware that you now need a JDK8
  • Xtext from 2.7.3 to 2.9.0: You will probably need to download the wollok IDE again, or install the plugins again in a new upgraded eclipse (Mars) if you manually installed it.
  • Eclipse from Luna to Mars: same as above

Language

Syntax

"inherits" instead of "extends"

We have changed the keyword that express class/WKO inheritance, instead of "extends" which has a broaden sense we now use inherits

class Dog inherits Animal {
   // ...
}

Catch type is now optional

You can have a catch block without specifying the type of the exception. In this case it will catch any wollok.lang.Exception (root class of all exceptions)

try {
    a.m1()
}
catch e
    console.println("blah")

New features

Coding Wollok in Wollok

We have done a very big refactor in the way Wollok implements "special" objects that comes with the language like booleans, strings, numbers, collections. Before v1.3.0 this where special object types that were part of the Wollok inner code. We have now modeled them in wollok language. They are part of the Wollok SDK library that is shipped automatically with Wollok language.

Here is a sample class diagram:

screen shot 2015-11-19 at 13 19 40

This means that all:

  • You can now browse this classes for wollokdoc and for the implementation.
  • other wollok mechanism like autocomplete or checks work for this basic objects
  • Wollok Interpreter code is now more consistent.

Objects can now inherit from classes which require a constructor call

Well-known objects can now inherit from classes which don't have a default constructor, and therefore require you to explicitly call a super constructor

screen shot 2015-10-21 at 23 41 00

VarArgs (Variadic functions)

A method can now declare that its last parameter is a vararg, which means that it can be called with a variable number of arguments, from 0 (zero) to "N".

Wollok will automatically wrap all those arguments in a list and call the method. So, from the method implementation point of view is just a list.

Here is a sample method declaration

screen shot 2015-11-26 at 22 44 11

Notices that it is a regular parameter followed with three dots. This are all valid calls

s.preffix("a", 1)
s.preffix("a", 1, 2)
s.preffix("a", 1, 2, 3)
s.preffix("a", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)

Checks / Validations

We added several new static checks for errors and warnings that should really improve the experience working with Wollok. They should now catch errors sooner during coding instead of later in runtime with weird error messages and exceptions.

Check messages to Well-Known Objects

Similar to what the checker does to messages sent to "this", now it also validates messages to well-known objects (named objects, those defined with 'object x { ... }'

screen shot 2015-10-13 at 22 29 13

Check non-return method usage

In some cases, Wollok can detect that the corresponding method at a message sending does not return a value when it's expected to do it, according to the message sending context. For example, when the hypothetically returned value is assigned to a variable or is a part of another expression. For the moment (without using the type system) those are:

  • messages sent to this
  • messages sent to super
  • messages sent to well-known objects

In such a cases Wollok will now check if you are trying to use the return value of the message, and if it finds out that you are expecting a value but the method won't produce any value (doesn't have a return statement or uses the shorthand for methods returning a value) it will produce an error.

screen shot 2015-10-13 at 23 31 18 In this case "eat" doesn't return any value

Warn for missing return on methods

It's a common pitfall to forget the return statement. The checker now analyses the methods' body and, if they seems to be generating a value but the method is not returning it, it will raise a warning.

screen shot 2015-10-14 at 15 02 56 screen shot 2015-10-14 at 15 03 06

Must return on every possible flow

Now methods that have a return statement are analysed to make sure you are returning values on every possible flow.

screen shot 2015-11-13 at 12 28 00

Unreachable catch blocks

The try catch with more than one catch blocks is now being checked to see if some of the catches are being hidden by a previous catch block

For example:

	try {
			a.m1()
			assert.fail("Should have thrown exception")
		}
		catch e : AException
			assert.fail("incorrect catch !")
		catch e
			console.println("blah")
		// XPECT errors --> "Unreachable catch block" at "e" 
		catch e : BException
			assert.fail("incorrect catch !")

Here BException catch is unreachable since BException is a subclass of AException

Check imports

Imports are now being checked to make sure they are valid. This checking is still limited. For the moment it just checks whether the file (the first segment of the package is defined by the file name) is valid.

wollok-check-imports

Quick-Fixes

In order to make it fun working in Wollok for more advanced developers, we have added new quick fixes for static checks, which should improve development experience and speed.

Create method on Well-Known Object if it doesn't exist

For the new check of messages to WKO we provide a quick fix to create a new method. It currently only works for objects defined in the same file.

screen shot 2015-10-13 at 22 34 43

Add return keyword when missing

In case you forgot it screen shot 2015-11-19 at 13 13 33

Exceptions

Exception handling has been improved a lot. Now there should only be a minimum number of scenarios where you will see a really long "java stack trace". Instead, you should now see a Wollok stack-trace similar to the following screenshot (if not, please report a bug ;) )

screen shot 2015-12-01 at 09 49 13

IDE

We have made some majors improvements to the Wollok IDE (meaning the more visual concerns).

I18N for Spanish

Wollok bundle now contains the eclipse spanish language pack by default. This means that when you run it in spanish (because of your locale or specifying the option "-nl es") not only the wollok specific parts will be in spanish but the whole product and eclipse platform will also be in spanish.

Here are some screenshots

screen shot 2015-12-11 at 15 46 55 screen shot 2015-12-11 at 15 47 10

Code Navigation for Messages -> Methods

Now you can navigate certain messages to methods with CTRL+click or F3

wollok-navigate-messages

For the moment this only works for messages being sent to:

  • this
  • super()
  • well-known objects

Resolving any message will require to have a type system.

Content Assist

Autocomplete for Messages to this and WKOs

The content assist now got more clever. It will propose you real messages you can send to:

  • this
  • well-known objects

Example messages to this screen shot 2015-10-15 at 11 12 41

Messages to WKO screen shot 2015-10-15 at 11 12 53

In case you are sending a message to any other object besides this and a WKO, it will only show you the list of messages you already sent to that variable within the context. Which is the best we can do without a type system.

Autocomplete based on reference initialisation

Wollok now analyses the reference initialisation to find out the expected (potential) type of the variable. Then it uses that information to create the autocomplete with methods belonging to the resolved type. This is a very basic type inference mechanism. Currently, it only works on the most simple cases where the reference is assigned with a literal object or a call to a constructor:

Examples here

  val a = "abc" // wollok.lang.String
  val a = 2 // wollok.lang.Integer
  val a = 2.1 // wollok.lang.Double
  val a = #[1, 2, 3] // wollok.lang.List
  val a = #{1, 2, 3} // wollok.lang.Set
  val a = console // console object
  val a = new Bird() // Bird

Potential match based on other parameters

If you are trying to send a message to a parameter, then we will analyse other methods of the current class/object and if we find a parameter with the same name, we will propose you the same messages as the ones you are sending on that other method.

Here is an example:

screen shot 2015-10-21 at 22 54 48

Autocomplete for imports

Besides checks, we also have autocomplete for imports now.

screen shot 2015-11-28 at 10 17 35

Static Diagram

Show relation between WKO and its superclass

It now shows the inheritance relationship between a Well-Known-Object and its super class screen shot 2015-12-07 at 17 50 43

Show referenced classes outside of the current file

It also shows the whole inheritance chain even if the classes are outside of the current file. screen shot 2015-12-07 at 18 16 12

Eclipse customization

We started to customize the eclipse to cut-off some advanced features that will probably confuse newcomers and students. For the moment we have tailored down the wizards options to the following

screen shot 2015-12-13 at 14 21 44

REPL

Syntax Highlight

The REPL console now has syntax highlighting. This is useful to differentiate the input lines from the output given by the wollok REPL (interpreter). It also highlights errors, and tries to highlight the input code you write in a similar way as the text editor (keywords, strings, variables, etc)

screen shot 2015-10-16 at 23 00 37

Part of the highlighting is actually done at the REPL size, so if you run the REPL from a console you will still see colors. Although not the full highlight as you will see in the Eclipse. Here is a sample with a bash console

screen shot 2015-10-15 at 16 32 21

Export Session as Test

There's a new button on the REPL console, which allows you to export the current session as a Wollok test. It doesn't export the whole history (which is longer than the current session), only the lines you just wrote on this session.

screen shot 2015-10-20 at 23 55 03

Here is a sample generated test

screen shot 2015-10-20 at 23 55 14

Wollok Game

Starting from this release we are including and shipping "wollok game" along with Wollok. WollokGame is a project implemented by Nahuel Palumbo, Juan Contardo and Carlos Raffellini as part of their Grade Thesis.

This is the start of a new working line for wollok to provide a level of "gamification" to the OOP learning experience. It is not an attempt to provide a framework to developers/students to code complete "games", but a way to easily have a graphical interface for domains.

Here are some screenshots:

wgame-sokoban

And

wgame-farmville

We want the student/developer to focus on the domain model behaviour and not geometry or graphical concerns. Still we want their domains to look and behave like in a game. So part of this research line is to try and test different approaches for this.

You can take a look at some sample game prototypes from this github repository

https://github.com/ProyectoFinal2015/ejemplos-wollok https://github.com/javierfernandes/wollok-wakman

Issues

Here is the complete set of issues solved in this release

https://github.com/uqbar-project/wollok/issues?q=is%3Aissue+milestone%3A%22Wollok+v1.3+Confucius%22+is%3Aclosed

Clone this wiki locally