• 1 Post
  • 31 Comments
Joined 3 years ago
cake
Cake day: February 21st, 2024

help-circle




  • WolfLink@lemmy.mltoWorld News@lemmy.world•*Permanently Deleted*
    link
    fedilink
    English
    arrow-up
    2
    arrow-down
    2
    ·
    2 years ago

    The thing is, we either get 2 more years of Biden, or 2 more years of Trump. Besides this one issue I don’t think Biden has been that bad. Trump and more broadly republicans have publicly declared their intent to move the country towards a dictatorship.

    In the election 2 years from now, if Biden is the president, we will have an interesting primary to see who is the next DNC candidate. If Trump is president, I’m not sure the country will be in a state where that’s possible (not to mention that if it doesn’t get that bad, the DNC will likely put Biden on the ballot regardless of what happens this year).














  • Say I’m doing what you describe, operating on the same data with different functions, if written properly couldn’t a program do this even without a class structure to it? 🤔

    Yeah thats kinda where the first object oriented programming came from. In C (which doesn’t have classes) you define a struct (an arrangement of data in memory, kinda like a named tuple in Python), and then you write functions to manipulate those structs.

    For example, multiplying two complex vectors might look like:

    ComplexVectorMultiply(myVectorA, myVectorB, &myOutputVector, length);

    Programmers decided it would be a lot more readable if you could write code that looked like:

    myOutputVector = myVectorA.multiply(myVectorB);

    Or even just;

    myOutputVector = myVectorA * myVectorB;

    (This last iteration is an example of “operator overloading”).

    So yes, you can work entirely without classes, and that’s kinda how classes work under the hood. Fundamentally object oriented programming is just an organizational tool to help you write more readable and more concise code.


  • To add to this, there are kinda two main use cases for OOP. One is simply organizing your code by having a bunch of operations that could be performed on the same data be expressed as an object with different functions you could apply.

    The other use case is when you have two different data types where it makes sense to perform the same operation but with slight differences in behavior.

    For example, if you have a “real number” data type and a “complex number” data type, you could write classes for these data types that support basic arithmetic operations defined by a “numeric” superclass, and then write a matrix class that works for either data type automatically.