[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vr / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / asp / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / qst / sci / soc / sp / tg / toy / trv / tv / vp / wsg / wsr / x] [Settings] [Home]
Board
Settings Home
/g/ - Technology



Thread archived.
You cannot reply anymore.



File: 1512326955080.gif (21 KB, 618x894)
21 KB
21 KB GIF
>Car car = new Car();
>>
>>63725239
what are the fields
>>
exit(1)
>>
File: 1490679432824.png (206 KB, 800x800)
206 KB
206 KB PNG
>>63725242
String color = input.nextLine();
Double mpg = input.nextDouble();
>>
File: 1500715363750.jpg (83 KB, 507x800)
83 KB
83 KB JPG
>>63725239
var car = new Car();
>>
>>63725239
string car = "Car"
Car::Car car = new Car::Car(car)
>>
(cons 1 (cons 2 (cons 3 nil)))
>>
>>63725538
Shit change string car to Car
>>
File: 4oo1clgqd5201.png (171 KB, 591x516)
171 KB
171 KB PNG
Car<Car> car = new Car<Car>();
>>
print car
>>
>>63725559
Car::Car<Car::Car> car = new Car::Car<Car::Car>()

The beauty of C++
>>
>std::unique_ptr<Car> car = std::make_unique();
>>
>>63725239
auto mobile = old Car();
>>
File: 5fd.png (88 KB, 768x752)
88 KB
88 KB PNG
var car = { "var" : "car" }
>>
first month of programming ever I remember writing
// create blue box
String box = new String("blue");

found that quiz recently and had to sit down and reflect for a while
>>
typedef Car Shit;

Shit car { 1995, "Toyota", "Camry" };
>>
>>63725585
a modern version would be
std::unique_ptr<Car::Car<Car::Car::>> car = std::make_unique<Car::Car<Car::Car::>>();
>>
>>63725239
In Swift:
var car = Car()
>>
And her comes python, BTFOing all of the other languages
Car = car
>>
>>63725651
90s Toyotas were good though
>>
>>63725681
wut
>>
10 PRINT "CAR"
20 GOTO 10
>>
>>63725685
Yeah, but I didn't have it in the 90s.
>>
File: images(6).jpg (20 KB, 580x529)
20 KB
20 KB JPG
if __name__ == Car()
>>
>>63725681
*errors at runtime*
>>
>>63725761
def Car():
return __main__
if __name__ == Car():

There, problem solved
>>
>>63725681
well done
>>
>>63725239
I know right? why the fuck would you do this? how did this ever become so popular?
>>
$car = ['wheel' => true];
>>
>>63725588
Nice
>>
let mut car = std::rc::Rc::new(std::cell::Refcell::new(std::boxed::Box::new(Car::new())))))
>>
Car car = Cars.createNewCar();
>>
car_t *car = (car_t *) malloc(sizeof(car_t))
>>
>>63726099
>Cars
hmm
>>
>>63725239
Lmao I love this meme
>>
>>63725239
>when you name a car "car"

COME OFFIT LAD
>>
And this is why I use C and not all these other meme languages!
>>
>>63725239
memes aside, why is this bad?
>>
>>63725239
Car car1 = new Car();
>>
File: a.jpg (14 KB, 240x320)
14 KB
14 KB JPG
>>63726159
>he casts the result of malloc
>>
>>63725239
can someone explain to me why object oriented programming is a thing, i have just started learning java and dont see a use case like why use an object when you can just store the same stuff in an array
>>
>>63728350
>encapsulation
>composition
>polymorphism
>>
post POST= new post1.(post1);

fuck it, just going to farm
>>
Object-oriented programming?
do you mean, Car::Car Car-oriented programming?
>>
>>63725239
car: Car = new Car();
>>
File: brain.jpg (55 KB, 800x450)
55 KB
55 KB JPG
>>63728350
CarFactory carFactory = new CarFactory("Car Factory");
Car car = CarFactory.createNewCar("Car");
>>
>>63725519
var car = Car()
>>
>>63728350
>you can just store the same stuff in an array

arrays can only have one data type
>>
>>63728350
I now have aids, thanks

polymorphism was a little tricky to understand but now its my favorite.
>>
"Car car;" declares an object and "car = new Car()" initializes it, is that how it works?
>>
>>63728350
Easy to subdivide your code into smaller pieces that do one job well and don't care about other pieces. Of course if your architecture is shit you'll end up with a procedural abomination of tightly coupled code.
>>
>>63725239

> (car (car '((new) car)))
>>
File: 1495857926886.gif (1.9 MB, 316x213)
1.9 MB
1.9 MB GIF
>>63725664
>tfw you actually code like this
>>
>>63728350

One of the biggest problems in programming is dealing with different "states". If your program got the correct input you are supposed to be in a differnt state than without correct input, if you sort an array you are changing state with every iteration and so on.
Now ther are two major concepts of dealing with this problem.

Functional programmign tries to avoid state as much as possible by making data structures immutable and only operates through functions. If you have immutable datastuctures there's no need to hide information, because ideally there's nothing that can even crash because all function use the same inout values at any given state, only the operating functions make it a different state.

OOP takes a different approach, it encapsulates state within objects by (partially) hinding functions and data structures in itself. Those objects may or may not tell other objects what their state is and may or may not provide methods to change their state from the outside.


You can solve every problem with both approaches, but both approaches have good and bad parts. So it depends pretty much much on the nature of the problem where one approach makes sense.

Functional programming makes it a breeze to let things happen at the same time. And it's also very comfortable to add functions. But if you find out that you have to change the underlying datastuctures you can run into alot of trouble and might have to fix or rewrite all those functions and proceses.


Object oriented programming makes it easy to add/remove underlying data structures. From the outside view it doesn't matter what happens inside the object or where those data come from. But if you have to change behaviour it can be a pain in the rear, because if you change one object you have to think about what it means for it's child classes, change interfaces, add/remove other methods to make it work and so on.
>>
>>63725239
car is a car.
>>
File: images.duckduckgo.com.jpg (23 KB, 480x360)
23 KB
23 KB JPG
CAR CAR CAR CAR CAR CAR CAR CAR CAR CAR CAR CAR CAR CAR CAR CAR
>>
>>63725239
let car: Car = Car::new(make, model, mpg, hp);
>>
>>63729004
Underrated
>>
File: 1512547569964.jpg (127 KB, 710x594)
127 KB
127 KB JPG
public static <I, O> ListenatbleFuture<O> chain(ListenableFuture<I> input,
Function<? super I, ? extends ListenableFuture<? extends O>> function)
{
>>
>>63725239
The fuck is this supposed to do? Java makes no fucking sense
>>
>>63727225
wow
patrician
>>
>>63725239
var 車 カー = 車()
>>
>>63728350
A lot of people made a lot of money pushing OOP to witless businesses
>>
>>63729525
create an object car of Car class.
You have to be retarded not to understand this and it has nothing to do with java.
>>
>>63729806
can you ever do:
ClassA objectname = new ClassB(); ?
>>
>>63725239
Nignog nignog=new Nignog("nignog", "nig", "nog") ;
>>
>>63730297
technically yes(?) if both objects have sub-variables with the same identifiers. e. g. nig.nog="nignog" and nog.nog="nig"

Nig nig=new Nog("nig")
Nog nog=new Nig("nog")
>>
>>63725239
import car
>>
>>63728350
Some things are easier.
Check out Algorithms 4th edition by Sedgewick, it's the only worthwhile Java textbook
As an exercise for yourself, try implementing all of the programs in the book in a different language like C. You'll figure out which stuff is easier and which stuff is harder with OOP.
>>
>>63729525
Create a pointer to a Car object, the pointer is stored in a variable named car. Initialize that pointer to a new Car object created with the default constructor, (Allocate memory for a Car object on the heap).
It's really simple
>>
File: a.png (42 KB, 426x422)
42 KB
42 KB PNG
>>63730382
>He needs to manually allocate space for a Car-sized object
>He needs to manually allocate space for an object
>He needs to manually allocate space
>He needs to do things manually
>>
File: DJ21ODgX0AEp2IT.jpg (79 KB, 693x1024)
79 KB
79 KB JPG
>>63725239
class Car extends Vehicle implements Drivable {
@SuppressWarnings("CO2Emissions")
@Override
public Integer getWheels() throws WheelsNotFoundException {
return super.onboardComputer.getInstalledWheels();
}
}
>>
File: 4chan.gif (1.11 MB, 316x195)
1.11 MB
1.11 MB GIF
>>63730430
>impements Drivable
>>
>>63730423
It isn't manual allocation. The JVM knows how much memory to allocate for a Car without you explicitly telling it, and the GC will free the memory as soon as the "car" pointer points to a different object or it goes out of scope.
>>
File: 1406278150278.jpg (94 KB, 800x451)
94 KB
94 KB JPG
>>63725239
I don't get it.
>>
>>63730514
The JVM doesn't know shit. The compiler knows how much memory to allocate.
>>
File: 1491808208778.jpg (116 KB, 960x880)
116 KB
116 KB JPG
>>63729709
yes
>>
File: oop.png (152 KB, 1948x858)
152 KB
152 KB PNG
we need a car version
>>
>>63730568
That's bullshit. I'm a C# dev, not Java, but I know Java isn't so garbage that you can't create an interface variable and assign to it with a runtime cast.

In C#:
//Somewhere
Object someObject = new PrettyBigCar();

//Somewhere else.
ICar smolCar = someObject as ICar;


The car variable could be storing anything that impliments ICar. The compiler has no way of knowing if the cast will work at runtime. In fact the "as ICar" is only really there to tell the compiler "hey I got this, the cast will totally work". Without it, you'd get an error that an implicit cast from Object to ICar can't be done.
>>
>>63730354
nope don't get it
>>
>>63725239
>be c++ guy
>to inteligent to understand c#
>>
auto car = Car();
>>
>>63725239
YOU WOULDN'T
MALLOC A CAR
>>
>>63730694
this
>>
>>63725239
CarFactoryFactory carFactoryFactory = CarFactoryFactory.getInstance();
if (carFactoryFactory != null) {
CarFactory carFactory = carFactoryFactory.createCarFactory("CarFactory", CarFactory.class);
if (carFactory != null) {
Car car = carFactory.createCar("Car", Car.class);
if (car != null && car.hasProperty(new Property("Wheel"))) {
car.drive();
}
}
}
>>
>>63729139
really good reply anon
>>
Python is beautiful
new_car = Car()
>>
>>63728807
>he can't into OOP
>>
File: 9IaImpL.png (239 KB, 632x472)
239 KB
239 KB PNG
(car (cons x y))
>x
>>
>>63731191
Nah, factories have no valid reason to exist, when you have Reflection APIs to solve the same problem more elegant and actually more robust with less need to change the code every time you add a new class.
>>
Car[] cars = {car1 = new Car(1), car2 = new Car(2), car3 = new Car(3)};
>>
if (Cars[thisCar].getIsCar() == true) {
Car trueCar = new Car("car");
cars.add(trueCar);
}
>>
>>63725239
val car = Car()
>>
>>63728350
That's because you're a brainlet
>>
>>63731788
Car car1, car2, car3;
Car[] cars = new Car[] {car1 = new Car(1), car2 = new Car(2), car3 = new Car(3)};
>>
Vehicle i = new Car();
>>
>>63725664
>not using auto
>>
>>63725669
That's also valid Kotlin.
>>
>>63728350
IMPERATIVE REVOLUTION NOW

LINES ONLY
NO ENCAPSULATION
FINAL DESTINATION
>>
This is "piracy" in a nutshell.
>>
AbstractFactoryAdapterViewModelCarBase car = new Car()
>>
>>63731428
Is that the man?
>>
auto car = std::make_car();
>>
KMS all you can't realize it's spelled char?
>>
>>63732603
>auto
that's longer than Car
>>
>>63730940
Red pill me on factories
Why?
>>
>>63733440
Some times you want to abstract over creating objects.
>>
>>63729709
レット 車 カー = 新車()
>>
>>63725239
const car = require('node-car')
let shitMobile = new car({
color:pink,
model:caddilac
})

car.addDestination("Your mom's house")

car.invoke()
.then(output => {
console.log("Oben ub dat nazty bussy.")
})
.catch(err => {
console.log('You've got crabs!")
})
>>
>>63725538
#
>error: car is already defined at line #1
>>
can someone put this into the context of bean factory for me
>>
File: 85e.jpg (263 KB, 764x551)
263 KB
263 KB JPG
ICar car = (ICar)VehicleFactory.Create(typeof(ICar));
>>
>>63725559
extending Driveable
>>
>>63731191
Maybe he's just a car manufacturer.
>>
>>63729139
State transition can be explicitly defined with a lot of different paradigms, not just OOP.
>>
File: .jpg (77 KB, 960x639)
77 KB
77 KB JPG
>>63730430
>@SuppressWarnings("CO2Emissions")
>>
 var car:Car = new Car(); 
>>
>>63733536
Overloading mang
>>
>>63728350
otherwise your code becomes:
if
then
if
then
if
then
if
then
>>
>>63733808
if instanceof
then
if instanceof
then
....
>>
File: 1508342444433.jpg (104 KB, 951x972)
104 KB
104 KB JPG
>>63725664
const& auto car = new CarInstance::GetInstance()->Car();
>>
>>63725585
>>63725664
In C++, the best way of doing this isn't
Car *car = new Car();

or
std::shared_ptr<Car> car = std::make_shared<Car>();

or
std::unique_ptr<Car> car = std::make_unique<Car>();

or
auto car = std::make_unique<Car>();


It's actually just
Car car;

which fully initializes the Car, calling its 0-argument constructor, and has automatic storage duration (i.e. no "delete"; destructor, if any, will be called automatically) and is the most concise way to make a car out of any language in this thread.
>>
>>63727217
Honestly it isn't worse than C
struct car *car = malloc(sizeof (struct car));
typedef struct car Car;
Car *car = malloc(sizeof (Car));

Car car = new Car();

new is just an elegant way to malloc and create pointers and once you throw abstract classes and interfaces in the mix it just makes sense
>>
File: .png (4 KB, 183x275)
4 KB
4 KB PNG
>>63733808
>what are function pointers
>>
>>63734228
>car_t* car = malloc(sizeof(*car));
or
>car_t* car = car_new();
Have you used C for more than a "hello malloc"?
>>
>>63734505
>manually emulating what moderns compilers do for you
sure is dpt in here
>>
>>63734557
>muh modern X
Why not write everything in this month's meme language? Why are you using an OS written in C?
>>
>>63728350
Some things are easier to explain with objects.
Most data structures are easier to implement with objects and algorithms surrounding data structures are therefore easier to solve using objects.
Java is a bad example for anything involving math, but something like a graph is much easier to make with objects.
>>
>>63734694
Why use C? My OS is written in x86 assembly.
>>
>>63734829
And what OS would that be?
>>
>>63733796
https://onlinegdb.com/BJVmWED-f
>>
File: Untit33led.png (16 KB, 549x508)
16 KB
16 KB PNG
>>63735544
>>63733796
>>63733536
>>63725538
>>
File: 1484966990277.png (239 KB, 372x508)
239 KB
239 KB PNG
car;
>>
>>63728350
A lot of data structures make use of objects, and data structures are pretty much used with everything
>>
let car  = Car::new();
>>
>>63735582
which ide is that?
>>
>>63725519
Disgusting.
>>
>>63736221
it's the site I've linked one message before.
>>
>>63730354
NigNog obviously extends Nig and implements DinDu
Nig nigNog = new NigNog();
>>
>>63736258
thanks
>>
>>63729205
best post on 4chan right now
>>
>>63734070
This person I agree with and therefore is the most correct.
>>
>>63734070
only if the object is small enough to fit into the stack
>>
(car Car)
>>
File: 1509893022495.jpg (212 KB, 1218x1015)
212 KB
212 KB JPG
>>63725519
let car: Car = new Car();
>>
Car = new мaшинa()
>>
File: 1463824184536.png (98 KB, 612x491)
98 KB
98 KB PNG
>>63736887
ordinal not in range(128)
>>
>>63736735
Almost all objects should fit comfortably on the stack no problem at all. The only situation I can think of where an object may be big enough to worry about storing it in the stack would be an object containing a large inline array, e.g.
struct Car {
long junk[4096];
};

However, this is normally a sign you're doing something wrong.

In C++, classes which do need to manage resources like big chunks of memory typically do so themselves in their constructors and destructors (or in their members' constructors and desctructors).

Typically if you want to store a large block of memory for example, you do it like this
struct Car {
std::vector<long> junk;

Car() : junk(4096)
{
}
};


The total memory taken up on the stack when you create a `Car` instance now is not much at all. Things like std::vector only contain a few fields such as a size and a pointer to some memory, which is only a few bytes, no more than having a couple variables on the stack. It's the responsibility of std::vector itself with its constructor and destructor to dynamically allocate memory and it only needs to hold a pointer to this memory in the class itself rather than a whole array of data inlined in the class. When you do `Car car;`, all the allocation happens in the std::vector without you having to handle allocating anything yourself. And all the destructors are called when the Car goes out of scope.
>>
you guys need more Java
>AbstractCar car = SimpleCarFactoryAwareAspectInstanceFactory.getInstanceFactory().buildCar(new UniqueNameThreadSafeTransactionAwareCarNamingStrategy());
>>
>>63725239
isCarHasWheels()
>>
>>63732825
>assuming std::make_car() returns Car
>>
>>63725538

Invalid cast from Car::Car* to Car::Car
>>
Also, while we're on the subject -- my other car is a cdr.
>>
>>63737212
function isCar(car, checkHasWheels = false) { } 
>>
>>63737376
void drive(bool hasWheels) {
assert(hasWheels);
doDrive();
}
>>
>>63728350
to work as a team :DDD
>>
>>63730818
underrated
>>
class Car : public Engine, public Wheel, public Seat, public Transport
>>
>>63728350
It's a wonderful paradigm for programs that have undefined operation order. This is actually most consumer software like web browsers, music / video players, torrent software, video games, internet servers, office suites, etc.

It's generally useless for command-line or functional programs that run in a pre-defined order such as cd, ls, sed, awk, etc.
>>
>>63734070
>stack pops
>you get a pointer to hell
>>
>>63727230
It's C++
>>
Just testing some shit, don't mind me.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct entry {
int a;
int b;
char *nick;
};

int entry_cmp(const void *arg1, const void *arg2)
{
const struct entry *a = arg1;
const struct entry *b = arg2;

if (a->a != b->a)
return a->a - b->a;
if (a->b != b->b)
return a->b - b->b;
return strcmp(a->nick, b->nick);
}
>>
int main()
{
char *line = NULL;
size_t line_len = 0;

struct entry *ent = NULL;
size_t ent_len = 0;

size_t n = 0;
ssize_t ret;

while ((ret = getline(&line, &line_len, stdin)) > 0) {
int addr[4];
int nread;
>>
        // Remove trailing newline
if (line[ret - 1] == '\n')
line[ret - 1] = '\0';


if (ret != 4) {
// Invalid
continue;
}
>>
        int ret = sscanf(line, "%3d.%3d.%3d.%3d %n",
>>
            &nread);
>>
            &addr[0], &addr[1], &addr[2], &addr[3],
>>
        int ret = sscanf(line, "%3d.%3d.%3d.%3d %n",
&a, &b, &c, &d, &nread);
>>
        int ret = sscanf(line, "%3d.%3d.%3d.%3d %n",
&addr[0], &addr[1], &addr[2], &addr[3],
&nread);
>>
        if (ret != 4) {
// Invalid
continue;
}
>>
        // Remove trailing newline
if (line[ret - 1] == '\n')
line[ret - 1] = '\0';

int ret = sscanf(line, "%3d.%3d.%3d.%3d %n",
&addr[0], &addr[1], &addr[2], &addr[3],
&nread);
>>
        int ret = sscanf(line, "%3d.%3d.%3d.%3d %n",
&addr[0], &addr[1], &addr[2], &addr[3],
&nread);
if (ret != 4) {
// Invalid
continue;
}
>>
        // Remove trailing newline
if (line[ret - 1] == '\n')
line[ret - 1] = '\0';




Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.