Hacker News new | ask | show | jobs
by dpedu 974 days ago
I think you're looking at this basic snippet and taking it for something it's not. Not shown in this example and considered best practice are:

- Defining and validating data structures passed in; type doesn't have to be a basic type, it can be complex objects

- Default value

- Input validation criteria

So, with a real world example this is still going to be less verbose than the java equivalents.

2 comments

Sorry, won't back down that HCL is junk. When it is easier to not do best practices in examples, then you're off on the wrong foot to begin with.
I could point out how it's way, way easier in java programs, since we're picking on java, to skip over doing things like this. Or I could point out how the bar to do things correctly is lower in this hcl example than the equivalent java. Or I could point out how the things I named as best practices can look in the real world, which seems to be the best course of discussion since unfamiliarity seems to be an issue here:

You have a type defined, it's just string. There's no default, which means it's a required input. Required inputs obviously can't have a default. Arbitrary strings are a perfectly acceptable input and without seeing how that variable is actually used, I can't speculate about validation criteria and it is very reasonable that for arbitrary strings there are none.

It's also interesting that this is also a valid variable definition which does the same thing, but without the bells and whistles:

  variable "name" {}