Learn to code?

Hi. New owner here, and eager to learn. I want to code…

I was by career a systems programmer for large Enterprise systems but also some PC and HTML dabbled.

So in reading the community forums many of the questions I have had been asked before of course, but many lead me down the rabbit hole to GitHub where I find code examples.

I can’t say I understand it all, but I’m very logical and like I said have many years experience.

But apparently I need to learn a new language. What’s the best way to learn? Resources, reading materials, etc?

Any help is appreciated, don’t be shy…

My suggestion is this (how I learn to code in a new language, including how I learned to program in Groovy). Take one of the simple apps from our public repo (https://github.com/hubitat/HubitatPublic/tree/master/example-apps), and modify it. See what the app does, and dream up something slightly different for it to do. Make that change, get it to work. Then sort of grow your modified app by adding additional features, modeling how they are coded based on other similar features. After a bit of this, try coming up with a new app, again using the examples to find snippets of code you need. Make extensive use of copy/paste.

Ask questions here as they come up. I or someone else will answer them. I highly encourage you to pursue this, it will start to pay off for you quickly.

10 Likes

Good start, I just learned it’s called Groovy. And your suggestion is certainly a good way to progress. But I think I need a base, like learning syntax, objects, etc…

Do I just search for a Groovy tutorial or do you have a recommendation?

There are a zillion online resources for Groovy. Check some out, and see if any of them 'fit' your way of thinking, based on your experience. You will actually learn more about syntax by looking at examples than by reading. Groovy is very flexible. As a beginner this helps.

Objects: pretty simple. The obvious scalar things like integers, decimals, characters, strings, Boolean (true and false). There are Lists (simple array indexed by integers, starting with 0) and Maps for more complex objects. You can define pretty much anything generically by using 'def', as in:

def myNumber = 14
def myName = "Bruce"
def pi = 3.14159
def myList = ["apple", "orange", "grapes"]
def truth = true

More formally these would be done with specifying the type, although this isn't required:

int myNumber = 14
String myName = "Bruce"
float pi = 3.14159
List myList = ["apple", "orange", "grapes"]
Boolean truth = true

See this: Groovy Tutorial

6 Likes

The official groovy documentation is good, you should look it over:

http://www.groovy-lang.org/documentation.html

5 Likes

You might these YouTube tutorials from @adamkempenich useful:

3 Likes

Just be sure to look at version 2.4, which Hubitat uses. :slight_smile:

https://docs.groovy-lang.org/docs/groovy-2.4.21/html/documentation/

There aren't many notable changes (in later versions) in terms of what might affect the Hubitat sandbox, aside from a syntax addition or two and some methods that were added, but it's still probably worth knowing.

6 Likes

This is great guys, thanks so much!

1 Like

Download the Hubitat app