News for hackers. Stuff that matters.
Re:TypeScript 3.6 by benatkin on Wednesday August 28, 2019 @05:29PM (#20824168)
I've noticed there's a lot of talk on twitter about making TypeScript be an agreed upon best practice for frontend web developers. I'm glad TypeScript is doing well because there are certainly a lot of talented and dedicated developers working on it, but I really don't want to use static typing, even if there is a lot of type inference happening. I will need to make sure I don't plan on finding job or gig opportunities at the types of companies that are going require the use of TypeScript.
Re:TypeScript 3.6 by root_axis on Wednesday August 28, 2019 @06:26PM (#20824690)
A proper type system offers a level of safety and correctness that simply cannot be achieved without one, especially as the complexity of an application grows. Also, the supposed lack of cognitive overhead without a type system is actually a subtle form of technical debt where you move faster because you eschew thinking deeply about your data structures up front, but inevitably pay a bigger price in production when you have to debug data type errors at run-time. The debt has to be paid again by every new developer tasked with working on the project because they have to organically absorb an understanding of the application's data structures that could have been explicitly defined and enforced by the computer. Finally, the extent of defensive programming required to begin to make up for a type system actually adds a ton of extra code itself (e.g. tons of guard blocks testing brittle application values at run time). Not all type systems are created equally, but a code base without types is pretty much always worse than a comparable one with types (the exception being shell scripts and other relatively simple programs that aren't maintained by a team of developers)
Re:TypeScript 3.6 by 2bitencryption on Wednesday August 28, 2019 @05:36PM (#20824238)
> I will need to make sure I don't plan on finding job or gig opportunities at the types of companies that are going require the use of TypeScript.

If you're really dynamic, the type of company won't matter, right :)

Re:TypeScript 3.6 by benatkin on Wednesday August 28, 2019 @05:46PM (#20824334)
It's generally pushing towards the type of projects I want to work on anyways, with small codebases, and things broken down into components, and lots of freedom in how to implement things.
Re:TypeScript 3.6 by vnorilo on Thursday August 29, 2019 @01:59AM (#20827036)
Sounds like you might enjoy Lisps even more (clojurescript for frontend?). In my experience, that's the pinnacle of dynamically typed.
Re:TypeScript 3.6 by sqs on Wednesday August 28, 2019 @05:32PM (#20824200)
Do you believe static typing is harmful (to the type of company you want to join), or is this a personal preference (which is totally valid)? Honestly curious.
Re:TypeScript 3.6 by lewisl9029 on Wednesday August 28, 2019 @05:59PM (#20824462)
I've found that the kinds of errors that static typing guards against are often things that would have been trivial to debug and fix in the first place (mostly things like typos).

Given that you have a good system for monitoring errors in production and a low friction deploy process so you can quickly and easily fix errors when you discover them, I feel these kinds of errors are honestly not worth guarding against in most contexts outside of those where getting everything perfectly right the first time is a hard requirement (health, fintech, other safety-critical industries, etc).

Of course, most companies lack either or both of these ( a good system for monitoring errors in production and a low friction deploy process), so they use static typing as a clutch to try to reduce the chance of errors making it into prod simply because they know they'd be slow to fix/detect those errors. That's a poor reason to choose static typing IMO, but I think that's by far the most common reason.

Re:TypeScript 3.6 by koolba on Wednesday August 28, 2019 @06:36PM (#20824773)
> I've found that the kinds of errors that static typing guards against are often things that would have been trivial to debug and fix in the first place (mostly things like typos).

Sure but unless you have coverage of all error cases, it’s nice to have that check at build time vs some untested corner case in production.

> Given that you have a good system for monitoring errors in production ...

Runtime errors are a totally different beast.

> ... and a low friction deploy process so you can quickly and easily fix errors when you discover them, I feel these kinds of errors are honestly not worth guarding against in most contexts outside of those where getting everything perfectly right the first time is a hard requirement (health, fintech, other safety-critical industries, etc). Of course, most companies lack either or both of these ( a good system for monitoring errors in production and a low friction deploy process), so they use static typing as a clutch to try to reduce the chance of errors making it into prod simply because they know they'd be slow to fix/detect those errors. That's a poor reason to choose static typing IMO, but I think that's by far the most common reason.

Fixing things earlier is cost effective regardless of your deploy speed. Sure it’s worth more the longer the cycle, but not having to run unit tests because the compiler knows “foo” is not “fo0” saves time as well.

Re:TypeScript 3.6 by lenkite on Thursday August 29, 2019 @02:14AM (#20827099)
I have found the main advantage of static typing being easy, convenient refactoring. I never get my design or code to be just "right" the first time. I get the naming wrong, the functions too big, the design a bit skewed. I need to do a couple of passes, refactoring to get it in a tight shape. And statically typed languages give you tools to refactor with confidence.

This is one of the advantages of typescript over a language like clojurescript.

Re:TypeScript 3.6 by lewisl9029 on Wednesday August 28, 2019 @07:01PM (#20824948)
That's totally fair.

I'm not saying detecting errors earlier through static typing has no value of course. Just that there is a spectrum of value a team can derive from static typing that scales based on the length of their deploy and error detection cycle, and at the lower ends of that scale it's not always clear that static typing provides enough of value to justify its costs.

And that if a team doesn't already have them, investing to minimize the deployment and error detection cycle is often much more valuable than investing in static typing because it's an effective tool for both dealing with runtime errors as well as errors that could have been statically determined.

Re:TypeScript 3.6 by BigJono on Thursday August 29, 2019 @01:28AM (#20826905)
One thing nobody likes to mention much is that the value of a type system also scales pretty heavily with the quality (or lack thereof) of developers using it.

For a small team full of talented engineers (e.g. a startup) it's not unreasonable at all to just... not make typing errors. I've put 5+ large apps into production in the last decade and could probably count on one hand the number of times I've really struggled with something type related.

There's certain anti-patterns that make up the majority of type-related problems in JS. Things like inconsistently mix 'n matching falsey types, adding or removing properties from objects in unpredictable ways, or leaking stringified numbers and bools everywhere.

Other classes of type problems can be solved in dynamic languages by structuring code in more self-documenting ways and properly augmenting any remaining ambiguity with comments.

If your team is naturally coding in a way that respects the dynamic typing of the language then your benefits from TS are going to be much more marginal, and that needs to be taken into account when comparing the costs and benefits of it.

My guess is that we'll see a harder split in the JS community in the next few years. Most people are going to drift towards only taking on TS or JS roles in much the same way most JS programmers wouldn't take a lisp or C# job at the moment.

Re:TypeScript 3.6 by hderms on Thursday August 29, 2019 @01:26AM (#20826899)
I've worked in a number of languages and fwiw I've never written such error-free code as I have in Scala when embracing the type system (to a reasonable degree) and embracing immutability/fp patterns. We write only the tests that truly matter, something I've never felt is possible in a dynamic language as I personally feel you need lots of tests which are more or less provided for free by the type checker.
Re:TypeScript 3.6 by cdeutsch on Wednesday August 28, 2019 @06:32PM (#20824751)
I used to think like that, until I was forced to use TypeScript at a new company.

Now I avoid using regular JavaScript.

I'm impressed how many bugs it prevents, and it prevents them early.

Refactoring in TypeScript is literally magnitudes easier and quicker.

Re:TypeScript 3.6 by siempreb on Thursday August 29, 2019 @05:20AM (#20827980)
> I used to think like that

Such arrogance.. ..and unfortunately so typical for TS proponents..

Re:TypeScript 3.6 by almostdeadguy on Wednesday August 28, 2019 @06:18PM (#20824636)
I think “debugging errors in prod” is not generally how I like to spend my working life, with or without excellent logging and tooling for surfacing errors.
Re:TypeScript 3.6 by lewisl9029 on Wednesday August 28, 2019 @06:54PM (#20824898)
How this works in practice is usually 1) deploy some change, 2) errors start showing up that correspond to that change, 3) click a button to revert the change instantaneously (some systems can even do this automatically), 4) debug the change in dev
Re:TypeScript 3.6 by root_axis on Wednesday August 28, 2019 @08:59PM (#20825686)
Monitoring is a tool to help you know when something is already broken, it does nothing to prevent problems, unlike a type system. If your error rates are spiking in production then real customers are getting a bad experience with your product, i.e. hurting sales, your brand image, and generating more work for your colleagues in the form of customer-support tickets that a human still needs to resolve even though you "instantaneously" rolled back the changes.

It's also common to encounter errors in production that are difficult to reproduce in the development environment, this is especially true of data-type errors in dynamic languages where some unusual edge case creates a strange data structure that would simply be impossible with static types.

There's also a chance that the developer fixing the code didn't actually fix it and instead only introduced enough guard logic to handle that one specific case based on their best guess regarding the shape of data that can come through, thus redeploying with a 30% error rate instead of a 60% one, repeating the cycle of attrition testing against the production environment until the error rate is "noise" but maybe not completely fixed.

Re:TypeScript 3.6 by almostdeadguy on Wednesday August 28, 2019 @07:17PM (#20825046)
There is no way any of this process takes less time to solve than "I got a red squiggle in my editor and fixed the variable spelling". I don't think typos are really the only things type systems fix (type systems provide powerful ways of preventing screw-ups by allowing you to encode invariants about a piece of data and how it may be used), but if typos are indeed the extent of it, it seems unimaginable to me that the process to fix would be faster by going through code review -> CI pipeline -> deploy and then back again, no matter how fast it is to revert a change in production. Honestly that's just the compile-time safety advantage of types, half the time saved in typescript is just not spending time having to read someone else's source code to figure out how a function may be used because cowboy js devs were too lazy to document them (knex is an especially egregious offender in this regard that I thankfully don't have to use anymore).
Re:TypeScript 3.6 by lewisl9029 on Wednesday August 28, 2019 @07:55PM (#20825329)
I never claimed it was "faster". Of course static types allow you to catch errors earlier in the process than without.

Whether or not that delta is worthwhile compared to a dynamically typed codebase with a well-optimized deployment/error detection system is not always clear however. Especially considering the costs of a static type system in limiting expressiveness compared to dynamic code and the mental overhead required when building abstractions that require layers upon layers of generics and higher order types to fully specify statically (library authors probably feel this pain the most).

Re:TypeScript 3.6 by hderms on Thursday August 29, 2019 @01:32AM (#20826920)
Some patterns or abstractions are more difficult in statically typed code but after a while you start to realize you probably shouldn't use them most of the time. Static typing makes it very easy to be _precisely_ abstract, and have some proof that things which claim to be that abstraction actually satisfy a certain structure. Dynamic typing may make it easy to be abstract in all kinds of crazy ways (I'm looking at you ruby metaprgroamming) but without safety abstraction can easily be more of a liability than a benefit.

I'd encourage you to keep your mind open to it's potential benefits as I've felt it has been a truly transformative experience that I'd like others to share.

Re:TypeScript 3.6 by smt88 on Wednesday August 28, 2019 @11:53PM (#20826529)
Dear god this process is insane. It’s the closest thing to malpractice that I’ve heard of in our industry lately.
Re:TypeScript 3.6 by Ididntdothis on Wednesday August 28, 2019 @05:38PM (#20824258)
I am starting to wonder if the preference static vs dynamic is some kind of character trait like introvert vs extrovert. I personally prefer static typing and use it to my advantage during development but I know very smart people who hate static typing and think it impedes them. Both sides have valid arguments but seem to prioritize things differently.

However I think it’s important to have used both for a while so you can make a good decision what you prefer.

Re:TypeScript 3.6 by bcheung on Wednesday August 28, 2019 @07:08PM (#20824992)
I think it depends a lot on previous experience, what type of thing you are developing, and your tooling. I'm very comfortable and happy bouncing between C# in Unity, React and JS, and Haskell for more CS / intellectual curiosities. For me it's more about fit and choosing the right tool for the job.

All things being equal I prefer something like Haskell because it is very clean and expressive. But I hate excessive types when you are dealing with generics 3 level deep or when you have these funky type signatures dealing with monad transformers. It's just too many layers of abstraction that takes you away from the actual data / parameters.

When I'm writing something small I find typing slows me down. But when writing something bigger, working in a team, or working on a codebase for a longer period of time the typing acts as documentation. Typing something and having Intellisense tell you what is in a class is extremely helpful. Otherwise you have to jump to the file or look through documentation.

For me it's less about the errors it catches and more about the time saving of not having to read through code that I am calling in order to understand what I need to pass to it.

In general. strong typing is great when you are working with other people's code and 3rd party libraries, but excessive overhead when you just want to experiment and crank out something small.

Re:TypeScript 3.6 by hderms on Thursday August 29, 2019 @01:36AM (#20826932)
Fwiw we have a relatively large Scala codebase that's exceptionally bug-free, performant.and easy to modify and haven't had to reach for a lot of the extremely abstract FP patterns that warrant the most blog posts. Simple immutability, garden variety monads (IO, Either, Option) get you a long way and are simple to understand.
Re:TypeScript 3.6 by rgoulter on Thursday August 29, 2019 @12:13AM (#20826625)
"static vs dynamic is down to personal preferences" was the running thesis of some of Steve Yegge's essays. His "Portrait of a N00b" is more/less one aspect of this.

For static-lovers, the idea of "just fix it if it breaks in production" is horrible. For dynamic-lovers, the idea of "spend time on work which doesn't get you closer to solving the problem" is essentially wasted effort. (Static-types are 'meta' code; the equivalent program works just as well without the types declared).

I've heard a good strategy is that the first-iteration should be dynamic (this gets the problem solved quickly), and static typing is good for further iterations (static-typing is better at conserving what's there).

Re:TypeScript 3.6 by vnorilo on Thursday August 29, 2019 @02:07AM (#20827073)
I don't know. My favourite languages to work in are Clojure (very dynamic) and the ML family (powerful types). I'll admit I've indulged in some C++ type orgies in the past. What I don't like is dynamic types in an imperative setting (python, js). I think dynamically typed oop is a bad combo.
Re:TypeScript 3.6 by Old_Thrashbarg on Wednesday August 28, 2019 @06:09PM (#20824549)
> However I think it’s important to have used both for a while so you can make a good decision what you prefer.

Exactly, I always found static typing to be annoying clutter and Python seemed to work even at scale. I removed the few type hints the codebase had.

Then I had to spend a year in C# professionally. At the end, I was fine with both, no preference. Then I jumped back into our Python and only then realized the utility of typing - it felt chaotic, my (IntelliJ) IDE was no longer helping me and every time I had Prod type related bug, it feeling dumb.

Ended up type hinting the critical parts of the Python.

Re:TypeScript 3.6 by Ididntdothis on Wednesday August 28, 2019 @06:11PM (#20824575)
I am also starting to embrace a mix. “Any” in TS or “dynamic” in C# can save a lot of code when parsing JSON but then I usually quickly try to move over into the typed world.
Re:TypeScript 3.6 by tomtomau on Thursday August 29, 2019 @12:21AM (#20826661)
`unknown` is also a really convenient type too: https://www.typescriptlang.org/docs/handbook/release-notes/t...

I think of it as "I don't care what the type is, but I also shouldn't be able to do anything with it"

Re:TypeScript 3.6 by ajxs on Wednesday August 28, 2019 @06:01PM (#20824486)
At first I thought I was going to read "I am starting to wonder if the preference static vs dynamic is some kind of character trait like intelligent vs ignorant", which would have been much closer to the truth. I think you're very incorrect. Maintaining a codebase of any sufficient size and complexity without static typing is a poor investment of development time. It can be done, obviously, but it's a nightmare. Typescript is a bandaid for web-development's biggest open wound. Taken on its own merits ( ignoring the garbage ecosystem, terrible tooling, etc ) Typescript is a decent enough language, but it's not a clever one. Is Typescript better than vanilla Node.js? Absolutely. Is it worth introducing to an area without Node.js? Absolutely not. If your project is any more complex than a four page CRUD app, in my opinion you're better off going with a bigger player like Java/.Net. These languages are more robust, more mature, there's better tooling, better community... The list goes on.
Re:TypeScript 3.6 by Ididntdothis on Wednesday August 28, 2019 @06:09PM (#20824554)
I am not sure if I want to work with you if you think it’s about “intelligent vs ignorant"...

Even though I seem to be in the “intelligent” camp by your definition.

Re:TypeScript 3.6 by ajxs on Wednesday August 28, 2019 @06:20PM (#20824644)
That's fine.
Re:TypeScript 3.6 by eleclady on Wednesday August 28, 2019 @05:50PM (#20824384)
Personal preference is valid only to an extent. At a certain point, with enough scale/team size/complexity TypeScript becomes invaluable. I've worked on projects that would have been intractable without TypeScript.

This is a huge problem with front-end. Too many people who don't know what they don't know, and think their use case is the only one.

Re:TypeScript 3.6 by wintorez on Wednesday August 28, 2019 @05:36PM (#20824237)
I don't like static typing, as a personal preference. I like the rapid prototyping of dynamic typing, and a type system often times gets in the way of that.
Re:TypeScript 3.6 by wvenable on Wednesday August 28, 2019 @06:03PM (#20824499)
That's funny, I don't like dynamic typing for the same reason. Rapid prototyping without types makes the whole process so much slower!

With dynamic typing, you don't get the immediate feedback of breaks when making frequent changes. You don't get the safety of automatic refactoring. You don't get auto-complete and easy of discovery of APIs.

I really don't understand the idea behind dynamic typing being better for prototyping unless that "prototype" is only a few lines long.

Re:TypeScript 3.6 by wwwigham on Wednesday August 28, 2019 @05:39PM (#20824271)
Even if you don't opt in to full TypeScript, please do remember that the same engine powering the TypeScript language is also what powers IDE support and completions for JS in vscode and VS, so even if you're not using TypeScript _the language_, you're potentially still using TypeScript, _the static analysis tool_. Even without opting in to full type safety, having those tools available can still be a huge quality of life improvement.
Re:TypeScript 3.6 by benatkin on Wednesday August 28, 2019 @05:36PM (#20824240)
It's a personal preference. Being able to make, fix, and guard against (with testing) type errors is a freedom that I've enjoyed with ruby, python, lisp (scheme/racket), scheme, and JavaScript.
Re:TypeScript 3.6 by lacampbell on Wednesday August 28, 2019 @06:14PM (#20824610)
I quite like static typing, though with some caveats. I strongly believe automated testing is more important. And I am also not afraid to make something an 'any' if it's proving particularly hard to type.

Have you considered thinking of static typing as a tool? A kind of ESLint on steroids. The great thing about typescript (or checking JS with the typescript compiler) is that you can set the dynamic/static continuum anywhere you want, pretty much.

Re:TypeScript 3.6 by gvkhna on Wednesday August 28, 2019 @06:11PM (#20824576)
I think another way to look at some of the benefits of TypeScript is class introspection. By writing your classes in an idiomatic manner, it makes it trivial to see the shape of your api’s without you having to write large amounts of documentation. As well TS compiler will check you’re using the api’s correctly. Huge wins!
Re:TypeScript 3.6 by Scarbutt on Wednesday August 28, 2019 @06:34PM (#20824753)
For another perspective, the TS compiler which is written in TS has zero classes.
Re:TypeScript 3.6 by codr7 on Wednesday August 28, 2019 @10:00PM (#20825999)
There are usually plenty of opportunities to infer types and check identifiers etc. at compile time without the need to annotate anything. And the more you annotate, the more opportunities for the compiler to help.

I don't have enough TypeScript experience; but from what I've seen, it comes pretty close to providing tools without mandating use and help where it can in the same spirit as Common Lisp.

I guess if your company mandates checking all boxes, which unfortunately seems bound to happen sooner or later, that doesn't help; but it's hardly TypeScript's fault.

The various Haskell-ish web languages popping up all over the place though, that's a different story. I wouldn't touch those with a ten foot pole. I'm so done with academic hoops.

Re:TypeScript 3.6 by rq1 on Wednesday August 28, 2019 @05:39PM (#20824270)
This you will need to explain. :o What kind of griefs static typing is giving you?
Re:TypeScript 3.6 by benatkin on Wednesday August 28, 2019 @05:42PM (#20824295)
It changes the order in which I think about solving problems, to something I'm less comfortable with.
Re:TypeScript 3.6 by ajxs on Wednesday August 28, 2019 @06:08PM (#20824542)
Is that really true though? To me this sounds more like making the validation of the program an afterthought, at best. Even in very academic mathematical models, introducing types early usually doesn't introduce much of a cognitive burden. I maintain that even when developers don't think that they're reasoning in terms of types, in many cases they are: "This is function 'x'. It takes two items of type 'T', which have to have a member 'a', which is a number. Function 'x' multiples the two 't.a' values together and returns a new 'T' with the result in its 'a' field."

If you opted to forego static typing, every step of the above function would require you to validate that you're dealing with the types you think you are. This kind of example isn't even at all uncommon.

Re:TypeScript 3.6 by rq1 on Wednesday August 28, 2019 @06:04PM (#20824510)
Isn’t it preferable to start with data modeling?

You can disagree but:

> Rule of Representation: Fold knowledge into data, so program logic can be stupid and robust.

http://www.faqs.org/docs/artu/ch01s06.html#id2878263

Statically and strongly typed languages excel exactly at this.

Re:TypeScript 3.6 by Koshkin on Wednesday August 28, 2019 @05:59PM (#20824470)
That's understandable - being pestered with error messages early on is not to everyone's taste and can indeed interfere with one's creative process. But can't one always start with JS and switch to TS later?
Re:TypeScript 3.6 by tony on Wednesday August 28, 2019 @05:51PM (#20824397)
What would be the downsides of TypeScript, from your perspective?

In a large codebase, having typings, even basic ones, go a long way.

I don't know about the term static typing or if that's what really helps. I also annotate for readabilities sake. For instance, it's nice to know a variable in python is only intended to be 'ACTIVE' or 'INACTIVE':

    from typing_extensions import Literal

    ActivityStateLiteral = Literal['ACTIVE', 'INACTIVE']

    # Lower in the code, e.g. inside a flask view
    activity_state = ActivityStateLiteral = request.GET.get('activityState')
For TypeScript:

    type ActivityStateLiteral = 'ACTIVE' | 'INACTIVE'

    // e.g. react component
    const activityState: ActivityStateLiteral = props.activityState || 'ACTIVE'
That leaves me no doubt when I/a team member comes back 3/6 months later that I'm only dealing with 2 possibilities of what that variable can be (or should be). The intention itself also valuable, even if incorrect.
Re:TypeScript 3.6 by benatkin on Wednesday August 28, 2019 @06:02PM (#20824496)
For your example, I would prefer a variable called active that can be true or false (True or False in python). This is just an example but I see stuff like this in statically typed projects, where integer enums are used when a string will suffice, and strings are used where booleans will suffice.

If I wasn't aware of valid values, I might search my codebase for uses of it. Usually if something is being set to true or false, it's a variable that can be true or false, or true, false, or empty (None in python, null or undefined in JavaScript).

Re:TypeScript 3.6 by ajxs on Wednesday August 28, 2019 @06:13PM (#20824596)
"I see stuff like this in statically typed projects, where integer enums are used when a string will suffice, and strings are used where booleans will suffice."

Typescript has proper enumerated types, so you really shouldn't be using either? Using magic number values for an enum is even poor programming practice in C. You've already listed one reason why you'd use a proper enumerated type over boolean, the fact that NULL is not part of the type's domain. The other big reason is that it is semantically correct. You can limit the type's domain to only values that make sense semantically. No more comments like: // A value of '1' means the missile is armed.

Re:TypeScript 3.6 by benatkin on Wednesday August 28, 2019 @06:42PM (#20824817)
I'm aware of this capability in TypeScript, which is why I specified integer enums instead of just calling it an enum. However, integer enums are still an option, and with TypeScript it would be easy to use an integer as a micro-optimization, which could be a pain if JSON gets exported and the person looking at it doesn't know what the numbers mean.
Re:TypeScript 3.6 by ajxs on Wednesday August 28, 2019 @06:48PM (#20824848)
Ah, I thought you were referring to an integer taking the place of an enum, which is a terrible practice that for some reason is more common than you'd think. I'm not too sure what you mean by 'micro-optimization' here, these kind of languages are so high level that the term 'optimisation' really doesn't apply. Regarding the JSON serialisation point: The internal representation of an enumerated type would probably depend on the needs of its serialisation medium. If it's going in a binary file, then an integer is probably your best bet. If it's going into a database, you might not have that limitation. This all depends on the scenario. As long as you're referencing the enum by its proper handle, that is.
Re:TypeScript 3.6 by benatkin on Wednesday August 28, 2019 @06:55PM (#20824907)
I was thinking of it as a storage optimization. "inactive" is going to take more storage than the number 2, both serialized and deserialized. Might seem like a bigger deal than the difference in CPU usage.
Re:TypeScript 3.6 by spiralx on Thursday August 29, 2019 @11:07AM (#20830145)
If you use a const enum in TypeScript it gets transpiled down to just the plain integer or string without any additional overhead. It just means you can't use a variable to get a value from the enum e.g. State[ currentState ] - which I'm not sure is a good pattern to use anyway.