DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Frameworks
  4. My Brain Can’t Handle OOP Anymore

My Brain Can’t Handle OOP Anymore

Swizec Teller user avatar by
Swizec Teller
·
May. 15, 12 · Interview
Like (0)
Save
Tweet
Share
20.19K Views

Join the DZone community and get the full member experience.

Join For Free

the other week i was working on my compilers homework – the semantic analysis part is an object-oriented nightmare. something called the visitor pattern to traverse trees and do weird stuff.

it made me want to curl up in a fetal position in the corner, rocking back and forth in a padded room, while mumbling tongues at myself. as river tam would say before running out of the room in panic “too crowded!”

what oop feels like

schizophrenic?

schizophrenic?

in object-oriented programming everything gets muddled together. functions are bundled with data, everything is codependent and there’s no telling what a function might do when you call it.

and that’s assuming there are no side-effects outside the object monad. otherwise, who knows, the world might explode!

this creates software that is impossible to understand. i used to think i could, but after a few months of functional-style programming i realized that i simply don’t have the brainpower to understand object oriented code. it’s too messy.

when you put singletons into the picture and objects using other objects it all just gets … let me give you a simple example:

foo: object {
   i: private integer = 0;
   add: function (a:integer) {
      i += a;
      return i;
   }
}
 
/* lots of code happens here, foo has been passed around, things happened */
/* foo is not a singleton though, just used a lot */
 
a:integer = foo.add(5);
 
// what is the value of a?

answering this simple question requires knowing everything . the whole execution history of foo . the whole codebase. you name it, you have to keep it in your head.

oh and did i mention class bar ? it depends on foo for a lot of its stuff. oh yeah, they got into a little friends with benefits situation last year. it all gets pretty interesting. i think bar cheated on foo with baz once, though. there’s no telling how foo might react to that!

functional programming

fp, by okeef creations

fp, by okeef creations

with a lot of gentle poking and prodding from @sbelak , i started learning functional programming about two years ago.

i was promised easy scalability, working with multiple processors without cost, expressive code, things that just work ™ and software with less bugs that is easier to maintain and shorter/quicker to write.

i may not have gotten all that, but i did get a whole new way of thinking about my craft. an easier way to understand.

at first functional programming felt like performing a lobotomy on myself by sticking hot pokers into my feet. are you sure i don’t need loops? but i do need variables don’t i? at least a bit of mutability? really? i don’t? this is some sort of hazing ritual isn’t it, any moment now you’re all going to jump up, shout “surprise” and start laughing at me.

but i kept at it. and even though my code looked horrible, i fell in love.

the first attraction of functinal style code was writing python functions that just pass data around. no storing in intermediate variables, just passing one function’s result directly into the arguments of the next function in the chain.

because who cares about reading intermediate steps? all i care for is that this chunk of code creates x . not that it first does y , then z, then pulls in a and b and combines them into x.

sure, you could define a function called x that combines y, z, a and b, but why create a new function for something that only gets called once? much better to just do something like x = a+b(y(z)) isn’t it?

a waterfall of data

plitvice falls

the way i think about code now is a waterfall of data.

you have data and every function in the chain is a ledge. the data stops falling, changes course a bit, perhaps even changes some properties, and falls onward to the next function.

in the end you have a pool. this is where your data ends up after falling through many functions and being changed. but then it flows onward to the next function, or wherever you might need it.

you might say this is really procedural programming , but i don’t like side-effects, imperative bits of code and so on. it’s still functional programming, but this is how my brain understands code. your mileage might vary.

fin

whatever way you think about your code, whatever way you visualise execution in your head … hat’s off to you, if you can handle the inherent complexity of object-oriented programming. you are a better man than i am.

i think you should give “ this functional programming fad” a try anyway. you  might like it ;)



Object-oriented programming Brain (computer virus)

Published at DZone with permission of Swizec Teller, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Benefits and Challenges of Multi-Cloud Integration
  • What “The Rings of Power” Taught Me About a Career in Tech
  • 4 Best dApp Frameworks for First-Time Ethereum Developers
  • MongoDB Time Series Benchmark and Review

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: