Categories
Uncategorized

Found in the Twilio TOS

Presented without comment

Twilio Terms of Service
Twilio Terms of Service

Categories
Tech Industry

The WFHpocalypse Part 2: Thoughts on On-Site Work

Years ago I was conversing with a friend in the field— a UX developer who worked at large Ruby consulting firm. It was the early teens, that is, 2010s, and Rails was taking off like wildfire within the startup scene of New York City. I too worked at this time in startups, first in advertising and marketing platforms, to app development, and eventually finding my way to e-commerce.

I don’t remember exactly which year he made this comment to me, but I remember the company: Gilt Groupe. I name-drop it here because neither he nor I have worked for Gilt so our observations are merely second-hand. (Typically I don’t reveal the names of the people or companies in my stories.)

Gilt employed 100 Ruby engineers, and bragged that at 12 noon, when their sales went on the site, they had traffic that was bigger than Amazon’s traffic. My friend came from a pair programming background— where everyone works in pairs. Each pair works on one thing on one computer, they use one monitor (typically, but can use two mirrored monitors) and two keyboards. In the old days, the actual advice from XP evangelists is to use one keyboard and slide it back and forth between the two developers.

(Obviously, the age of corona will challenge some of these old days of working.)

In a conversation about workplace culture my friend said to me that Gilt was a very “headphones on” kind of place.

What he meant, in short, was: a culture of overly intrusive management, little collaboration, perhaps even competitive behavior between the engineers, and people wearing headphones in an office setting to signify to their colleagues that they don’t want to be interrupted.

Many companies and the people who run them might find this challenging.

If your idea of building software is that you need developers to be available to you to be ‘responsive’ to changing needs— throughout the day— you probably aren’t planning your software very well. Constant interruptions will universally mean that your engineers won’t be able to truly focus on the really hard stuff.

But these aren’t great reasons to insist on growing your workforce on site. In fact, they are only reasons why you should question if you have the right tools in place.

Second, if you think you need developers to be onsite because you want to ‘talk’ to them about the product, then you probably don’t know what  a product owner is or could do for you.

A strong development effort will be led by a Product owner, who will have onsite meetings, and will write everything down in a neat, codified way for your engineers.

Third, and this is one of the most important: 40 hour work weeks are arbitrary. In fact, laborers used to work in factories more than 40 hours/week, and it was only because of the rise of unions that we now have a Monday through Friday workweek.

What’s important to software development effort is:

1) Focus (getting ‘in the flow’) and not being interrupted

2) Comfortable workspace, with good lighting, and an ergonomic chair or standing desk

3) Being mentally and socially stimulated, through interactions with others (“interaction” here implies either face-to-face or any other kind of online interaction for someone remote)

4) Not overworking.

Great software is built with effort, and effort makes you tired.

It’s natural to be tired after a good day’s work. It’s so normal we have a nomenclature around it: “go home to recharge” we say.

The most effective way to work is to focus on efficacy and recharging adequately. Stop worrying about everything else.

Pros of working onsite:

1) You should code onsite because face to face meetings convey more than you can over written words, stories, video chat, etc.

2) You should code onsite because coding is a collaborative exercise

3) You should code onsite because CEOs and managers like to see occupied workstations to make it look like people are working

In 50 Ways To Find a Job, Dev Aujla says:

“There are two types of jobs that you can get. One is the type of job where you mentally check out, bide your time, and collect a paycheck. In this job you days are filled with a type of work that often feels stressful, frantic, meaningless. The second type of job is filled with the kind of work that feels natural, that comes easily, that rejuvenates you, and that isn’t motivated by stress or fear.”

Dev Aujla, 50 Ways To Find a Job

When I read this, it struck me a slightly simplistic but I knew exactly what she meant.

It would be ill-advised to argue that onsite work is naturally soul-crushing, or that remote work is naturally better— because it wouldn’t make sense.

Fried and Hanmeir Hanson are such advocates of remote work (they wrote a book about it) that they call offices “distraction factories.”

But it doesn’t have to be this way!

Mentoring & Pairing

In Extreme Programming Explained, Kent Beck proselytized a practice known as Extreme Programming, or “XP” for short. In it, programmers pair. Pair programming means, specifically, that two developers work at the same time on the same code. In fact, the classic way to pair is for both developers to sit at one computer with two separate sets of keyboard & mice (mouses?). The programmers sit equally distant from one another using a big flat screen monitor (not one person on their laptop and the other “looking over their shoulder.”)

Typically, one developer acts as the ‘navigator’ and the other the ‘driver,’ but an effective pair will swap roles naturally and without formality. (As mentioned before, another setup suggested by Beck is having one keyboard that is passed back and forth between them.) The ‘navigator’ will be thinking big-picture about the code, where they are going, the interactions between objects. The driver is the one doing the typing, typically paying attention to the syntax of the API and each little detail as they go. But even when you’re the driver, it’s still exponentially better to have a second pair of eyes catching for mistakes.

When I first read about pair programming I was inspired. Although I’ve done and seen many forms of light pairing over the years, I’ve only known a few companies that have a two-programmer policy for all of their onsite work. 

When I can say from my decade and a half in this industry is that while there is no moralism to onsite vs. remote, there is often economy to it. To CEOs and managers, onsite workers seem like workers who can be managed, because they can see them. Onsite workers give CEOs and managers a sense of certainty. Onsite workers, especially engineers, artificially inflate the value of the company because investors and/or other companies who might buy you out will value a company more because of the perception created by having onsite workers.

Furthermore, there’s always been this thing in professional settings where people who work onsite schedule their own personal needs: doctor, dentist, the cable guy are all always seen as typical reasonable excuses for taking time off or working from home.

But what’s typically not so obvious to younger employees is that if you only take time away from your work for these “life necessities” things, you’re likely ignoring self-care in a dramatic way. I’m talking about things like exercise, eating well, doing your laundry, spending time outside. If you have kids, these might be the most important years of their lives: What parent wants to have to work until 6PM or later when their kid gets out of school at 3PM?

Most young parents I know in these scenarios have negotiated some degree of working from home or schedules that allow them to be with their kids after school (Like leaving a 3 pm to go pick them up.)

These kinds so of ideas make companies very nervous. They falsely equate time-on-the-clock with output, which is dangerous. Typically in that mindset, your onsite employees will produce a little as they can to keep their jobs and perform at the minimal output to make it look like they are good employees.

What if I told you a few dirty little secrets of onsite work.

Cons of working onsite:

1) Generally speaking, people who work onsite spend most of their time managing their boss’s expectations, going through what appears to be motions of looking productive and inserting themselves into structures of face-to-face interactions in your company to make themselves appear to be valuable. While I see this a lot from non-engineers, I’ve seen this plenty from engineers too.

2) Offices, especially open offices, are probably the most distracting place to code. People coming and going, other teams making noises, various managers coming up an interrupting you throughout the day. I think most engineers have all been there and know what I’m talking about.

3) Nobody actually works 40 hours per week or 8 hours per day. People come in at 9:45, they unpack their bag, they set up their computer, they go get some coffee. They stop at the ‘water cooler’ for a quick chat with their colleague. They might start about 30 minutes later (but even that isn’t a given.) They do a few minutes of what looks like work, but then they get distracted (see #2). At 10:30 maybe the team has stand-up, which should last 5 minutes but instead takes 20, and then they’re thinking about what someone said at stand-up. They take a few minutes to look up something new, or to check Facebook, or the news. All things considered, most ‘onsite’ employees typically have an effective workday that comes out to about 5 or 6 hours, or sometimes less.

This effect is compounded by being good. If you’re a rockstar, you actually have no incentive to work harder in this scenario. Why? Because the amount of energy you spend is related to the function of difficulty of the task you’re working on, not the number of minutes you are hypothetically sitting at your desk with that problem in front of you. If you get more done in less time, your company only gets more out of you but you (typically) make the same amount of money.

It’s a natural tenancy to manage our work in this way— what’s not natural is the concept that each hour equates to a linear amount of output.

Now, this is not to say that onsite work is the pits or to advocate for remote work— in some regards the opposite.

Some employees probably aren’t better working remotely. Some need guidance, supervision, or mentoring that can’t be done well remotely.

The thing I’ve been wanting to ask employers who insist that onsite work is better— often with something of an obsession with this subject as a moral divide is whether they’ve asked themselves some really deep questions about their own expectations:

1) Do really think that making people be onsite for 40 hours/week (or 38 hours, or 36 hours/week) actually makes them 40 hours of productive?

What if we had a 4-day workweek? What if we gave everyone the day off on Fridays, would they get 4/5ths of what they get done now get done in 5 days? Shocking to most suit & tie people, the answer is almost always no.

When you give people the freedom to work on their own schedule, employees nearly always work harder. Most engineers I know would rather work four 10-hour days (Mon-Thur) and take Fridays off. Why? Well, it comes back to flow. More compressed, focused work is almost always more effective.

2) As a CEO/manager, you know that programmers spend a lot of time at their keyboards. But what’s all this other stuff they do? Talking, diagrams, sometimes just walking around the block.

In software, we call this stuff at the computer GAK — short for “geek at keyboard.”

What software engineers don’t tell you is that lots of the hard problems aren’t solved at the keyboard. In fact, sometimes when you are solving the hardest problem, the best solution is to walk away from the keyboard and start to come up with a mental model of how to approach the problem.

This mental modeling can happen in many forms. Sometimes a team of people can do it (together) in front of a whiteboard. Sometimes you really need to take a walk around the block.

I’ve found personally that the best code I write I actually have to give a great deal of thought to before I write it. Sometimes these mental models take me hours of just thinking about how all of the parts might fit together. (Admittedly I might be doing more architecture work than coding in these cases, but the point is the same: A lot of the work is conceptual, not typing.)

3) Are 8 continuous hours of work, starting at some abstract time like 9AM or 10AM and running through 5PM or 6PM, really the most effective way to get coding done?

In my experience, I tend to work very hard in the morning for several hours. If I get 3 hours of focused, uninterrupted time in, I know I’ve had a good morning. (If I can get 3 ½ hours, I’ve had a great morning.)

The level of concentration required to code is intense.

If you still don’t believe me about the lack of a connection between hours on the clock and work produced take this anecdote: I noticed years ago that if i did very little in the mornings I wouldn’t get hungry to the late afternoon. If I worked very hard, I would get hungry earlier (like lunchtime). After thinking about it more, I realized that work is related to synapses firing in your brain.

Since many of the easy problems you will encounter will be solved quickly, as an experienced software engineer what I’ve seen most is that the hard problems are the ones where the work takes mental energy. It’s the hard problems that demand that I concentrate and focus. It’s the hard problems that make me more tired after 1 hour of coding than 3 hours of non-coding. It’s when I’m solving the hard problems that I don’t want you to talk to me.

Zoom

Now that’s not to say that working onsite is useless: in this age of quarantine, we are reminded of all of the subtle ways Zoom is inferior: 1) interactions are negotiated over email, Slack, or another messenger, any choice of which forces one to confront the explosion of messaging options we have available today (a task that could give anyone choice anxiety).

2) Sitting in front of Zoom screens involves both a kind of participation and acting at the same time, as you become keenly aware of looking at the feeds of the other participants and also the fact that they are looking at you.

3) There is something just slightly lost about the remote pairing. I’m not sure what it is, perhaps it is the added need to negotiate the control of the typing (something that comes a little more naturally while in person). Perhaps it is the fact that onsite pairing makes both partners focus precisely on one thing until it’s done. With everyone at home, there’s a propensity to be distractible with either activity in your home or other activity on your computer (that is, you can keep the ‘Zoom window open’ while doing something else). It just doesn’t seem equal to me to what we now call ‘f2f’ (face-to-face)

4) The actually productive meeting— you know, the elusive one that everyone dreams about having— in which ideas were written out onto whiteboards and then erased and re-worked and you felt like the meeting itself was the process of coming to the group decision. (Not those ill-managed ones with endless circles of indecision gripped by design by committee.)

Those things are lost, sadly, in our Corona-Zoom era.

Maybe Coronavirus and the new remote work paradigm will mean that working remotely becomes de facto. (Likely, when the quarantines are lifted the culture clash between onsite vs. remote will become even more stark.) Maybe not.

But one thing I can tell you is that a lot of people are experiencing this for the first time who’ve never even asked any of these tough questions— if you’re at your desk, are you really working? If you’re writing code, what’s the hardest part of what you’re doing and what’s the easiest? Are you really more effective working longer hours, or are you more effective working shorter, focused hours? What sacrifices are you making to be onsite at a job continuously throughout the day?

I’m not saying remote work is for everyone or every company, just like onsite work isn’t for everyone. But I know for sure that anyone who tries to tell you that one is morally better than the other is full of malarkey and that a huge number of engineers who never been pushed for efficacy simply don’t know what it is. In fact, I’ve also seen the dangerous opposite: A developer who is oriented by the company to put their energy into thinking in the ways of the existing structure and not outside the box. While this is a natural effect of being employed, it isn’t a normal or rational choice for any highly motivated engineer. That’s because the pace of change in this industry is lightning fast.

Categories
Programming

How to Get Emojis in MySQL (fixing Incorrect String Value)

So your Rails application with a MySQL database was humming along and all of a sudden it hit this error:

Mysql2::Error: Incorrect string value: '\xC5\x99\xC3\xA1k

What does that mean? Upon inspection you realize that someone has typed into your website the all-too-favorite Millenial communication tool: the emoji. 💛✨

MySQL needs a little massaging. For steps 1 & 2 in Rails, create a new database migration and use execute to run these commands directly onto your database.

  1. Make sure you actually alter the database’s character set

ALTER DATABASE <DATABASE NAME> CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;

Where <DATABASE NAME> is your database. in Rails, because we have different database names for different environments, try this inside of your migration…

execute "ALTER DATABASE #{ActiveRecord::Base.connection.current_database} CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;"

  1. Make sure you ALTER the TABLE AND FIELD where you want to insert the character set

ALTER TABLE CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE modify TEXT charset utf8mb4;

(If you made a Rails migration, you can do this in the same migration using another execute.)

IMPORTANT: I have assumed above that your field is of type TEXT. If it is not, change your field’s type definition before running this. If you don’t, you’ll convert your existing field to a TEXT field even if you didn’t want to.

  1. Restart your MySQL instance (DO NOT FORGET)
  2. In Rails, you must also specify the encoding & collation in the MySQL adapter which you will find in your config/database.yml file (where you have specified mysql2 as the adapter).

For example:

production:
encoding: utf8mb4
collation: utf8mb4_general_ci

or if you want it in your default configs

default: &default
encoding: utf8mb4
collation: utf8mb4_general_ci

See also…

https://stackoverflow.com/questions/22464011/mysql2error-incorrect-string-value#22464749

https://stackoverflow.com/questions/16350310/mysql-mysql2error-incorrect-string-value/18498210#18498210

https://stackoverflow.com/questions/16350310/mysql-mysql2error-incorrect-string-value/16934647#16934647

Categories
Tech Industry

The WFHpocalypse Part 1: Thoughts on Remote Work

Since the global quarantine working-from-home, or remote work, seems to be everything anyone can talk about. 

About 15 years ago when I started my career, software engineers were a rare, abstract breed of professionals. People knew of this profession, talked about it, but few had met someone who actually worked day-to-day writing code.

In that day (around 2005), the term ‘colocating’ became a thing.  Colocating basically means, albeit confusing, when people work in the same office. So in other words, working onsite. (In the context of a computer or server that is co-located, and I realize I’m dating myself by even mentioning physical servers— yes, actual machines— colocate meant to host your physical server on-premises with your company or in an existing data center with other physical servers you also operate.)

In my experience, even by 2008 it was regular and normal for more non-tech employees to work from home (or “WFH” as is abbreviated) at least one day a week. Jobs were routinely advertised or negotiated with a certain number of ‘WFH’ days. Engineers worked from home even more, many working remote all of the time. 

Then around 2013 some of the larger tech companies started to crack down on their employees working remotely. Marissa Meyer, the new head of Yahoo, famously set a no-work-from-home policy, vexing many of the Yahoo employees with families who had felt they had been hired under the auspices of workplace flexibility.

Years before this, a manager told me that they had no shortage of mediocre people who would show up onsite and work 9-5, but virtually no candidates who would work a regular 9-5 job and were exceptional. The exceptional candidates, she explained, all had demands—workplace flexibility chief among them.

My own experience has born this out too: The best developers I ever worked with were ones who worked remotely.

In fact, two that come to mind worked for companies in New York City — where I was an ‘onsite’ employee on the team — and did all of their work entirely remotely. While both of these people came to New York to visit— maybe once every six months — neither preferred to move to city that was more expensive than where they already had a good living.

Both of these guys were rockstars, and I mean rockstars in the truly respect-worthy sense. You’d have meetings with them and the next day they’d already been whipping up some sample code. They outperformed every member of the large team consistently week after week.

Except one time. Stan (one of these exceptional developers) and Peter (the product owner), and I built a system. It was a management workflow for an internal agency. In the agency, the projects had a natural step-by-step flow from concept to ideation to wire framing to production to delivery. Sounds straightforward enough.

Peter the product owner had written a complicated state diagram that showed while the normal set of steps was 1, 2, 3, 4, 5. Sometimes a project could go from step 5 back to 2, or from step 3 to step 2. His diagram had a number of complex transitions based on what the stakeholders had told him upfront about their needs.

So Peter, shows this to Stan (who happened to be my boss at the time) who immediately solves it using every developer’s favorite pattern: a state machine.

The state machine implementation was beautiful. It had gated locking mechanisms that allowed transitions only through the specified transition steps. We deployed it; everyone loved it. It was the first time the agency has had a custom workflow built around their needs.

“This thing is great,” someone tells me as feedback. “But why can’t I go from step 4 to step 2? Why must I advance to step 5 before going back to 2?”

Peter, me, and Stan have a meeting. “They love this product but we don’t need all these rules blocking people from just putting the project into the state they want it to be it.” Dammit, Stan thinks, then why did you draw me a fancy chart that said you did up-front?

Whether this was a failure of product development or imagination I can’t say, but it always struck me as funny that here I was, much more junior to Stan’s experience in Ruby on Rails, and I had an inkling that the fancy state machine he built wasn’t going to be as useful as he thought. (Of course, he was my boss, and obviously it is what ‘they’ had asked for, but I still pictured the agency’s chaotic workflow and thought to myself, they’re going to want to change the states back and forth and back and forth, why are we building this state machine that locks them into specific transitions? I didn’t bring up my objections to Stan at the time.)

Not only had he overbuilt something, but he’d in fact built something that was a hinderance to the end user (exactly what you don’t want in good software). In our case, our user base was small and forgiving (only the people in the company), and so the impact was minimal. We removed the transition locks (but still kept the underlying ‘state machine’ coding pattern) so that a project could be moved from any state to any state. All things considered, nobody creatives were harmed in the making of the software and the cost of being wrong was low.

But building that state machine wasn’t a small bit of coding. Not months of wasted work, but it probably was weeks of wasted work.

It always struck me that Stan, a bit of a left-brained nerd, always seemed to related to the code better than he could relate to the people.

And therein lies the heart of the tension between the ‘onsite’ world and the ‘remote work’ world: Are you relating on an empathic level to the company’s needs or are you relating on an technical level?

I’ve heard all sides of the onsite vs. remote-worker divide. Since it’s such a controversial topic, I’ll list just some of what I’ve heard about the benefits of letting your workers work remotely: 

1) As a company, you can have access to a much more significant pool of talent

2) Your workforce is more likely to work harder

3) You can distribute workers at different times to allow for asynchronous work to be done— for example, an engineer codes a feature in afternoon and someone else does QA on that feature in the evening. (In a traditional onsite workplace, your features won’t get QAed until the following day when people come back into work.)

4) Workers can live somewhere significantly cheaper than the expensive tech hubs of San Francisco or New York City. While many people think the cost living difference might be a factor of 50%, I estimate the true cost of living difference, after taxes, between an expensive city like New York and the mid-west is probably 400% (that is, it’s 4 times more expensive to live a “city lifestyle” in an expensive city than it is to live “normal lifestyle” anywhere else.)

5) Offices are distracting and not conducice to concentraion. In their book Remote,  Jason Fried and David Heinemeier Hansson ask

If you ask people where they go when they really need to get work done, very few will responde ‘the office.’ If they do say the office, they’ll include a qualifier such as “super early in the morning before anyone gets in” or “I stay late at night after everyone’s left” or “I sneak in on the weekend.’

I’ve seen both sides of this coin. On the onsite side, I’ve done onsite pairing, product development, white boarding, led and participated in onsite meetings, done mentoring of junior developers face-to-face, and also been the coder with headphones on at his desk (if you don’t know, when an engineer wears headphones you can think of it like he or she is wearing a “don’t talk to me right now” sign)

I worked remotely for years as a consultant, and I “worked from home” on and off though many jobs in New York City too.

I am ambivalent about the debate: one the one hand, I have found onsite work to be stimulating, connecting, and effective, especially when you have a strong team (one that makes you want to come in every day.) I’ve also found onsite work to be draining, exhausting, and, worst of all, distracting. How can both of these things be true?

To be effective at what we do, developers need something that we call ‘flow.’ For laymen, thinking about the last time you wrote something— something difficult. Maybe a paper for school or a presentation that required a lot of writing. Let’s say you sit and start writing. At first, your attention is easily diverted. What you’re going to have for lunch, what your wife said to you yesterday, the sound of the ticking clock. You know you aren’t concentrating, so you concentrate harder. After about 15-20 minutes, you are typing sentences and they seem to be flowing out of you. Then someone comes in the door and asks you a question. You look up, “Sorry, what did you say?” Half of your brain is still writing, but it was just jarred into something else by the event that distracted you.

Programming is like this every single day, and the need for focus is even more dramatic than most professions. Non-programers typically underestimate the significance of flow in software development. 

Product development, which is a constant back-and-forth with stakeholders, is something that dramatically benefits from people being in the same place. If you sit with the people you are building software for you are more likely to connect with them on an empathic level, a key component to being a great product owner. As the state machine example with Stan demonstrates, sometimes if the only things you interact with are computers you begin to identify more with the computers than the people. (That’s not a good thing.)

Self-starters remote employees like Stan and Thomas (and yours truly, often) — partly because they have the privilege of working remotely— are focused on results precisely because nobody is looking over our shoulder or clocking our hours.

The Coronavirus is a paradigm shifting event to the WFH vs. onsite worker debate: Everybody has to stay home during the quarantine. Companies and teams that have never worked remotely are suddenly forced into this situation. I can only imagine CEOs and Human Resources people who have looked down on remote workers judgmentally— which sadly I fear are the majority— are going to loose their shit.

 

In the next post I’ll explore working onsite work, how it has changed, where it shines and what its pitfalls are. 

Be sure to LIKE & FOLLOW for Part 2.

Categories
Tech Industry

Working from WeWork During a Pandemic

I sit here as the World Health Organization declared last night a global pandemic due to COVID-19, and all everyone can seem to think or talk about is how scary this virus is. Nearly universally, as universities and events were canceled this week, workers across America began to work from home.

Zoom Conferencing, global platform for video-conferencing, arguably, the company to have defined the video platform industry, is up on the stock market today, as a sign of the times:

  • Loading stock data...

Everywhere I turn it seems people are freaking out: scared to ride the subway, travel is down, stocking up on supplies and food, and talking about working from home.

In a cafe that I went to yesterday — normally a quiet haven of distraction-free concentration — a woman sat with her laptop on video conference. “Is this working? Can you hear me? We’re all video conferencing, then!” she said in her slightly British accent. Amateur, I thought, as I put on my headphones so as to maintain some semblance of separation between me and the talk of the pandemic.

Although I couldn’t help but be struck by one obvious paradoxical fact: The cafe I was sitting in posed no less of a risk than a traditional workplace. In some regards, with that many people touching tables, touching counters, etc, there isn’t any reason to think that the virus won’t spread just as easily if we all work from public cafés.

Here at my WeWork office earlier this week, people were talking about adjusting to this ‘new normal.’

“I heard they aren’t testing here in New York,” I overhear someone say. “I heard they are but they don’t have enough test kits,” someone else responds. Mostly, it’s the fear of not knowing that seems to be the driving force of stress.

The small coffee shop where I get my coffee (not the café mentioned above) had a sign today that read: “Out of an abundance of caution due to COVID-19, we are not doing ‘bring your own’ container or using ceramic mugs for the time being. Thank you for understanding.” Of course, I think, the customer touches the reusable to-go cup (like those metal mugs people use to reduce waste), the barista touches the container, the virus spreads to the barista’s hands, they give it back to the customer and then go on to spread the virus to the next customer’s order, and the next.

And so the small modifications to our lifestyle and adjustment to this ‘new normal’ begin.

As I sit and write this from WeWork DUMBO (in Brooklyn) it strikes me how ironic it is that in fact, working from WeWork is probably rather safe right now. Why? Well, for one thing, there’s nobody here. Office after office has shut down, people are working from home. This place feels like a ghost town.

Furthermore, people who work at WeWork tend to be adult professionals who act in a highly professional way:

  1. Of course everybody washes their hands every time we come in or go out.
  2. I get to walk here, which helps me avoid the germ-infested subway system of New York City.
  3. The entryways have contactless scanners I don’t even need to touch my card to the turnstiles (I can just wave it over).
  4. I touch only the elevator buttons and can even do this with my elbow.
  5. I wash my hands immediately upon walking in
  6. Every surface is washed down, now (as I’m told by general announcement) multiple times a day.

Hospitals used to be a place where it was presumed that you would go to die as people generally went into hospitals and didn’t come out. Then doctors and nurses started washing their hands and people started coming home from the hospital.

(In 1846, Ignaz Semmelweis, a Hungarian doctor noticed something interesting about two wards: In the maternity ward run by students and doctors, women giving birth were more likely to develop a fever and die than the women in another maternity ward right next door that was run by midwives. He noticed that doctors and nurses often visited expecting mothers after performing an autopsy on a dead person. As a result, Semmelweis mandated handwashing with chlorine for doctors. Suddenly, new mothers stopped dying at the rates seen before.)

Today, doctors and nurses who work in hospitals will tell you that they wash their hands not to protect themselves from disease, but (largely) to protect their patients. The biggest risk is not from a doctor or nurse who is infected, but from passing germs from patient-to-patient as they make their “rounds.”

That’s why the medical profession has always said (and keeps saying): wash your hands!

The truth is, there’s a lot about COVID-19 that we still just don’t know. Panic is a manifestation of the threat to our egos. It’s a normal reaction, but the stress it causes is useless. Whether you are working from home, a café, or an abandoned (and probably septic) WeWork, there’s nothing to support the idea that just changing our work location, in fact, puts you in any less risk. Washing your hands, not touching things unnecessarily, avoiding travel, and keeping a strong immune system are probably the most effective things for you to put your energy into.

Honestly, for myself, I think the WeWork is the safest bet today.

Categories
Humor

Some Humor

Categories
Programming

Essential React Packages of Early 2020 ( do not develop without )

The most essential Node packages to set up your React app today.

(This article was written in the context of React versions 16.9, 16.10, and 16.11 in late 2019/early 2020)

Absolutely Standard (you should install by default):

• styled-components

For creating styles inside of your components. 

prop-types

prop-types is used for validating the properties are what they are supposed to be. This is invaluable for speed in development. In a nutshell, you should get used to the idea of declaring what the valid types for your properties are (string, array, number, etc)

• @dr-kobros/react-webfont-loader

For loading Google fonts. Want your website to look pretty and unique? Go choose a Google font.

• bootstrap, reactstrap

For installing and using Bootstrap, the world’s most popular CSS framework. 

For Bigger Apps: 

• isomorphic-fetch

This is what you need to make Ajax calls to a remote server. 

• react-redux, react-thunk, thunk

You will need react and thunk if you want to create a Redux tree of data. You will have to learn how to do fun things like mapStateToProps and mapDispatchToProps, and then you will have a giant data tree that will be mapped to your react components. 

For feature detection:

• react-use

This magic tool can detect anything your user’s browser is capable of. 

• query-string

Query string will check those query parameters (like ?search or ?utm_campaign, etc) to let you grab them from the browser’s URL. 

• react-helmet
You use React helmet if you want to set the page’s HEAD tags, for example, if you want unique meta or content tags to be generated depending on what is on the page.

For Testing:

@testing-library/dom, @testing-library/jest-dom, @testing-library/react

With these you do fun things like unit testing, watching all your specs as you develop, and run a coverage report of how many lines of code you have covered. 

cypress

This is what you use if you want to integration testing. You’ll note that Cypress is written in jQuery, ironically, because you aren’t supposed to use jQuery with React.

• deep-freeze

This package makes sure that your pure functions return with no side effects and without mutating the original objects

• enzyme and enzyme-adapter-react-16 (for React 16)

Categories
Tech Industry

Queens JS (4 Apr 2020)

A photograph on the backdrop of coronavirus panick throughout the city.

Angus Grieve-Smith (@grvsmth) treated us to a display of how to audio interfaces using native web controls, appropriately titled “Web Audio With Javascript” Their website is grieve-smith.com

Angus shows how to use native Javascript to build an audio recorder.

Peter Karp talked about Pydantic, a python validation tool. He compared it to marshmallow, a tool he says is outdated and was used for serialization, validation, and typing in JSON manipulation.

Peter Karp talks Pydantic

And finally, Tracy Hinds (@HackyGoLucky) talked about conflict resolution on software development teams.

Categories
Programming

Something About Refs

React’s Virtual DOM arguably revolutionized web development. In short: React will keep a copy of the DOM in its own memory space. When you make updates, for example, several updates to component state, the React will manipulate the Virtual DOM first, performing all of the mutations on it in succession. Once all of your logic has run, React knows how to compare the Virtual DOM to the real DOM, and then it makes small, isolated updates one-by-one, only changing the least amount necessary.

Why does it do this? Well, for one thing, when the browser performs DOM operations it is famously slow at doing so, that is non-performant when many updates are happening. If each mutation of the DOM was done in the browser, you couldn’t achieve the fast effects you can with React.

You’ll note then that the objects you code in React, then, don’t expose direct access to the DOM elements. This is a good thing, because it means that to change the DOM you must always go through the React re-render cycle when you want to change your DOM.

Most of the time, this can get you most of what you need doing. But occasionally, if you need to access DOM elements to inspect them, you’ll want to use a feature of React called React Refs.

Other cases of using Refs is to manage text highlighting, managing focus, and media playback. Refs are also used for some advanced purposes too, like managing interactions with 3rd parties and multistep form state.

Today I will explore three patterns for using Refs in React: 1) A basic Ref implementation, 2) A forwarded Ref, that is a ref that has been sent to another component, and 3) A forwarded Ref used within a Styled Components setup.

Remember, your Ref will simply point to the DOM elements. What’s important here to keep in mind is that you 1) first need to create your ref, 2) then assign it to a component using ref= , and 3) let React maintain the Ref for you during the rendering.

Example #1 — Basic Usage

First, you need to create a Ref object. You do this before your component is rendered using React.createRef()

First let’s start with the most basic React component. (To see this, edit your App.js file and remove the default content and add <ThingOne />)

// src/thing_one.js

import React from 'react'

class ThingOne extends React.Component{
  constructor(props) {
    super(props)
    this.ref1 = React.createRef()
  }
  
  render() {
    return (
      <div>
        
      </div>
    )
  }
}

export default ThingOne

Notice that in the constructor, we create the Ref using this.ref1 = React.createRef(). At this point, if you examine your object, you will see something interestingly empty:

Notice that your variable now holds an object with a single key, current, that points to nothing (null).

Now, let’s add an input checkbox and also tell React to use this ref (ref1) for that input checkbox.

import React from 'react'

class ThingOne extends React.Component{
  constructor(props) {
    super(props)
    this.ref1 = React.createRef()
  }
  render() {
    return (
      <div>
        this is an experiment into forwarded refs
        <br />
        Please check this box:  
        <input type={"checkbox"} ref={this.ref1} />
      </div>
    )
  }
}

export default ThingOne

We use this Ref (ref1) in the render method, when we call

<input type={"checkbox"} ref={this.ref1} />

Here, we’re telling React when it renders the dom, a reference will be stored back onto the value in the current slot in our Ref.

If you examine the Ref after React has rendered, you get something different:

Now, the Ref’s current value is a reference to the DOM element. That means that it can be treated like a “native DOM element” because it is one.

Finally, in our little baby example, we’ll attach an onClick handler to the boxChecked handler.

import React from 'react'

class ThingOne extends React.Component{
  constructor(props) {
    super(props)
    this.ref1 = React.createRef()

    // if you don't bind your method then boxChecked will be called
    // without `this` in scope
    this.boxChecked = this.boxChecked.bind(this)
  }
  boxChecked(event) {
    const dom_elem = this.ref1.current
    const is_checked = dom_elem.checked
    alert("This box is now " + (is_checked ? 'CHECKED' : 'UNCHECKED'))
  }

  render() {
    return (
      <div>
        this is an experiment into forwarded refs
        <br />
        Please check this box:  
        <input type={"checkbox"} ref={this.ref1} onClick={this.boxChecked}  />
      </div>
    )
  }
}

export default ThingOne

Be sure to bind it to the this object (because, err.. javascript) in the constructor, and Bob’s your uncle… once clicked, this.ref1.current now returns {current: input} as you see above. As you can see from the code in boxChecked, you can pull the DOM element out from this.ref1.current and then examine it using native HTML properties (.clicked is implemented in the browser and is a native DOM element property.)

You can see the full code for this example here.

Example 2 — With Ref Forwarding

Now it’s time to go down the rabbit hole a little deeper. And with ref forwarding, we really are traveling down a rabbit hole.
Let’s stay we want to nest ThingTwo inside of ThingOne, but be able to look at the ref for ThingTwo from code inside of ThingOne.

Let’s say we try something like this

// src/thing_one.js

import React from 'react'
import ThingTwo from './thing_two'

class ThingOne extends React.Component{
constructor(props) {
super(props)
this.ref1 = React.createRef()

// if you don't bind your method then boxChecked will be called
// without `this` in scope
this.boxChecked = this.boxChecked.bind(this)
}
boxChecked(event) {
const dom_elem = this.ref1.current
alert("ThingTwo is " + dom_elem.getBoundingClientRect())
}

render() {
return (
<div style={{position: 'relative', border: 'solid 1px green'}}>
this is an experiment into forwarded refs
<br />
Please <button onClick={this.boxChecked} type="button" > click here </button>

<ThingTwo ref={this.ref1}/>
</div>
)
}
}

export default ThingOne

// src/thing_two.js

import React from 'react'

class ThingTwo extends React.Component{

render() {
return (
<div style={{position: 'relative', top: 0, left: 0, border: 'solid 1px red'}}>
This is thing Two
</div>
)
}
}

export default ThingTwo

Warning: The above code doesn’t actually work!

It makes sense that we might think we can pass a ref as a prop from one component to another. However, because of how React passes props around, this doesn’t actually work. Moreso, it actually produces no error message or indication to the developer that this is wrong. But here’s how you know it’s wrong: If you examine the ref once the UI is rendered, you get this wrong result:

If you see the name of the Component, something is wrong. it won’t work and your ref will not be usable. What’s wrong here is that you need to forward your ref from one component to another.

Interestingly, the code in thing_one.js doesn’t change — you’re still going to pass the ref down to ThingTwo via the props.

However, for ThingTwo, you need to wrap ThingTwo’s entire implementation in React.forwardRef. This utility method will take a function and will call that function with two arguments: the props passed and the ref passed, but it will allow you to pipe the ref into ThingTwo like so:

import React from 'react'

class ThingTwo extends React.Component{
  render() {
    const {selfRef} = this.props

    return (
      <div ref={selfRef} style={{position: 'relative', top: 0, left: 0, border: 'solid 1px red'}}>
         This is thing Two
      </div>
    )
  }
}

export default React.forwardRef((props, ref) => <ThingTwo {...props} selfRef={ref}  />)

Many examples online use a pattern like ref={ref} but I personally find this confusing for demonstration. What is happening is that one variable name exists in the ForwadedRef constructor, and a distinct variable also named ref then also exists inside your component, they just happen to both be called ‘ref.’ To eliminate the confusion, I named the ref that ThingTwo receives selfRef, indicating that this variable is only ever used as the reference to DOM element that maps to the component (to ‘itself’). You can pick any variable names you want, but this example demonstrates that the variable occupies a distinct namespace in ThingTwo.

Now, if you examine your ref after rendering, it looks like so:

Note that in some cases your DOM element object looks slightly different. For example, if React renders multiple of the same component, it will keep letter-based class names on your objects (it does this as its internal mapping to the DOM).

Here’s an example from a different app (you aren’t seeing the code for this). In this case, my component has a built-in class for logo-container and the strange-looking characters that make up the other classes are correct.

The example code for example #2 can be found here.

Example 3 — With Ref Forwarding in a Styled Component

Forwarding refs is slightly tricky. Once you get the hang of it, it makes sense. Always remember that the receiving component must be wrapped in the forwarder. The final pattern to show you here is how a ForwardedRef can be used with Styled Components.

This example is just like #2, except that ThingTwo uses a StyledThingTwo to display itself

import React from 'react'
import styled from 'styled-components'


const StyledThingTwo = styled.div`
  position: relative;
  top: 0;
  left: 0; 
  border: solid 1px red;
`

class ThingTwo extends React.Component{
  render() {
    const {selfRef} = this.props

    return (
      <StyledThingTwo ref={selfRef} >
        This is thing Two
      </StyledThingTwo>
    )
  }
}

export default React.forwardRef((props, ref) => <ThingTwo {...props} selfRef={ref}  />)

You will note that because StyledThingTwo is a functional styled component, it doesn’t need its own forwarded ref wrapper. Only the ThingTwo needs to be wrapped in the forwardRef call.

Categories
Tech Industry

Brooklyn JS #75 (13 Jan 2020)

Thomas Bery told us about his project to build jambuds.club, a social listening platform he has been working on as passion project.

Fil Zembowicz, who says he runs a company called FormSort, gave a talk called “Grappling with Higher Powers”. @fzembow on twitter.

Jessie Wu talked to us about building automated phone systems using Amazon connect with Amazon Lex. She pulled of a successful live demo of Hotling bling.

Travis Fisher then gave us some opinions about open source.

Finally, Tom Luttg finished off the evening with a talk called “Keeping Neural Networks Weird”


The musical guest for the evening was Jake from Baby Got Backtalk

TODO: look up saasify.sh