Monday, February 12, 2018

Groovy: Basic Concepts

In presenting a new programming language, there are a number of basic concepts that are common to all programming languages.  What is different is the way they are expressed.  These basic concepts include:

  • Values and Types - how the programming language defines the data types it uses and how it manages storing values.
  • Expressions - statements and elements that express a concept in the language.  These can include things like literals, iterative expressions and built in function calls
  • Variables, Storage and Commands - This section combines managing simple and composite variables as well as several command types, such as if/then and switch/case
  • Bindings and Scope - in a programming language, when a programmer defines a variable two key bindings occur: the variable name to the value and the variable name to its type.  Once this happens, how long the variable stays bound is governed by scope.
  • Procedural Abstraction - when building an application or program, there will be a need to encapsulate functionality into reusable blocks.  This is called procedural abstraction and can include functions and methods, plus the arguments provided to them.

Before beginning, a few key concepts and items to understand:

At its core, Groovy is a Java-based language. Because it targets the Java Virtual Machine as its runtime environment, it derives much of its syntax and capabilities from the native Java language. However, it provides a set of extensions that allow it to offer additional capabilities not found in the core Java language specification.

These include closures, optional typing, scripting capabilities and functional programming. This section will review the basic elements of the Groovy language, specifically trying to point out where the Groovy language differs from Java.

One key item of note, especially when reading the following examples, Groovy treats the ';' line terminator as optional, so most of the examples omit it for brevity.

No comments: