AI Conversations
Tags: javascript, react, functional, declarative
Published: 2020-12-31 04:21:01

I recently built a new AI model.  You've probably seen where other teams have trained AI to "write" poetry or to "paint" images (often with nightmarish effects).  Well, I trained my AI by feeding it transcripts of actual conversations that I've had with other people in tech - on the web or IRL.  I then tasked it with creating a single, unified transcript that best reflects all of those dialogs in a single conversation.

My first test of the model was to feed it every discourse I've ever had with React Acolytes.  The following is a fairly accurate representation of all such conversations distilled into a single transcript.
<br/><br/>


![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xfygakk98zp94weavsyb.jpeg)
## The Conversation

**React Acolyte:** How can I help you, Grasshopper?

**Me:** Well for starters, my name is _Adam_.

**React Acolyte:** How can I help you, Adam _Grasshopper_?

**Me:** I've run into a strange bug while dealing with a state variable in React.

**React Acolyte:** Do not try and bend the spoon.  That's impossible. Instead, only try to realize the truth...there is no spoon. Then you'll see that it is not-

**Me:** What the hell does a spoon have to do with React state??

**React Acolyte:** Oh, right... sorry about that.  What I meant to say was: Do not try and bend the state.  That's impossible. Instead, only try to realize the truth...there is no state. Then you'll see that it is not the state that bends, it is only yourself.

**Me:** OK, first of all, that makes no friggin sense whatsoever.  Second, that's a pretty blatant rip-off from The Matrix.

**React Acolyte:** `<Shrugging>` Truth is universal.

**Me:** So is copyright.  But do you have any insight that can help with my problem?

**React Acolyte:** Maybe some more _detail_ about this "state" problem?

**Me:** Sure.  You see, when the user clicks this button, it triggers an event.  And that event, in turn, checks the state value before determining whether to proceed.

**React Acolyte:** Do not try and bend the event.  That's impossible. Instead, only try to realize the truth...there is no-

**Me:** **_STOP THAT!!!_**

**React Acolyte:** _What???_

**Me:** Endlessly regurgitating that tired quasi-spiritual claptrap from The Matrix.  It's irritating.  And it's not helpful.

**React Acolyte:** But you wanted help with _events_ and _state_.  And this is exactly what I was told at the latest React conference.

**Me:** How is that even remotely useful??

**React Acolyte:** Well... _state_ is responsible for complexity in apps.  It's the mutable nature of state that makes it the source of most bugs.

**Me:** OK, I get that.  Mutations cause complexity and complexity breeds fragility.  But what am I supposed to do about that?

**React Acolyte:** _Remove_ state.  Resist the temptation to use it.

**Me:** You _do_ realize that "state" is essentially an app's _memory_, right??  And that without memory, most apps are utterly useless??

**React Acolyte:** Possibly.  But we should still strive to write code that is state-agnostic.

**Me:** Yeah, yeah... whatever.  Shrink state.  Minimize mutations.  That all sounds good on paper.  But I have to deliver an app to my employer.  One that will, you know... _remember stuff_.  And that won't be happening any time soon unless I can manage state.  And "managing" state means that, occasionally, it needs to be _updated_.

**React Acolyte:** I sense much fear in you - fear of _purity_.

**Me:** I write "pure" stuff all the time.  Pure functions.  Pure components.  _Thousands_ of them.  I don't have any "fear" of them.  Besides, that sounds a lot like something that-

**React Acolyte:** Fear is the path to the dark side. Fear leads to anger. Anger leads to hate. Hate leads to imperative programming.

**Me:** OK, now you're stealing from Star Wars.  I mean, if you're gonna be so blatant, at least gank something from the original trilogy.  I don't understand how any of this helps me to fix my bug.

**React Acolyte:** Pure functions have no state.  No dependencies.  They work the same way, every time, without nasty side effects.

**Me:** Yeah... I've known that _for years_.  And like I said, I write pure functions all the time.  Whenever I can, in fact.  But you can't build an entire enterprise-level app without using state, and at least _some_ "impure" functions, and the occasional events that essentially tie them together.

**React Acolyte:** Why have you cut yourself off from the Force - of Declarative Programming?

**Me:** _What??_  No!  Whatever gave you that idea??

**React Acolyte:** You spoke of... _events_!

**Me:** Well... _yeah_.  The user clicks this button, which triggers an event, which then-

**React Acolyte:** Much defiance I sense in you.

**Me:** Crappy Yoda impressions you make.

**React Acolyte:** Sarcasm leads to the Dark Side.

**Me:** Oh.  Then maybe you should call me _Darth_ Adam.

**React Acolyte:** Darth Grasshopper, you have forsaken Declarative Programming.

**Me:** That's ridiculous.  I love me some JSX.  I got my Functional Programming Merit Badge.  Every night I urinate on a statue of the jQuery God.  I've even been... _declared_ to be a declarative programming guru!

**React Acolyte:** That was a really bad pun.

**Me:** Someone doing bad Yoda impressions and ripping off The Matrix wants to judge my puns?

**React Acolyte:** `<Shrugging>` We all have our own standards.  My standards require the shunning of all _events_.

**Me:** So... _your_ programs run with no user input whatsoever??

**React Acolyte:** Of course not.

**Me:** When _your_ users click that button, you don't think of it as an "event"??  Maybe you call it "The Clickening"?  Or... "mashing"??  

**React Acolyte:** It's not that my code doesn't _have_ events.  It's that my events are not handled in an _imperative_ manner.

**Me:** Oh... so you mean, in your React apps, that all of the event handling is programmed directly _inside_ of the JSX?

**React Acolyte:** Precisely.

**Me:** And you believe that if I were to cram all of my conditions, and loops, and any other logic _inside_ of my JSX, that this would magically fix my event/state bug??

**React Acolyte:** Bugs are the purview of weak minds.  Minds that program... _imperatively_.

**Me:** I'm leaving.

**React Acolyte:** But we haven't fixed your bug yet!

**Me:** I now realize that _we_ are never going to fix this bug.

**React Acolyte:** But I have so much more to teach you, Darth Grasshopper!!

**Me:** Smell ya later, Holmes.

**React Acolyte:** No!  Don't leave!!  Try to snatch this pebble from my hand!

**Me:** Please lock up on your way out.

**React Acolyte:** What is the sound of one hand clapping?!?!

**Me:** Peace out.

**React Acolyte:** Grasshopper!  You haven't left me, have you Grasshopper?!  _Darth Grasshopper!  Come back!!!_