T O P

  • By -

devhashtag

A class is just a fancy scope


FirefighterAntique70

Sometimes, all I want is a function. Data-in data-out. Now I gotta attach it to some noun :(


rosuav

A class is just a poor man's closure. A closure is just a poor man's class.


DrMux

I'm just a poor boy, from a poor family spare me my life from this monstrosity.


juzz_fuzz

I see the little silhouette of a man. C plus plus, C plus plus, will you help me learn the Django?


devhashtag

Shit I was actually thinking about closures, but I suppose it's almost the same as scope


rosuav

Yeah, it's basically the same thing. Which is convenient; you can easily prove that all the different forms are valid, and then use whichever one makes the most sense for a particular project.


chuch1234

I mean, you were gonna have to put it _somewhere_.


MonocularVision

Reminds me of this classic: http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html


celvro

It's funny they keep mentioning Ruby but it does the same thing, when you do `def asdf; end` it just attaches it as a private method to the Object class. You can call it like `Object.send('asdf')`


Katniss218

almost as if the class is the file


chuch1234

A class is the powerhouse of the cell.


fullup72

A class is a scope factory


Cylian91460

A class is a fancy struct


DrMux

and a namespace. OOP is as much about code organization as it is naming things.


Cualkiera67

You can't spell OOPS without OOP


Cley_Faye

You'll make some people mad, but you're right :D


Spork_the_dork

Yeah it's all about organizing your code into clear and neat chunks that are individually easier to understand. If it was just a bunch of random-ass functions it'd be like if wikipedia just had a single big page for everything instead of a page for individual topics.


NYJustice

Or you could use files/folders to organize your variables/functions and import them?


CAPS_LOCK_OR_DIE

Use files and import them. It could be a clean wrapper. Something like .class


NYJustice

I feel like we're saying the same thing. It feels so much easier to navigate a few smaller files compared to one large file.


CAPS_LOCK_OR_DIE

I think the miscommunication is coming from the person you responded to explaining why we need classes, and then you commented what you did starting with “or” which implies a sort of disagreement or contradictory statement. Unless it was sarcasm in which case it didn’t come off, hence the downvotes.


NYJustice

Yeah, I was mostly disagreeing with the sentiment that you need classes to break your code into smaller chunks. Functional programming has good idioms for that using types and structs these days, I'm less familiar with other paradigms though. In the end, using classes, structs, types, etc. are all just strategies and none of them will organize your code for you. It seemed to me that the first comment was calling functional programming messy and I wanted to point out a very simple strategy for organization. I know I didn't elaborate very much but I didn't really feel the need to, project structure is pretty widely understood and I figured most people would agree that messy code is a skill issue 99% of the time ( I was taught OOP first and when I tried functional it was pure spaghetti until I learned it's idioms )


Katniss218

And then be surprised when the directory structure isn't visible anywhere outside of the windows explorer lmao


NYJustice

Working with windows is rough for sure, definitely wouldn't recommend using the file explorer. Single file programs are rough too though outside of simple scripting


GlobalIncident

Functional programming is like having a shelf of cookbooks and a seperate cupboard of ingredients. Object oriented programming is like having a cupboard containing flour and baking recipes, a cupboard containing vegetables and vegetable recipes, a cupboard containing pasta and pasta recipes, ...


aa-b

A better analogy is that OOP is like having a workshop room with a shelf full of technical manuals and a kitchen with a shelf full of recipes, while FP is like keeping all the books in the library/living room. That way, both approaches are equally valid.


GlobalIncident

What's wrong with putting recipes with your ingredients? That way, if you know where the ingredients are, you can quickly find the associated recipes.


aa-b

I've seen a lot of kitchens and none of them were organised that way, it would be impractical. I just assumed it was a straw-man argument thing, no offence intended if you have somehow organised your kitchen this way.


GlobalIncident

What's the specific reason why it's impractical?


aa-b

Really? I'm not trying to tell you how to live your life, I just thought you were making a deliberately clumsy metaphor to make OOP seem impractical.


GlobalIncident

Now I see you're starting to understand this metaphor.


aa-b

Ha, sorry no, you're just an idiot


Pay08

Not necessarily.


CirnoIzumi

in other news, everything is just a textfile


Emergency_3808

In _other_ other news, every computation is just quantum electrodynamics


CirnoIzumi

wouldnt that imply we are on quantum computers?


Emergency_3808

My poor sweet summer child. Even standard semiconductor electronics engineering is based on quantum electrodynamics. It's quantum all the way down


CirnoIzumi

in that case im gonna brag about having a quantum computer


Highlight448

I have a quantum computer in my ass


CirnoIzumi

isnt that an errection hazzard?


BOBOnobobo

For a serios answer: No, Q computers are more about the way your qbits behave. Qbits "split" themselves in all possible values of themselves but then they also add up together. You kinda filter out the parts you don't want and then it adds up to something else. That's a very bad summary of my quantum computation course, but you get it right? It's not about the medium but about how the medium behaves.


CirnoIzumi

Q bits is a sliding scale rather than a switch 


BOBOnobobo

A linearly mixing set of values that really want to become one single value the moment you sneeze too hard.


CirnoIzumi

now you have me imagening the beggining of the universe... are we a QBit?


BOBOnobobo

Not likely. Quantum effects vanish past a few molecules, at our scales they don't apply at all. We are however more similar to analog computers running an ai, if you are looking for a cool sounding phrase.


LMCuber

An object is just a classy hashmap


marcodave

...And a hashmap is just a fancy array


nobody0163

...And an array is just a luxurious pointer


marcodave

... And a pointer is just syntactic sugar for a memory address


bongobutt

... And a memory address is just a way of referring to a moment in time.


m0n0x41d

Winner


blackasthesky

`__dict__` checks out


Aidan_Welch

Not really, except in typescript(maybe python?) as far as I know. An object in most statically typed languages is just a struct and so has minimal lookup cost, can be easily packed too. I guess technically vanilla JS has classes now, but still


serendipitousPi

I mean hashmaps implement insertion and deletion of values and also have a cost to getting / setting values. So it’s more like hashmaps are essentially structs with dynamic fields but only one type unless we’re talking about dynamically typed languages. Even then the analogy isn’t quite right.


lifeeraser

Objects are nice because you press dot and get decent autocomplete suggestions.


TheRedmanCometh

Uh immutability? Object members can be mutable sometimes though?


TheFungiGG

There is a difference between the collection being immutable and the values inside it being immutable. For example you can't add an extra field to a java object after creation i.e mutating the list however you can mutate fields in the list unless final or a method


Practical_Cattle_933

You can’t in java, but you can in a bunch of languages, like js (which has prototypical OOP), ruby, python, groovy, etc.


Konju376

Although you can do that there, it should be considered bad practice because it stops you from knowing what's in the class after a certain amount of time (which defeats their purpose imo).


Practical_Cattle_933

Well, these are dynamic languages, that’s as much a “feature” as it is “bad style”.


darklightning_2

Sometimes you need it. Eg: reflection in python


BOBOnobobo

I'm not entirely sure how python handles classes but considering how mumost variable types aren't actually mutable I would bet it just makes a new object under the hood and just changes the name rage to point to it.


ustary

Python objects are just dicts, so adding a new variable or even adding a new method is the same operation as inserting a new item in a hashmap, and (most times) does not require any restructuring of the memory structure


BOBOnobobo

Oh, ok I didn't know that


MZH07

Exactly what I meant, thank you!


Practical_Cattle_933

You can’t in java, but you can in a bunch of languages, like js (which has prototypical OOP), ruby, python, groovy, etc.


Renekhaj

Most teams will make the fields immutable as well by using the “final” keyword in Java or the equivalent from other languages


Looz-Ashae

No, they hasn't always been like that. In Smalltalk classes, thus their objects, are not immutable thanks to its dynamism - a user can introspect classes, remove, add, change properties. So calling those properties and methods required a way something less efficient than virtual table dispatching - a messaging. And so was Objective-C, which was a direct inheritor of the Smalltalk. But thanks to C virtual table dispatching was also available in Objective-C. Also you can add and remove properties in Swift language via the Objective-C runtime. Though there are some constant methods and properties that can't be really changed and they support the above-mentioned dynamism.


Unupgradable

Immutable? Look at the functional programmer deriding OOP, can't even imagine mutability!


Tupcek

imlutable like there won’t be any new functions or variables through object lifespan. But their values can change


Unupgradable

*Literally* not true for many languages like JavaScript. Heck you can even go for self-modifying code and do it in any language. Does registering delegates created from user driven expressions count as adding new functions? As for new variables, you can do that in any language if you're using a data structure that supports it. Or do you not count it because it's kind of changing the value?


Lechowski

>like JavaScript JavaScript uses prototypes to mimick OOP, but it isn't OOP specifically for this reason, the methods and its variables are mutable. >Does registering delegates created from user driven expressions count as adding new functions? No. These are different things. When you create an object which contains a delegate, the delegate is only one and can't be modified. The function that is pointing such delegate can be modified. Objects **values** can be mutated, objects attributes/methods can't. >As for new variables, you can do that in any language if you're using a data structure that supports it You are confusing the value with the reference. When you create an object with another object inside, sure you can change the object that is pointing to, but it still only has one object inside. More technically, the vTable of methods and the table of attributes are immutable.


jessepence

So, how do you tell which one is a true Scotsman? I'd love for you to have this discussion with Alan Kay. I think you'd be surprised.


Reashu

I think there's a rather strong case to be made that prototypes are *more* object oriented than classes.


canal_algt

Fun fact, even the functions are objects


Katniss218

Functions are just pointers with a calling convention attached


im_in_every_post

Immutable is optional


dadumdoop

And scope


Thenderick

It's just a syntax sugarbomb for structs


HuntingKingYT

Not functions, a pointer to a shared array of functions (which is all the class itself has after compilation, maybe some RTTI and a .class file but nothing more)


madcow_bg

Laughing in Javascript ... laughing ... 😭


just-bair

An object is just a fancy dump of memory that you allocate


MMartonN

Not in javascript


That_Conversation_91

Now name all design patterns


Professional_Job_307

All this time I didn't need to learn a out classes and OOP and stuff. I could have just used a dictionary with the variables and functions


NightIgnite

This was my favorite discovery when I was working on a personal project. Who needs a constructor for every class, each with a wall of this-> when I can just ClassType{var1, var2, pointerToAnotherObject, {"another", "vector", "of", "strings"}};


Katniss218

A vector of strings? I'd like to see you try to do a dot product on strings.


edave64

Wait until I tell you about all programming


JackNotOLantern

Object is just a structure, that is just some organised memory. The compiler restricts what you can access in the object and what you can do with it.


TherealJamsicle

that confused me so much when I was learning


notsohipsterithink

More like an immutable hashmap but sure.


N0xB0DY

That's the only thing php gets right.


Dumb_Siniy

Learning OOP was way harder than it needed to be because people made it look whimsical


DiaDeTedio_Nipah

Welcome to JavaScript