Communicating in Code

Communicating in Code

Writing elegant code is an extremely difficult task. In some sense, you can think of it as writing a paper in a mix of foreign languages and trying to make sure that your Spanish professor and your Mandarin professor can both read it in their native tongue. If this sounds like a difficult task, that's because it is. In our example, the Spanish professor may be your computer (or compiler or interpreter or whatever), while your Mandarin professor is likely your colleagues.

The point that I'm trying to make is that humans process things differently (and less predictably) than computers. However, when you're writing code, you're usually writing under the premise that two different entities will consume that code. One of those entities is a computer and the other entity is one or more humans. Most of the time that second entity is your colleagues or other maintainers of that code, but sometimes it may just be you. These two separate entities have very different expectations around how code is processed. It's often difficult to write code that is easily understood by the computer but also understood by humans.

Person near apple keyboard with cup of coffee beans

A mutual, shared context helps create the same level of understanding across multiple contributors in a codebase. A really great example of this can be found by comparing two technologies built for frontend web interfaces. The first being Angular and the second being React. Angular is a full-on framework for building Client Side web applications where React is a library for building reactive user interfaces. Angular has a lot of opinions on how the entire application fits together where React is more of a toolkit that you can build your own framework (or choose not to) on top of. Because of this, Angular often takes longer to learn (and is more complex because there's many more parts). My experience agrees with that. Angular took me longer to learn, but when working on our Angular codebase the entire development team had a strong understanding of what needed to be done and how the framework enabled that work. Working in React with team members across varying skill levels and opinions has shown a fair amount of friction when trying to answer questions that Angular answers for us. Sure, it's more to learn up front but when the framework provides that mutual, shared context, it's easier to keep everyone on the same page. People on the same page have a lot less that they need to communicate via code because they call fall back to the opinions and tools of the framework.

Design Patterns provide you with a way to express application architecture decisions in a way that makes sense to most contributors. Additionally, Design Patterns still have meaning to the computer as well. A great example of a design pattern can be seen when building an application that talks to multiple databases. You can leverage the Adapter Pattern to build a Database Adapter. This helps remove the need to identify which database you're working with (and which flavor of SQL or NoSQL) and instead, consumers can directly communicate with the adapter. This form of abstraction generally is considered helpful, but layering pattern on top of pattern can often make things feel more complex, too. If you're interested in learning more about Design Patterns, I'd recommend this book.

As I mentioned in the last paragraph, Design Patterns help express application architecture. Similarly, you can take your design patterns and place them in an application architecture diagram to show how the pieces of your application fit together. If the diagram is messy, something is possibly wrong with the pattern choices that were made and you may want to revisit those patterns. Alternatively, when designing a new application, start with application architecture diagram to identify patterns that would help, then implement those in code afterwards.

No alt text provided for this image

Comments provide insight into code but are completely ignored by the computer. These are most useful when you have to explain why a choice was made ("https:// we're using a for loop here instead of map because the performance really matters"). You can think of comments as a way to provide information for the human-party but keep in mind that the compiler or interpreter will ignore them. You can even use a comment to beg forgiveness from your peers, too! ??

I say that comments are ignored by the computer, but that's not entirely true. Some compilers will look for specially formatted comments to generate documentation for your code. There are tools out there that take this a step further. OpenAPI (the artist formerly known as "Swagger") helps generate documentation for your entire API using the OpenAPI specification. This means that, if you write your comments correctly, you can generate your own API specification that another developer can use a tool to parse, which in turn will generate a client for them to use to interact with your API.

Hot Off The Press: Spicy Tech ??

Prisma is an extremely interesting piece of tech to me. Prisma is a typesafe ORM for NodeJS applications. Prisma works with MySQL, SQLServer, Postgres, and SQLite. The heart of Prisma is the Prisma Schema which defines your application models and their relations (with an emphasis on being human readable). If you already have an existing database, you can use Prisma Introspect to generate a Prisma schema for the schema you already have in place! Additionally, Prisma has support for migrations and a GUI client if that's your thing (Prisma Studio). If you're looking to use an ORM in Node, I strongly recommend checking this one out!

Little Bits:

  • Bosun 0.1.0 released - Support for generating help text with flags added!
  • Flutter 2.8 released - Performance improvements out the wazoo!
  • Educative.io is a fun little way to learn with course quality instructions but all via text. I struggle a lot with certain video courses and this has been a pleasant alternative for me!

Wanna get your own Little Bit shared? Tell me here!

Eric McDowell

Senior Backend Engineer - Java

3 年

Something I have seen a lot of lately is reinventing the wheel and not leveraging tools from frameworks in use. There's a lot of things that Spring does for you, and without any special edge cases, they work for 90% of applications, but I've seen so many people rolling their own solutions for thing that are half-baked and hard to follow, and of course completely undocumented.

回复

要查看或添加评论,请登录

Brad Cypert的更多文章

  • Modern times call for modern languages

    Modern times call for modern languages

    Computing has only been around for roughly 70 years. While that may seem like a long time, it's actually an extremely…

  • Dart all the way down

    Dart all the way down

    If you're using an app and it's built with a cross-platform framework, chances are high that it's either built with…

    1 条评论
  • Type Systems

    Type Systems

    This issue is going to deviate a tiny bit from the more theoretical format. Instead, we're going to dig into why I…

  • The one on burnout

    The one on burnout

    I really, really enjoy writing code. It's both my hobby and my career, and in that sense I am extremely fortunate to be…

  • How to write less code without losing your mind

    How to write less code without losing your mind

    Today's issue is near and dear to my heart. As I've moved up in my career (in the "away from code" sense, not the…

  • Shortening the SDLC

    Shortening the SDLC

    One thing that has been on my mind a lot, recently, is how the SDLC is effected by modern development practices like…

    4 条评论
  • Read Only Memories: Optimizing Software

    Read Only Memories: Optimizing Software

    Hi! I wanted to give you some insight into what exactly Read Only Memories is. The goal with Read Only Memories is to…

    4 条评论
  • Boxing things in Rust

    Boxing things in Rust

    Rust's memory management can feel a bit intimidating for most developers. Rust gives you some control over whether…

  • Understanding Clojure's map and pmap

    Understanding Clojure's map and pmap

    Let's be honest - Part of the reason you're using Clojure is the higher order functions like . They're great…

  • Introduction to Asynchronous Processes in Clojure

    Introduction to Asynchronous Processes in Clojure

    I've been writing about Clojure for a while now, and after some requests, decided to write about Core.Async.

社区洞察

其他会员也浏览了