[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 24
File: swift_calculator.webm (1 MB, 744x1336) Image search: [Google]
swift_calculator.webm
1 MB, 744x1336
r8 my calculator design edition

Previous Thread: >>54339493

What are you working on /g/?
>>
>>54347773
Does it work on Gentoo?
>>
Sorry anon, you were 30 seconds too late
>>54347762
>>
>>54347773
>iOS
Disgusting
>>
>>54347795
no but it's open sores just like gentoo

>>54347846
At least it's not Android
>>
File: 1462195553898.png (90 KB, 963x866) Image search: [Google]
1462195553898.png
90 KB, 963x866
Hey /dpt/,
We've started a slack group with the aim of organizing the studying of books related to CS/math/philosophy.
This Sunday we finished past projects and are starting some new ones, namely:
1)SICP
2)Networking
3)Goedel, Escher, Bach
4)Set Theory
5)Logic II
https://docs.google.com/spreadsheets/d/1A_zbRf7YoiY_454INuLXEuSuW3ro0rZtaGJtnIb4XNw here's the schedule.
If you're interested, then leave your email here (making a fake one is recommended, needed only for an activation) and I'll send an invite.
>>
any programmers interested in joining a game dev?
>>
>>54347987
Sounds cool
>>
File: 1452813272440.jpg (210 KB, 1278x2170) Image search: [Google]
1452813272440.jpg
210 KB, 1278x2170
WHO SPAGHETTI CODE HERE?

I feel like everything I program can be done much more efficiently. Feels like I'm fucking duct taping everything to work.
>>
>>54347987
[email protected]
>>
>>54348578
Are you me?
>>
>>54348400
Sure
>>
>>54347773
>Space cowboy
I'm working on a syntax theme for my editor that is themed after that, what does it look like?
>>
>>54347987
[email protected]
>>
>>54347987
[email protected]
>>
>>54348578
same, but nobody else reviews my code so i never really improve.
>>
>>54347864
>>54347846
>not firefox os
ishygddt
>>
I need to pass around a file through multiple functions and Im not sure how to create the variable for it.
Would either of these accomplish what I want in c++
ifstream myfile;
myfile('txt");

or

ifstream myfile;
myfile="txt";
>>
>>54351572
The first one
>>
>>54351603
thanks
>>
File: 2016-05-02 23_34_48.png (50 KB, 1131x846) Image search: [Google]
2016-05-02 23_34_48.png
50 KB, 1131x846
Modelling a quadrotor in matlab/simulink. I think I just got the rotor model working...
>>
>>54347987
freebird (at) teknic.io
>>
How does one go about implementing hooks in C?

Currently trying to write a plugin api for a core lib I wrote a year ago that I'm rolling into an application. It's voice modulation software with the core lib being a collection of low level transform functions. Basically want people to be able to insert their own transform stages, but don't really know how to do it.
>>
>>54348578
>spaghetti code
Anon, getting away from that is easier than it sounds. Function are like cli tools, they should do one thing, and do it well. If you need to build a complex function, do it by chaining smaller ones _where appropriate_ with appropriate named titles. At the end of the day your program will only ever be as good as the API you develop internally.
>>
>>54347987
[email protected]
>>
>>54347773
it's a calculator/10
>>
>>54348400
6figures plus stocks ,signing bonus etc?
>>
>>54353654
$0.00

maybe a hot pocket if you do really well
>>
>>54352125
Function pointers senpai.
>>
python is fucking shit, fucking delusional babby's first imgur scraper script reddit tier shitters
>>
>>54354820
You already said that >>54354812
>>
>>54354832
woah how fucking fascinating

here's your (You)
>>
>>54354820
(You)
>>
>>54354851
He's a Java fanboy too
>>
Am I crazy or is it not possible to run a function from inside the run function of a thread
so would something like this work?
thread::run()
{
dostuff();
}
>>
>>54354855
no i'm just not a fucking relic of the past that thinks java is slow because of shitty web apps from another decade
>>
>>54354863
Why not just std::thread(&dostuff)?
or std::thread([&]{ return obj.doStuff(); })
>>
>>54354870
Java is slow because of bytecode, garbage collection and OOP
>>
>>54354890
java is not slow especailly not compared to python you fucking retard
>>
it's this fucking sperg shit over and over again

fuck you i'm not doing this

fucking kill yourselves and it's your loss anyway if you believe java is bad and python isn't bad AHAHAHAHAHAHA fucking pathetic sad cunts
>>
File: lol.gif (2 MB, 325x244) Image search: [Google]
lol.gif
2 MB, 325x244
>>54354895
>Java is not slow
>compared to Python
holy shit anon, and hear I didn't think you were capable of making me laugh
>>
>>54354906
(You)
>>
>>54354884
Because I have no idea what youre doing. Its been a while since I learned threading and if I remember correctly the solution was just to start another thread
>>
>>54354921
I don't know what you want

>>54354920
Anon you're doing it wrong. (You) is not an excuse to avoid a valid argument, like calling you out on saying you can run faster than a disabled kid
>>
>>54354884
if it helps to understand what Im doing. I want to run the function inside a while loop in the thread.
so really it would be
thread::run()
{
while (bool)
dostuff();
}
>>
>>54347987

[email protected]

pls
>>
>>54354935
Is dostuff() a member function or a loose function?
std::thread([&boolvar](){ while (boolvar) doStuff(); })
>>
>>54354934
>valid argument
like that "12yo simulator"

pathetic
>>
>>54354935
well I guess I could try put the function in line, but thatd be the second dirty patch Id be making to this.
>>54354954
its a member function.
>>
protonmail vs tutanota
>>
you pathetic spergs fucking suck at life it sucks to be you

meanwhile i'm rich as fuck i don't give a shit what delusional beliefs you have about some programming languages lmfao i don't need to convince you of anything and you'd refuse to change your mind anyway (because you're literally spergs)
>>
File: leavemealone.webm (372 KB, 400x300) Image search: [Google]
leavemealone.webm
372 KB, 400x300
Ask your favorite programming literate anything (IAMA)

>>54347987
Invite me please

[email protected]

>>54354890
>Java is slow because of bytecode
No

>garbage collection
Yes

>and OOP
No

>>54352125
uint i;
void (*hooks)(void)[10];

bool registerHook (void f(void))
{
assert(i < 10);

hooks[i++] = f;
}

void callHooks (void)
{
for (int j = 0; j < i; ++j)
hooks[i]();
}
>>
>>54354996
GC only causes problems if you create tons of object instances because you have no idea what you're doing
>>
>>54354963
I see you learned what a red herring was
Remind me how replying to someone throwing around big 12 year old insults is any kind of debate or discussion where I should be worried about putting forward arguments

>>54354968
Is the bool a member?

>>54354996
Yes to all three. Bytecode is slower than native code. Garbage collection obviously. OOP is slower than procedural.
>>
>>54354954
Im not sure whats going on here.
Is there a good place where I can find an example?
>>
Can someone give me an estimation of how long or difficult it would be for a somewhat beginner C programmer (not exactly beginner, but not exactly comfortable either) to write a text-only web browser (like Lynx but less complex) using C?
>>
>>54355039
[](){} is lambda syntax, it's kind of like an inline function but it's actually an inline function object (so you can capture objects by reference)

auto function = [captured variables](function parameters){ function code; }

to capture by value
[var]
reference
[&var]
this (if you're inside an object)
[this]
to set a default capture mode
[=] value
[&] reference

e.g.

float num = 5.f;
auto adder = [&num](float a){ return a + num; }
adder(3.f); // 8.f
num = 6.f;
adder(3.f); // 9.f

std::thread(function)
>>
>>54355060
not too difficult and maybe a few weeks if you just want something that "works"
>>
File: bench.png (183 KB, 1050x750) Image search: [Google]
bench.png
183 KB, 1050x750
>>54355012
A gc need 5x more memory to reach an execution almost as fast as with implicit memory management. Memory consumption is also a performance indicator.

>>54355037
>Bytecode is slower than native code.
Clang compiles a program into llvm bytecode then that bytecode is compiled into native code. Java does the same but at runtime.

>>54355037
>OOP is slower than procedural.
OOP gives more optimization rooms. OOP can be both procedural or functional.
>>
>>54355092
>A gc need 5x more memory to reach an execution almost as fast as with implicit memory management. Memory consumption is also a performance indicator.
Check out the Go gc.
>>
>>54355092
>but at runtime
Yeah, that's the point

>OOP gives more optimisation rooms
No it doesn't
>OOP can be procedural or functional
Not really, you're just interfacing with functional and procedural concepts
>>
Thinking of writing a basic encryption tool to hide lewd pics of me and my gf. Would it be okay to just hash a password, then add that has to every byte of the file? then to decrypt, just subtract the has of the given password? It's super simple and not safe at all but all I'm going for is 1 step ahead of prefixing the file name with '.'

Any flaws I'm note foreseeing?
>>
>>54355037
>x paradigm is slower than Y paradigm
should I be laughing or worried
>>
>>54355117
excuse the phone typos

s/ has / hash
s/note/not
>>
>>54355127
>it's an >all paradigms are equal< episode
>>
>>54355117
Give them to me and I'll store them safely :DDDD
Don't even bother writing your own encryption tool. Just write a front end for gnupg or some other tool.
>>
>>54355156
I was planning on doing it for fun but might as well just use gnupg.
>>
>>54355151
>it's a >black and white thinking< episode
>>
>>54355184
>>x paradigm is slower than y paradigm
>closed minded para-racist!
>>
>>54355194
>>C++ is multi-paradigm and it's one of the fastest languages
>lalallala can't hear you
>>
>>54355177
Obviously you can write your own implementation of AES if you're into that.
>>
>>54355066
thanks for the help.
But it turns out Im just dumb and had an off by 1 error crashing my code.
>>
>>54355214
>C++ is not an OOP-only language and it's one of the fastest languages
>C is not an OOP language and it's one of the fastest languages
>Assembly is not an OOP language and it's one of the fastest languages
>>
>>54355258
any sizable C program uses a form of OOP
>>
>>54355258
>C++ is not an OOP-only language and it's one of the fastest languages
>C is not an OOP language and it's the fastest high level language
>Assembly is not an OOP language and it's the fastest language
>>
File: why.jpg (26 KB, 524x350) Image search: [Google]
why.jpg
26 KB, 524x350
>>54355108
Go gc has a good memory consumption but the execution speed is still lacking.

>>54355113
What point ? What is slower is that sun micro systems choose to JIT compile only the hotspots, not to AOT compile the entire program like it's now done on android. The problem is not the program being bytecode or not but what you are doing with that bytecode.

>>54355113
>Not really, you're just interfacing with functional and procedural concepts
An object's interface can be procedural, functional, or both. OOP is only a data abstraction technique.
>>
Hey /dpt/, I've got a problem with my project. I'm making a more primitive version of msPaint in c#.
One of the functions is that when you you press the "Randomize" button, all Squares, Circles etc. change location. Since I don't know how many shapes the user will create (using predefined functions to draw specific shape) I tried to use List, draw new shapes over the existing ones with same color as background and draw new ones at random XY. The problem is that it doesn't really work and the best result was when shapes apeard in horizontal line to my drawings. Any help?
>>
>>54355389
kill yourself
>>
>>54355092
OOP leads to overly separated code along line that make sense to humans but it ends up being more difficult for compilers to optimize
>>
>>54355275
not true
>>
>>54355441
nice meme
>>
>>54355275
rubbish. Large c programs have been written for decades. no inheritance, no polymorphism, no encapsulation.
Good times, I miss it.
>>
>>54347773
>"Select your color!"
>"!"
why?
>>
>>54355502
>color
>not colours, colour scheme or colour set
>>
>>54355523
>colour
>ou
kill yourself
>>
>>54355531
Dumb american.
>>
>>54355531
>COLL ORE
>>
>>54355541
>britbong is the entire world outside of america
retard
>>
>>54355464
any examples ?
>>
>>54355574
You mean English.
You know, the language Americans (+ the civilised world) speak
>>
>For faster builds, increase the maximum heap size for the Gradle daemon to more than 5120 MB.
What the fug? It's just some glorified Android fart app.
>>
>>54355258
cancer. You are disgrace to this industry. Dumbest comment I have seen today.
Nobody writes non-OOP C++
A language cannot be fast/slow itself.
Assembly is not the fastest, as compilers are better than humans for big projects
>>
>>54355587
no i'm talking about geography for fuck's sake you assumed i'm american just because i write color when the fact is the vast majority of the world says color and not just america
>>
>>54355608
vast majority of the world don't learn English as a first language
>>
>>54355597
it's just the MAXIMUM, not what it'll actually use, and gradle can deal with big projects, and it's a build system not a fart app, and you don't have to use it so fuck off dweeb
>>
>>54355608
vast majority of the world studies American English that still doesn't mean Brits should abandon their native language.
>>
>>54355617
people in any country that's not a complete shit hole learn english at least as a second language

>>54355624
yes it is british english is fucking shit
>>
>>54355605
>non-OOP is cancer
>nobody writes non-OOP C++
>a language cannot be slow/fast itself
>the industry

Holy shit you're quite the little carcinogen aren't you

>>>>the industry
>>>/v/
>>
>>54355632
>British English
You mean English. There's American English and there's English.
>>
friendly reminder that >>54355636 is a delusional butthurt sperg and it's pointless to have a "discussion" with him
>>
>>54355648
delusional as fuck

kill yourself
>>
>>54355636
I never said non-OOP is cancer. I said you are cancer.
>nobody writes non-OOP C++
When you graduate from your community college, you will understand.
>a language cannot be slow/fast itself
It cannot
>>
>>54355605
>Nobody writes non-OOP C++
I can name a few. Myself included.
It's mostly for parameter and operator overloading and some other quality of life updates.

But most of the time they actually go to the extra effort of making it ANSI C compliant.

I'm just more productive when writing procedural code. And I find it much more readable too.
>>
>>54355632
>yes it is british english is fucking shit
personal opinion. For me, british English is better and I am a guy who studies in an American university.
>>
>>54355667
>I'm just more productive when writing procedural code. And I find it much more readable too.
because you're a stupid sperg

stick to writing C instead of writing fucking ANSI C compliant """"""""C++""""""""
>>
>>54355673
lol cuck
>>
>>54355667
Have you written anything bigger than a mergesort?
>I'm just more productive when writing procedural code. And I find it much more readable too.
Anything worthy includes a mix of procedural and OO code. For most problems, OOP makes much more sense.
>>
>>54355663
Interpreted-only languages are necessarily slower
OOP is a bad paradigm with many negative ideas
You said I was cancer because I was saying OOP was slower. It is slower.
Sorry, I meant to say because you didn't have a valid response.


>>54355681
>""""""C++""""""
I didn't realise Bjarne was in the thread
>>
>>54355714
>Interpreted-only languages are necessarily slower
Interpretation is not a language spec but just an implementation.
>OOP is a bad paradigm with many negative ideas
such as?
>You said I was cancer because I was saying OOP was slower. It is slower.
How can a language paradigm itself be slower? I can write an OOP to procedural compiler, will it make it fast in the end?
>>
>>54355681
Why? Every platform I ever make something for has a C++ compiler.
Might as well use it for the occasional c++ feature I need.

>>54355698
>Have you written anything bigger than a mergesort
Right back at you.

>procedural and OO code
Why?
Don't get me wrong. I'm not against objects. I'm against programming the OOP way where you have to think of your code in objects.
However i dislike mixing styles. There really is no difference between

struct Foo { void Bar(), ... };

and

struct Foo { ... }; void Bar(Foo* foo);

encapsulation is a meme.
>>
how do you choose a language?
I know absolutely nothing about programming. I was thinking on learn how to use the terminal (I'm running linux) and then learn python. but it seems like there's a problem with python 3 and I don't know if it's worthy.
so, how do you choose a language? wich ones you would propose to a person wich knows nothing?
>>
>>54355747
Learn either python or C depending on what you want to do.
>>
>>54355733
>Interpretation is not a language spec
Not true.
>such as
Making everything a class, considering everything harmful, insane levels of verbosity, many other things that make programming a dull, repetitive job, and many things that slow down how long it takes to write the code. All the constructors and destructors slow down the code, too.
>how can a paradigm itself be slower
The same way anything else can be slower.
>>
>>54355673
I like it more too but that doesn't change the fact that the common language on the Internet is American English.

I don't force Dutch on the Internet either, britfags should stfu.
>>
>>54355735
Most real world problems are easier if you think of your code as objects.
Any big projects includes many problems, some of which are suitable to be solved by OOP and some by more procedural code, so mixing is necessary to have a readable code.


struct Foo { void Bar(), ... };

and

struct Foo { ... }; void Bar(Foo* foo);

are different entirely.
>>
>>54355769
The common language is English, 99% is the same.
>>
>>54355779
>Most real world problems are easier if you think of your code as objects

I don't agree
>>
>>54355758
I'm not thinking on getting serious with it. I mean, giving it a profesional use or something. I just want to know a little so I better understand how things work and maybe solve some problems or develop something if I can
>>
>>54355764
>Making everything a class
OOP is not about classes. I can write a perfectly fine procedural code in Java.
>insane levels of verbosity
How is this connected with OOP?
>All the constructors and destructors slow down the code
are you trolling me?
read http://c2.com/cgi/wiki?PrematureOptimization
>>
>>54355769
> common language on the Internet is American English.
says who?
>>
>>54355794
>OOP is not about classes

>how are verbosity and OOP connected
Encapsulation, design patterns, SRP, etc etc

>are you trolling me
A constructor is a function. That's a function call. If you've got non-inlined setters and getters, that's even more function calls. If you've got a ton of encapsulation, you might be transforming the input and output a lot (in a potentially expensive fashion).
That slows down code.
Encapsulation and SRP also do, by de-localising related code, and making excessive function calls.
>>
>>54355823
Confirmed freshman.
There is no point to argue. You don't want to understand at this point. You will understand when you get your first job.
>>
>>54355779
The problem is that you don't know how your API should look before you've written your user code.
I just start writing in my main function and things that will need to become a separate function or be bundled in a struct becomes obvious.

I've seen OOP programmers do their thing. They're like "Oh i need to objects for this and that" spend 2 hours writing getters and setters for everything.
Only to find out they wrote a completely unusable API once they start with their user code. So now they have to either use their shitty api or spend another week rewriting it.

>>54355779
>are different entirely.
HAHA. All the c++ compiler does is silently add a Foo pointer to your void Foo::Bar() method.
I'm guessing you think virtual functions work like magic as well?
>>
>>54355735
>There really is no difference between
>struct Foo { void Bar(), ... };
>and
>struct Foo { ... }; void Bar(Foo* foo);
>encapsulation is a meme.
kill yourself retard
>>
>>54355847
Let me guess. The next thing you'll say is that Java is not OOP
>>
>>54355864
nice argument.
>>
>>54355747
well you already fell for the linux and python meme so you're pretty much fucked
>>
>>54355871
stay delusional retard and you're not entitled to a "valid argument"
>>
>>54355787
>so I better understand how things work
Then go for C
>>
>>54355853
>HAHA. All the c++ compiler does is silently add a Foo pointer to your void Foo::Bar() method.
I am not talking about the resulting machine code. The resulting code is completely meaningless for this argument.

>They're like "Oh i need to objects for this and that" spend 2 hours writing getters and setters for everything.
were they Indian?

>The problem is that you don't know how your API should look before you've written your user code.
Wrong. Of course you have to refactor some code but that's true for any style.
>>
>>54355582
All of them, because C supports none of these features.
>>
>>54355899
>The resulting code is completely meaningless for this argument
You're trolling right.
>>
>>54355866
As I said, I can write a perfectly fine procedural Java code.
>>
>>54355908
C is turing complete RETARD
>>
>>54355908
You can always do them yourself in C


>>54355913
Write a Java program without a single class
>>
>>54355911
We are comparing paradigms, that is, comparing things that are of higher level abstraction, so the resulting machine code is meaningless.
>>
>>54355898
I'll take note of this, thanks.
I don't enter on this threads normally as I don't know about code. but I was expecting to find some links with info at the OPs post, like in other threads of this kind, so I didn't have to bother no one, but there's nothing.
>>
>>54355908
open a book on C then read about incomplete types, tard.
>>
>>54355780
>>54355811
Common sense, naturally you should be able to figure that out given you're not delusional.

For something more concrete: programming languages accept "color", not "colour".
>>
>>54355921
Class doesn't imply OO. In the same way OO doesn't imply classes(see JS). Why am I even wasting time on you, I am out.
>>
>>54355921
No you can't. It has to be supported by the compiler.
>>
>>54355922
>lets compare paradigms
>real world examples and practices don't matter
>it doesn't matter that 99% of OOP is x, where x is bad, because I don't do x
>I can write in a good paradigm and that means my bad paradigm is less bad
>>
>>54355933
That must be right after the chapter of late binding and type safety I assume?
>>
>>54355940
What the fuck are you barking, you fucking imbecile? The way compilers translate the code is meaningless when comparing OOP and procedural programming.

>it doesn't matter that 99% of OOP is x, where x is bad, because I don't do x
kill yourself, Pajeet.
>>
>>54355935
>Class doesn't imply OO
>OO doesn't imply classes

Oh, I didn't realise you were using THAT definition of object oriented. You know, no objects.

>>54355936
No, I don't mean what he was saying (language features), I was saying you could do it in C
Inheritance is just the same as storing virtual function pointers in the class (but since instances share a common set, they have a pointer to a table that contains it instead)
>>
>Oh, I didn't realise you were using THAT definition of object oriented.
Again I am talking about the conceptual stuff, not the language-specific tricks.
>>54355958
You can do everything with assembly, why don't you do it?
>>
>>54347987
[email protected]
>>
>>54355958
Storing pointers to functions is not the same as inheritance, polymorphism or encapsulation.
>>
>>54355978
>the conceptual stuff
>no classes
What are you talking about?
Even if you went by your minimalistic oop (that certainly is NOT reflective of the majority of OOP - SRP, design patterns, encapsulation, etc) which is apparently just a . operator, you still have classes because you still have limits of what functions can be done to what
>>
>>54347987
[email protected]
>>
>makes a black and white blanket statement that procedural is faster than OOP
>oh but only the worst pajeet tier code counts as OOP
>>
>>54355991
I mean like this

struct base { int x; }
struct derived { base __base; }
SomeDerived.x; // transform into derived.__base.x

struct abstractInterfaceTBL { void(*vfun)(int,int); }
void someMethod(derivedInterface*, int, int);
struct derivedInterface {
abstractInterfaceTBL __vtbl; // set to someMethod on creation
}

SomeDerivedInterface.someMethod(3,4); // transformed into SomeDerivedInterface.__vtbl.vfun(&SomeDerivedInterface, 3, 4)
>>
>>54356094
From trips' post
>>54355999

>Even if you went by your minimalistic oop (that certainly is NOT reflective of the majority of OOP - SRP, design patterns, encapsulation, etc) which is apparently just a . operator

A bunch of that slows shit down.
>>
>>54355991
>inheritance, polymorphism or encapsulation.
One of those even OOP programmers know are bad.
One can be emulated in C.
The last is completely useless.
>>
>>54356108
any sizable C program uses some form of OOP and design patterns
>>
>>54355958
a concept and its implementation are two different things. i could implement a dynamic typed programming language in C, does that make C dynamically typed ? i don't think so.
>>
>>54356130
>bad OOP code is not OOP
>good procedural code is OOP
>>
>>54356136
>memes
>memes
>>
>>54356133
Which part are you replying to?

And you can't have OOP without classes, because an object requires a restricted set of members or methods. That in itself is a class.
>>
File: 1460751987629.jpg (34 KB, 1280x720) Image search: [Google]
1460751987629.jpg
34 KB, 1280x720
>>54356141
Yet another shitty response. I hope you know I plan on coming back to these.
>>
>>54356161
(You)
>>
File: lol i trold u xd.jpg (15 KB, 325x184) Image search: [Google]
lol i trold u xd.jpg
15 KB, 325x184
>>54356178
You're officially retarded. Congratulations. You are incapable of even responding, let alone acknowledging that OOP might possibly have faults, let alone that it is "considered harmful".
>>
>>54356146
>And you can't have OOP without classes
see JavaScript. It is literally OOP without classes. (they added class keyword in the latest version though)
>>
>>54356199
>it doesn't have the word class so it doesn't have classes

To have OOP you have to have objects.
Objects have a set of what can and can't be done to them.
The set of what can and can't be done is the class.
>>
>>54356206
It didn't have any alternative keyword for what you are describing. The idea is completely different.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript
>>
>>54356198
nice meme
>>
File: 123415683.png (30 KB, 399x317) Image search: [Google]
123415683.png
30 KB, 399x317
>>54356218
No, the difference is between a static language based on offsets, and a dynamic language based on maps.

You don't explicitly create a class and then constrain the variable like in a static language, but the class is still there.
>>
>>54356239
Unoriginal comment
>>54355447
>>
>>54356247
k /care
>>
>>54356249
>>54354753
Step it up
>>
>>54356241
this has nothing to do with it being dynamic or static.

Again it doesn't have a "template"-like structure for creating objects, which is what class is.
>>
>>54356260
No, it has structure to it, what you can think of as constraints or a contract, and that is the class. As I said, the class doesn't have to be declared and then used to constrain, the class is just an abstract specification for what can and can't be done to a grouping of objects
>>
Why do I sepnd so fucking long bikeshedding...
#include "Renderer.hpp"
#include "Window.hpp"

int main() {
using namespace MuhApplication;

auto& window = Window::get_instance();
auto& renderer = Renderer::get_instance();

while (!window.is_closed()) {
renderer.render();
window.present();
window.poll_events();
}
}


How do I adjust this api so that it reflects the reality that:
Renderer::get_instance() can't be called before Window::get_instance() (both are lazy loaded and Window needs set some global OpenGL state up)?
>>
>>54356274
Window window;
Renderer renderer;

std::tie(window, renderer) = GetRenderingContext(); // returns a pair
>>
>>54356258
cool story bro
>>
>>54356096
That's beside the point. Try to replicate this in C please:

List m = LinkedList();
List k = ArrayList();


Where LinkedList and ArrayList are different subtypes of the common type List.
>>
>>54356295
>>>reddit
>>>facebook
>>
>>54356301
>try to replicate this
You mean you want OOP?
>>
File: 1457915333382.png (483 KB, 529x470) Image search: [Google]
1457915333382.png
483 KB, 529x470
>>54356315
What I meant to say was I love you.
>>
File: innocent blush.gif (2 MB, 500x281) Image search: [Google]
innocent blush.gif
2 MB, 500x281
>>54356331
>>
>>54356301
Look at GTK and GLib for an example of object oriented programming in C.

It's not pretty, but it's possible.
>>
>people arguing semantics all day long
Some things never change.
>>
File: 1457647829631.png (57 KB, 292x219) Image search: [Google]
1457647829631.png
57 KB, 292x219
>it's a C-fags think their language can do every paradigm episode
>>
>>54356363
I'm not fond of C
OOP still has flaws
Minimalist OOP is alright but still flawed
>>
>>54355881
wich meme?
I would be better using OSX?
and for python, I'm asking if it's a good idea, so I did not even fall.
is this bait?
>>
File: 1366425950550.gif (1 MB, 261x162) Image search: [Google]
1366425950550.gif
1 MB, 261x162
>>54347773
Newfag programmer here.

I'm trying to make an android app to send an int to a HC-06 bluetooth transceiver, but when I call the send method it shits the bed.

I didn't write most of it either, I just forked google's bluetoothchat example.

Anyway, I keep getting this error
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.example.android.bluetoothchat.BluetoothChatService.connect(android.bluetooth.BluetoothDevice, boolean)' on a null object reference
at com.example.android.bluetoothchat.BluetoothChatFragment.connectDevice(BluetoothChatFragment.java:347)
at com.example.android.bluetoothchat.BluetoothChatFragment.onActivityResult(BluetoothChatFragment.java:315)
and have no clue what I did to cause it or how to fix it, anybody know what's wrong?

http://pastebin.com/gyt5zDdb
http://pastebin.com/ekcFBrFV
>>
>>54356146
class is just a way to describe objects, other ways exist (prototype, high order programming, messages, ...)

you seems to be a newcomer to the subject.
>>
>>54356344
Would you be so kind as to search through those projects' source codes and post an example that replicates the example >>54356301 in C please? It doesn't matter if it's pretty or not. It just has to be equivalent.
>>
>>54356380
a prototype is a class
classes aren't just for objects
messages and method calls are basically the same in modern OOP

you seem to be a newcomer
>>
>>54356304
>>>yourmom
>>
>>54356393
A prototype is not a class.
>>
>>54356385
inheritance is bad and not inherent (pardon the pun) to OOP. we've been over this, anon.
>>
>>54356428
The prototype defines the contracts that are the class
>>
>>54356199
Javascript is not OOP because it is dynamically typed. Dynamically typed languages can never OOP. The argument about classes doesn't even matter at this point.
>>
File: 1461991255420.jpg (13 KB, 320x224) Image search: [Google]
1461991255420.jpg
13 KB, 320x224
>>54356431
Maybe but >>54356301 is subtyping and not inheritance.
You're not really gonna look through the source code for us, are you? You dirty liar.
>>
>>54356457
https://github.com/GNOME/gtk/blob/master/gtk/gtk-builder-tool.c

there's plenty of OOP fucking idiot
>>
>>54356457
here's a walk through GObject subtyping https://developer.gnome.org/gobject/stable/howto-gobject.html
>>
File: 91i328.jpg (142 KB, 740x740) Image search: [Google]
91i328.jpg
142 KB, 740x740
>>54356492
>>
>>54356503
nice argument tard
>>
>>54356505
Are you saying that code is NOT sickening?
>>
>>54347846
Fucking xcode is better than android studio fucking dogballs fucking shitty fucking IDE fuck that shit I hate it with a passion.
>>
>>54356522
C is sickening yes but i'm just giving yourself some of your own medicine with the brainless "nice argument" sperging etc
>>
>>54356492
/* Padding to allow adding up to 12 new virtual functions without
* breaking ABI. */
gpointer padding[12];


>C's OOP is limited to 12 methods per class
>>
Why do we argue about the same things every single day, /dpt/?
>>
>>54356536
>C's OOP
Glib's OOP. C doesn't have native OOP.
They could add more, but it would break the ABI.
>>
>>54356533
What are you talking about?
>>
was dpt always this shit infested?
>>
>>54356559
i thought you were the sperg from a few hours ago

>>54356545
because the most vocal posters are mostly the same thick as shit spergs that visit every day

>>54356562
more or less
>>
>>54356522
I said it wasn't pretty. But that's what you have to do to actually achieve OOP. Most people don't actually use GObject etc directly either, they just use bindings from other languages. But the point is, there's nothing you can't implement in C, even retarded memes like OOP.
>>
>>54356585
Inheritance is basically just the same as passing around a tuple of functions
>>
>>54356610
virtual functions i mean
>>
>>54351905
Kind of cool anon, I did the same in some course last year

Here's a grade A paper for the control aspects:
https://pdfs.semanticscholar.org/2e83/b6f1d6da2694dd029597911599c03b690afc.pdf
>>
do android apps give you full access to the java standard library or do you have a limited set?
like, could i make an app and use java.net.Socket out of the box?
>>
>>54347987
[email protected]
>>
>>54356756
yep
>>
File: my-brain-is-full-of-fuck.jpg (13 KB, 268x268) Image search: [Google]
my-brain-is-full-of-fuck.jpg
13 KB, 268x268
>>54356553
>>54356585
I don't think you understand the issue here. Gobject is NOT OOP just because it has a type hierarchy. The hierarchy is worthless because it has no safety. VOID IS NOT SAFE FOR FUCK'S SAKE.

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

/* parent */
typedef struct {
int i;
} parent;

void new_parent(parent* p, int i) {
p->i = i;
}

/* son */
typedef struct {
parent p;
char c;
} son;

void new_son(son* s, int i, char c) {
s->p.i = i;
s->c = c;
}

int main() {
son a;

new_parent(&a, 21);

return 0;
}


This does not compile. And why should it? It's OOP in C, which the language wasn't designed for.
Gobject's attempt at OOP isn't OOP it's just >>54356610 which is inheritance. Congratulations, you successfully emulated inheritance in C but that's not enough to be called OOP. For example, it cannot substitute inherited types with their parent types without casting to void. Don't be fooled.

/* We're just assuming that the cell layout is using a GtkCellAreaBox. */


This is the true nature of Gobject's OOP. Assuming type of objects at run time. What the fuck.

PS: I think Gobject is pretty.
>>
File: 1462175595110.gif (6 KB, 355x200) Image search: [Google]
1462175595110.gif
6 KB, 355x200
>>54356792
>parent
>son
>>
>>54356792
that's not an object, that's a data type.
>>
>>54356818
an object is a data type
>>
>>54356818
That's the point.
>>
>>54356375
>is this bait?
No, just regular /dpt/ shitposting.
> it seems like there's a problem with python 3
I have not idea what problem you mean here. That 2.7 is more popular and is default in distros? That's not that big of a problem - you can still install it, learn it and develop all you want.

>how do you choose a language?
When you know nothing about programming - pretty much randomly, then hopefully learn about programming and choose intelligently a language with the flaws that you find the most manageable to deal with.
>>
>>54356792
>without casting to void
What's wrong with that? Why does that exclude something from being pOOP?
>>
>>54356823
Not really, objects is distinct from data types in purpose, philosophy and reality. An object is not necessary a type but is implicitly typed by its interface contrary to a data type.
>>
>>54356865
Because it can't be cast back without knowing what it was in the first place so you can't do it at run-time.
>>
>>54348650
>>54348885
>>54348788
>>54352014
>>54352290
>>54354940
>>54355982
>>54356079
>>54356759
sent ;)
after this thread, we won't be recruiting anymore
>>
IMPLICIT CASTING ONLY TO HIGHER-PRECISION DATA TYPES
>>
File: pug_the_grey.jpg (96 KB, 599x602) Image search: [Google]
pug_the_grey.jpg
96 KB, 599x602
Which is better Cfags?
while (blah < halb) {
foo();
if (op == faggot)
bar();
}

OR
if (op == faggot) {
while (blah < halb) {
foo();
bar();
}
}
else {
while (blah < halb) {
foo();
}
}

Also, is it good style to initialise all your variables and functions which setup up values from the environment in a header file and use include so that it doesn't clutter the file, e.g.
foo.c

int main()
{
#include "bar.h"
printf("%d\n", blah);
return 0;
}

bar.h

int blah;
doSomething(&blah);

So that you don't have to have it clutter your main if there is a lot of them.
>>
>>54356901
>Because it can't be cast back without knowing what it was
Possible solutions:
An argument or field which tells you what type it is, like POSIX's struct addrinfo.
Probably has the least downsides, but isn't easily extendible for users.

A vtable in the parent which contains all of the behaviours you want from the parent. Inside these functions, it can be cast back to the original type, so that the fields may be used.
This one has a lot of boilerplate and overhead, but allows users to extend it.
>>
>>54347987
[email protected]
>>
>>54356995
sent ;)
>>
>>54356983
Both solutions conflict with the data hiding principle. The vtable conflicts with the subtyping principle. You cannot have information about the subtypes stored in the parent type.
>>
>>54356850
>When you know nothing about programming - pretty much randomly, then hopefully learn about programming and choose intelligently a language with the flaws that you find the most manageable to deal with.

Good point. this is a smart and useful answer. thanks.
this should be at OPs post to guide other people who know nothing
>>
>>54356933
yeah, nah
>>
Guy,

Is there a way to prevent certain code or data from being moved to virtual memory?
>>
>>54357011
How does
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>

struct animal {
void (*make_noise)(struct animal *);
void (*pat)(struct animal *);
};

struct dog {
struct animal parent;
};

void dog_make_noise(struct animal *a)
{
puts("\"woof\"");
}

void dog_pat(struct animal *a)
{
puts("You pat the dog.");
puts("The dog happily wags its tail");
}

struct dog *dog_new(void)
{
struct dog *d = malloc(sizeof *d);
d->parent.make_noise = dog_make_noise;
d->parent.pat = dog_pat;

return d;
}

struct cat {
struct animal parent;

int num_pats;
bool left;
};

void cat_make_noise(struct animal *a)
{
struct cat *self = (struct cat *)a;

if (!self->left)
puts("\"meow\"");
else
puts("The cat isn't here anymore");
}

void cat_pat(struct animal *a)
{
struct cat *self = (struct cat *)a;

if (self->left) {
puts("The cat isn't here anymore");
return;
}

puts("You pat the cat.");
if (++self->num_pats < 3) {
puts("The cat purrs.");
} else {
puts("The cat got sick of you and left.");
self->left = true;
}
}

struct cat *cat_new(void)
{
struct cat *c = malloc(sizeof *c);
c->parent.make_noise = cat_make_noise;
c->parent.pat = cat_pat;
c->num_pats = 0;
c->left = false;

return c;
}

struct animal *get_random_animal(void)
{
return (rand() & 1) ? (struct animal *)dog_new() : (struct animal *)cat_new();
}

int main()
{
srand(time(NULL));
struct animal *a = get_random_animal();

a->make_noise(a);
for (int i = 0; i < 3; ++i)
a->pat(a);
a->make_noise(a);

free(a);
}

conflict with the submeme principle?
>>
>>54357259
By being a kernel.
>>
>>54357259
write a program that rewrites their kernel
>>
>>54357319
That's always sort of bothered me. It makes it really hard to implement certain optimizations. Say I'm writing some kind of tool that i want to be running in the background, and come into view when i press some kind of hotkey, and i want it to show up instantaneously. I can't do that because I can't stop the OS from moving all that code into the page file.

Fucking sucks how slow the windows 10 start menu is to show up if you haven't used it in a few minutes.
>>
>>54357286
That's polymorphism, not subtyping. For starters I recommend you make assertions about the behavior of the make_noise and pat functions.
>>
>>54357382
in haskell ideally
and the program in nim or some other equally meme language
>>
>>54357393
It's called subtype polymorphism
>>
>>54357286
How do you determine the run-time type of a inside the for loop?
>>
>>54357447
you don't
>>
>>54357392
>I can't do that because I can't stop the OS from moving all that code into the page file
Buy more RAM.

>>54357393
>For starters I recommend you make assertions about the behavior of the make_noise and pat functions
It's just a stupid contrived example I just threw together. I was at the upper limit of lines allowed in a 4chan post, so I couldn't add any more.
Also, as the other anon said, "subtype polymorphism".

>>54357447
'a's type is 'struct animal'. But really, as it currently is, you can't tell if it's cat or dog.
However, if you're trying to use subtyping, why would you care?
>>
>>54357505
He was wondering how it dispatched
>>
>>54357524
Function pointers.
>>
So I'm digging in this class reference, and I fount something that fits my needs, but I have no idea how to use it.

void SFEMP3Shield::getTrackInfo(uint8_t offset,char * infobuffer )    


From similar pieces of code I have figured out something like this:
SFEMP3Shield MP3player;
char id3[30];
MP3player.getTrackInfo(no idea what to put here,(char*)&id3);


I tried to put something like 1 in it and it doesn't like that.
>>
>>54357590

Did you try 0?
>>
>>54357609
>how could this possibly go wrong
>>
>>54357630
It's called 'offset'.
Usually, 0 is a pretty safe bet.
>>
>>54357609
>>54357630
>>54357637

C:\Arduino\libraries\SFEMP3Shield/SFEMP3Shield.h: In function 'void setup()':

C:\Arduino\libraries\SFEMP3Shield/SFEMP3Shield.h:734:10: error: 'void SFEMP3Shield::getTrackInfo(uint8_t, char*)' is private

void getTrackInfo(uint8_t, char*);

^

sketch_may02a:136: error: within this context

MP3player.getTrackInfo(0,(char*)&id3);

^

exit status 1
within this context


This is with 0, same effect as 1.
>>
>>54357590
try 0 m8, its probably the offset it starts copying at in the buffer you provide
but really, you should just find a documentation instead
>>
>>54347864
Lemme get that sores OP
>>
>>54357647
>error: 'void SFEMP3Shield::getTrackInfo(uint8_t, char*)' is private
Did you even read the error message?
>>
>>54348400
>any programmers interested in joining a game dev?
Send me the Google developer console invite guy.
>>
>>54357661
Yeah, but I don't know how to fix that. I'm a pleb if it comes to classes.
Thread replies: 255
Thread images: 24

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.