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
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
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.
>>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?
>>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
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.
>>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
>>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 bethread::run()
{
while (bool)
dostuff();
}
>>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)
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
>>54352125uint 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"
>>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
>>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?
>>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
>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.
>>54356141
Yet another shitty response. I hope you know I plan on coming back to these.
>>54356161
(You)
>>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
>>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
>>54356301
>try to replicate this
You mean you want OOP?
>>54356315
What I meant to say was I love you.
>>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.
>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?
>>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 errorCaused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.example.android.bluetoothchat.BluetoothChatService.connect(android.bluetooth.BluetoothDevice, boolean)' on a null object referenceand have no clue what I did to cause it or how to fix it, anybody know what's wrong?
at com.example.android.bluetoothchat.BluetoothChatFragment.connectDevice(BluetoothChatFragment.java:347)
at com.example.android.bluetoothchat.BluetoothChatFragment.onActivityResult(BluetoothChatFragment.java:315)
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.
>>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
>>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?
>>54356756
yep
>>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.
>>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
Which is better Cfags?while (blah < halb) {
foo();
if (op == faggot)
bar();
}
ORif (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.
>>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
>>54357637C:\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.
>>54347846
The iPhone 5 is a few years old now. Price has dropped to about 150 USD. Still werks better than any Android phone that's the same price.
>pajeets can't install keyloggers, adware, and other nasty things
>anyone who steals it gets a brick because iCloud locks
>gets updates until at least iOS 10
Try it. You won't be disappointed.
>>54357673
Oh figured it out now. But how the fuck do I have to get my ID3 information then?
https://mpflaga.github.io/Sparkfun-MP3-Player-Shield-Arduino-Library/class_s_f_e_m_p3_shield.html
That is the class reference. I have to find the duration of the songs.
>>54357286
>>54357393
>>54357403
>>54357505
>>54357524
>>54357529
>>54357447
>>54357478
Close but no cigar. Here is the problem:void dog_make_noise(struct animal *a)
a must be of type struct dog*, not struct animal*
This becomes apparent when you try to implement functions with different parameters down the hierarchy, for examplebool (*compare)(struct animal *, struct animal *);
If you inherit the animal function pointers then the subtypes can never be independent of each other. Everything you wrote operates on the animal struct and dog/cat are just fake. Simply changing the order of the variablesstruct cat {
int num_pats;
bool left;
struct animal parent;
};
and the code completely breaks because C handles memory in-order. Your example might fool a newfag but you can't fool me.
>>54348400
What languages and frameworks?
>>54357747
>the code completely breaks because C handles memory in-order.
That's part of the idiom. You have to use the same layout if you want it to work.
>>54357747
>simply changing the order of the variables
>dog/cat are just fake
Not true. This is how C++ is normally done - whether the vtbl pointer is first or last depends on the compiler - in which case, "simply changing" the order WITH the vtbl member not hidden would break it.
>multiple dispatch
C++ doesn't have this
>>54357753
javascrpt gaem
>>54357747
>a must be of type struct dog*, not struct animal*
The function is meant to be 'private' to dog, it's only struct animal * because the C type system requires it to be that way. You can't call the methods of a subclass with a parent class in other languages either.
>This becomes apparent when you try to implement functions with different parameters down the hierarchy, for example
How the hell does it make sense to 'compare' two different types? You would be comparing something which resides in the parent.
>Simply changing the order of the variables and the code completely breaks
If you fucked with the memory ordering of other languages, they would break too.
>>54357810
C++ is irrelevant to this discussion. We're talking about C. Complete the compare function and see what happens.
>>54357841
He means multiple dispatch, where rather than the function being virtual on 1 type it's virtual in both. You can do this from single dispatch by having 1 virtual function on the first object (1 type is now resolved) call a virtual function on the second with itself (both types are now known)
>>54357853
>If you fucked with the memory ordering of other languages, they would break too.class YouAreThisDumb {
private $herp;
private $derp;
}class YouAreThisDumb {
private $derp;
private $herp;
}
lol
>>54357858
>C++ is irrelevant
No it's not, we're talking OOP features like inheritance and polymorphism in C. This is directly related to C++'s original implementation and many modern implementations.
Here's an implementation for compare that works with the two
a->make_noise == b->make_noise
>>54357896
The vtable in C++ is always at the start. If you could move it somehow, that would break everything.
>>54357896
Man, I can't wait till you fucking turn around and say that you were "only trolling lol", because it's clear you actually believe this. Holy shit, get help.
Take two pointers at the same address. Convert them to both types. Compare the addresses of a field. Are they the same?
>>54357924
Not always, and then there's multiple inheritance
>>54357935
sent ;)
>>54357902
You misunderstand. The compare(animal, animal) is the problem because you can't determine the type at run-time.
>>54357950
Why on earth would you need to know the type of the second argument?
>>54357950
What are you talking about? Simply check the function pointers
If you had a vtable, as most implementations would, you could easily add some metadata to tell you what the type is
>>54358004
What if the function pointers are identical but the types are not? If you're not inheriting functions there is no need for a class hierarchy in the first place.
>>54357999
To compare them.
>>54358037
Then use a vtable, or make functions distinct (one way to do this is to add a bunch of instructions in front of the function that basically just jump to the function, and then you have distinct pointers to the same function)
I can't fucking choose between C and C++. Wich one is better if I know only python?
>>54356961
you need to run client-side game logic either way like footstep sounds, grenades, wallbangs
>>54358037
>What if the function pointers are identical but the types are not?
They won't be. It makes absolutely no sense for two things to have all of the same function pointers and be different types.
>>54358127
C++>C
>>54358070
vtables are not type safe.
>>54358138
They are if you use them safely
>>54358144
int main() { return ('C'++ > 'C'); }
>>54358127
C is basically a subset of C++.
However OOP is a shit paradigm so you might as well just use C.
>>54358166
C++ adds a bunch of shit that isn't OOP
Features people think are OOP in C++ are useful for leveraging as non-OOP features
>>54358159
>'C'++
>Using the postfix increment operator on something that isn't a modifiable lvalue
>Claims to know anything about C or C++
Kill youself.
>>54358166
>C is basically a subset of C++.
That is nowhere near true. There are all sorts of semantic differences and C-only features.
>>54358133public class Main {
public static void main(String[] args) {
President a = new Trump();
President b = new Hillary();
President c = new Bernie();
}
}
public interface President {}
public class Trump implements President {}
public class Hillary implements President {}
public class Bernie implements President {}
>>54358186
I was just pointing out that C++ > C is an error
>>54358159
>They are if you use them safely
Flawless logic.
>>54358186
Don't be autistic. I didn't say it was an exact subset.
>>54358192
If when cast to a supertype they behave exactly the same, perhaps comparing them should return true
Consider 3.99999999999999999f and 4.0f
>>54358208
Programming is not safe
trying to get into android apps, having to manually edit the manifest.xml file by hand is getting pretty annoying
is there any plugin that does this shit automatically?
>>54358217
>perhaps comparing them should return trueint compare(struct animal *a, struct animal *b)
{
return rand() & 1;
}
>>54358177
>C++ adds a bunch of shit that isn't OOP
And? if learning C++ will teach him shit paradigms its not a good idea to learn it.
>>54358232
what's so annoying about it?
>>54358208
>Flawless logic
Not him, but yes, it is.
How is something unsafe if it's only used safely?
>>54358213
>I didn't say it was an exact subset
So basically, your statement was completely useless.
There is no point going on about near-subsets. It's a subset, or it isn't.
But even then, as I said, there are actually fucking heaps of differences between them.
>>54358213
THERE IS NO SUCH THING AS An ALMOST-SUBSET
DID YOU EVEN READ THE THREAD YOU FAGGOT
THE ENTIRE THREAD IS ABOUT SUB TYPING
HOLY SHIT
>>54358237
>>>>>IF WHEN CAST TO A SUPERTYPE THEY BEHAVE EXACTLY THE SAME
i.e. go with the fpointers
>>54358226
Not if you program in Rustâ„¢
>>54358246
>How is something unsafe if it's only used safely?
Condoms.
>>54358238
It won't, you can avoid shit paradigms completely. Learn C but write C++. Most of stdlib isn't what you'd call OOP
>>54358254
An exact subset: A < B
An "almost" subset: A <= B
>>54358274
Stop bringing the real word and statistics into this.
We're in the abstract mathematical land at the moment, and computers are deterministic things.
>>54358254
Calm down anon. Your autism is showing.
>>54358246
completely useless.
Not really. Most C code will compile with a C++ just fine without the need for extern "C" or require only some small adjustments.
Which is what I trying to point out.
>>54358261
Are you telling me that Rust isn't turing complete, or just that it doesn't let you make system calls or manage memory?
I don't know should I learn C or C++ so I will just filp a coin.
>>54358287
>Most C code
C has evolved a lot since 1989, you know. Even in C89, there are different semantics.
Modern C and Modern C++ are completely different things.
>>54358279
>Learn C but write C++.
I agree with that, however pretty much resource that teaches C++ teaches OOP.
Which is why he should start with learning C and expand his knowledge with some C++ later on.
>>54358240
having to search the docs for the xml syntax
>>54358300
C but I will learn C++
>>54358217
>If when cast to a supertype they behave exactly the same
>Trump, Hillary, Bernie
>all the same
>>54358300
It doesn't matter, just don't use OOP
>>54358360
They're all die hard liberals that couldn't care less about the constitution
>>54358255
The compare function does not necessarily need to fail on different structs. For example you could compare an int 3 to a float 3.0 and they should be equal but obviously have different function pointers etc.
How are you not getting this.
>>54358381
If you need more than virtual functions you should be using what is basically a vtable but for information
>>54358397
I hope you're not suggesting a struct that only holds two variables: pointer to arguments and pointer to methods. Because it doesn't matter how much you delegate, the main problem is determination of type at run-time which is impossible in C.
>>54356301
>>54356385
Literally a fucking union, that's it.
Have structs or whatever representing your different types of list, and a generic "List" union set to one of them.
How the fuck are you OOP tards this stupid?
>>54358586
>determination of type at run time is impossible in C
struct MyType {
int __type__;
...
}
#define typeof(X) ((int*)&X)
or more sensibly
struct tptr {
void* target;
int type;
}
>>54358613
I think he wants an open ended set
He really hasn't explained the interface at all though
>>54358360
All of them are lying scumbags.
Consider the following:interface shape
class square implements shape
class rectangle implements shapecompare function assertions
square 3 == square 3
square 3 != square 4
square 3 == rectangle 3 3
square 3 != rectangle 3 4
There is no way to do this safely in C. But go ahead, give it your best shot.
>>54358635
The interface must not know about its subtypes. The macro you wrote gives all classes information about all other classes.
>>54358613
Changing legacy code whenever there is an extension? Don't call us we'll call you.
>>54358687
>The interface must not know about its subtypes
Says who? And it doesn't. As far as it knows, they're just random numbers.
help /dpt/
iam trying to use stoi() on linux.
i included string.h but it says
>'stoi' was not declared in this scope
here is a code snippetstring temp;
int dec_temp;
getline(cin,temp);
if(temp.find("/")<temp.length()){
for(int i=temp.find("/");i<=temp.length();i++){
dec_temp= stoi(temp[i]);
dec_mask.push_back(dec_temp);
}
}#include <vector>
#include <iostream>
#include <string>
using namespace std;
>>54358687typeof(shapeA) == typeof(shapeB)
>>54358650
It's not a built-in data structure though, so it's open ended in the sense that you just change it to fit your needs.
You can even make functions that specifically take in List unions only, which is as good as inheriting class methods.
>>54358700
So waiting for Oracle to extend the class for you because it's a built-in, rather than just changing it yourself is better?
>>54358702
If you only save pointers then there is no way to make a flat hierarchy. You won't be able to compare classes with subclasses. Ergo 1:1 but it should be 1:M
>>54358711
Fails on square 3 == rectangle 3 3
>>54358737
What are you talking about? The examples I gave
struct MyType {
int type;
...
}
struct TPtr {
void* ptr;
int type;
}
Allow runtime type information.
>>54358707
Did you compile with -std=c++11 ?
std::stoi is only there since c++11
>>54356301
http://pastebin.com/LRuqR1RT
>inb4 muh undefined behavior
>inb4 muh portability
>inb4 it's harder to read than a langage created specifically for this purpose
>>54358780
undefined behaviour
not portable
harder to read than a language created specifically for this purpose
>>54358793
wait nvm, that's quite readable for C
where's the undefined behaviour? casting a pointer?
New thread
>>54358814
>>54358814
>>54358814
>>54358777
yes, in vim with:!gcc -std=c++11 % -o <filename>
and on the command line after exiting and saving the file.
>>54358829
dumbass
>>54358812
Casting a void pointer to a function pointer, IIRC.
Also I thought I used a transparent union in there, so I wrote 'inb4 muh portability', but ended up doing without.
>>54358843
What gcc version?
>>54358886
gcc version 5.3.0
>>54358912
No idea then.
>>54358921
do i need mingw?
>>54358753
no it doesn't, you don't know what typeof does
>>54358945
Maybe: http://stackoverflow.com/questions/30665366/c-stoi-was-not-declared-in-this-scope
>>54354996
cute
>>54358972
sadly still doesnt work.
I thought it was a kinda stupid question because it was about making something in VBA that's pretty entry level but I've been directed otherwise >>54358714