Hidden Gems: The Null Coalescence Operator

In a previous Hidden Gems post, I covered the artistic side of programming as expressed through the use of the ternary operator. Here is the original post if you’re interested, otherwise here’s a quick summary of the concept: programming relies on the use of conditional statements, where a certain path is taken depending on the value of a variable or expression, and a ternary operator is an elegant, shorthand way of writing these conditionals. In the example below, the function isItSnowing() will return a true or false value telling us if it is snowing. If it is snowing, then we’ll stay inside, and if it is not, then we’ll go outside. The ternary operator has unlimited potential, with the ability to string multiple conditions together, but must be used carefully; just because it improves readability and style in this scenario does not mean it always will.

The null coalescence operator is a slightly more nuanced version of the ternary operator, but even more interesting due to it’s use cases. Oftentimes in programming, you want to assign a value to a variable, but you don’t know for sure that the value exists. The value might come from another source and you can’t guarantee that it was received correctly or as expected. In most programming languages, trying to use a value that was never created causes a disaster (one can easily see why), and will usually crash the program. However, programmers would usually prefer to provide some default value instead, to prevent the program from crashing. Here is that exact situation presented in relatively simple, but verbose code:

This is a fairly straightforward conditional statement, which says in plain English, “if the value of temperature is known, the message will be that value, but if for some reason we don’t have the temperature, let the message be a default warning that we don’t have the temperature”. If you’ve been paying close attention, you might have noticed that this conditional is very similar to the one we explored when discussing ternary operators, and as a matter of fact, this conditional can be expressed using a ternary operator, as demonstrated here:

Notice again the power of the ternary operator in simplifying the conditional. It compacts the same logic into one statement, which reduces the number of lines and is more efficient to run. Now behold the same statement written using the null coalescence operator:

The differences may be subtle at first, but they are extremely important. Notice that there is no expression to test whether or not “temperature” exists, as it is built into the operator. Also see that it automatically assigns the value of “temperature” if it exists. Finally notice that the default message comes after the null coalescence operator, and is assigned when the value of “temperature” does not exist. A common way to read the operator in English is “reading from left to right, give me back the first thing that exists”. This use case is extremely common in programming, which is what ultimately led to the null coalescence operator being created. Personally, I was thrilled when I discovered this: after writing hundreds of the equivalent ternary versions, I had finally discovered a way to write less code while also improving the style of my code. Once a programmer is used to using this operator, it reads much more naturally than the ternary operator and saves valuable time when trying to understand the code. This operator can also be chained, similar to the ternary operator, as shown in this example, where the default string is used if both the “temperature” and “backupMessage” variables are null:

At the end of the day, the null coalescence operator may not seem like a revolutionary idea, and it isn’t. However, it is a testament to the ingenuity and artistry of programmers, motivated by a unique combination of laziness and empathy for the programmers who follow. It is the accumulation of these small improvements that evolve into the modern programming languages we have today, which are more powerful and easier to read than ever before.

Study Hal: Week 35 – Full Inbox

Hal is a fan of cozy mornings lately. If he can take some time to drink his coffee and listen to some jazz before class, he will. Hal is also a fan of setting personal boundaries, so he tries not to check his email after a certain hour. In the before-times, that was not a problem. But, now? Logging back on feels like catching up on a novel!

Hal knows there are some of you wild folks out there who have thousands of unread emails, but Hal keeps his inbox tidy. This many emails overnight is overwhelming! We’ll cut the senders some slack, since email is about the only way of communicating outside of class anymore. At the same time, Hal supports walking away until you’re ready to process all of it.

If you’re new here, welcome! Hal is a senior studying remotely this semester. He’s back on Tuesdays, but you can check out the Study Hal tag to see more of his daily activities.

The Artist’s Panel: Story, Word, Sound, Sway

Story, Word, Sound, Sway is an exhibition that features eleven Stamps School of Art and Design alumni. It’s currently on display at the Stamps Gallery but you can also access it online at this link. After spending time with the online exhibition, I thought that more people should be aware of the amazing work being featured! Four of the Stamps alumni that have pieces in this exhibition will be participating in a virtual panel to discuss their work and how they’re using their art to combat racial injustice. The panel will take place this coming Thursday, February 18th from 6:00-7:30 PM. You can register for this live event here! I hope you all are able to check out the exhibition and participate in the important conversation that’s being fostered on campus by these eleven talented University of Michigan alumni!

Black History Month Company Spotlight

Urban Bush Women was founded in 1984 by Jawole Willa Jo Zollar. It is based in Brooklyn, New York, a non-profit dance company and the only professional African-American women’s dance company in existence. This company strives to bring forth untold stories of living as a black woman in America to light through dance. Through dance they address issues of social justice, affirming diversity, fostering community engagement and developing new audiences.

Urban Bush Women started has hair parties, a place where black women can come and do their hair together. Growing up I never had to learn how to do my hair differently than any of my friends, I honestly didn’t even know that caring for black hair was different than caring for my type of hair. These hair parties allowed women to share stories and come together as a community.

The company recognizes that everyone comes from different backgrounds and uses that as a force to drive the works they create. Trust is key to building the relationships necessary in order for each participant to get the most out of their experience at a hair party or dance class. The demand for leadership allow the group members to feel comfortable enough in a vulnerable group setting is vital- this helps foster creativity within the group. Having taken class with the dancers of the company I know how important it is for the leader to create a safe space.

Two years ago the company came to set a piece on the dance students for the departments annual Power Center show. The process of the audition and rehearsals were not only extremely physical, but emotionally liberating. The way Urban Bush Women carry out their classes is similar to the Batsheva Dance Company. All mirrors are covered, everyone is dancing facing in towards the center of the room, everyone in the room must be participating in the class. This allows the judgement of oneself to be left at the door. In class we would often find ourselves exhausting our bodies with physical moment, and with the instruction of the leader we would yell out something- whether that be a happy or sad thought. We are often left to let our movement subside and embrace the emotions that we are left with.

Here is the Urban Bush Women website: https://www.urbanbushwomen.org/

Here is Urban Bush Women “Hair and Other Stories”: https://www.youtube.com/watch?v=idHpfjroH3g

 

Mile-Long Mixtapes: Ep. 3

“Mile-Long Mixtapes”: Ep. #3

New Beginnings

by Kellie M. Beck

 

Can we ever really start over?

 

Today, (the day I’m writing this) is oddly enough the Lunar New Year. While it may not be traditionally celebrated the same as the calendar new year, January 1st, it is a celebration of newness. 

 

From what I can tell, we, as human beings, really, really love newness. We celebrate every new year, every new age we turn. We celebrate our times with our families over the holidays by giving one another new things. Every new school year, we buy our children new jeans, new shoes, new clothes. And while some of this serves a distinct purpose, (I mean, c’mon– kids outgrow their clothes at the speed of light!) newness has become a trait of modernity that I can’t help but feel at odds with. 

 

Why? Because newness, in the largest sense, doesn’t exist. 

 

I’m sure it can’t be just me– the idea of starting over is borderline seductive. And maybe that’s just because we never really get to start over– it evades us as does perfection. A fresh start is a version of perfection. But if we spend all our time pretending to start over at every new job, new semester, or every new year– when will we ever give ourselves the chance to grow? 

 

What if we all agreed that newness was impossible to achieve? I think of Walter Benjamin’s idea of what he calls “the aura”. The aura describes the appeal of aged things– how they have been altered by time is what makes them beautiful to us. I think of the old houses of Ann Arbor, or on a grander scale, the cathedral of Notre Dame. We find them beautiful for their aura. 

 

I genuinely hope the same concept can be applied to you and I. 

 

When we relinquish our desires to be new, what is left of us? The only other option for change, if we cannot start over, is to grow. I think about it like a great painting– if we throw away every canvas in which we make a mark we do not like, we will never have a masterpiece. But if we choose to stay, and reckon with what marks we have made on the page, we have the ability then to move past them. 

 

Round green shapes of varying sizes glow against the black background. The text reads, "Immersive."

Immersive #1: Life In A Day 2020

In a world that’s constantly responding to unexpected events that seek to sow division and reap unrest, the challenge of creating unity and a shared understanding among nations, communities, and families grows exponentially by the day. Nevertheless, in light of all these differences, there is the fundamental experience of life that is shared amongst all of us, generating empathy and compassion to the struggles that each and every one of us faces in hopes of a brighter tomorrow: the beautiful nature of humanity.

However, it is all too often that these nuanced and lived experiences of our day-to-day lives get ignored for larger and louder occurrences in the media and on the internet. Wanting to draw attention back to the intricacies of our daily lives and create unity within an isolated world, filmmaker Kevin Macdonald partnered with Ridley Scott to create Life in a Day 2020, a crowd-sourced documentary that sought to capture the human experience on a global scale.

A sequel to Life in a Day 2010, Life in a Day 2020 was carefully cultivated from over 324,000 video submissions from 192 countries that were all filmed on a single day: July 25th, 2020. The end result was a moving film that brought together our fears, hopes, concerns, and aspirations for the past, present, and future.

In the film, we are first exposed to the night. The chirping of crickets intermixed with the humming of an ensemble creates an intimate tone that is soon expanded upon after the waxing of the moon. A woman gives birth and then another one after that. Together, we welcome the new lives that have been introduced into the world, and we welcome a new day. The narrative soon picks up in pace, tying together short clips of urban and rural life from all across the globe. We gain a sense of cohesiveness from the rawness of the lives that are shown to us. Nothing here is foreign or strange, only human.

“This is my way of projecting my inner self into the world. Most people get stuck with what they see in the mirror every day, but there’s so much more to the universe. We just have to be willing to go beyond what we know,” the narrator remarks as a drone slowly flies away from its operator to capture an entire mountain. And to this point, I must agree. We must learn to embrace exploration and new knowledge in order to recognize the authenticity of all of our experiences.

Given the abundance of rich insights into daily life that were featured within the film, I can only wonder what other stories were left out to be able to cultivate the compelling narrative that is Life in a Day 2020; who weren’t we able to hear from because of the limited capacity of the production team? Because of the technology barrier? Because of the scope of the project? Even with all of these lingering questions at the end of the film, I still believe that Life in a Day 2020 was successful in its endeavor to create an intimate understanding of what it was like to live all across the globe on that single day in the summer of 2020.

Watch Life in a Day 2020: HERE