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

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 365
Thread images: 20

File: 1275769859420.jpg (131KB, 800x800px) Image search: [Google]
1275769859420.jpg
131KB, 800x800px
What are you working on, /g/?

Old thread: >>62363622
>>
Welp, I pretty recently found out that Windows doesn't support fmemopen.

Now I have to learn how the fuck Resources work.
>>
I've fixed the side effect problem:
    val result = Task.traverse(args)(Rss.task(client, _)).unsafeRun
result collect { case Left(NonFatal(e)) => e } foreach (_.printStackTrace)
val files = (result
collect { case Right(root) => root }
flatMap (Rss.files)
filter (!_.exists)
distinct)
(Task.traverse(files)(_.task(client)).unsafeRun
collect { case Left(NonFatal(e)) => e }
foreach (_.printStackTrace))
>>
>>62369794
>What are you working on, /g/?

homework.
>>
File: 00I0I_bF9DCt9pRqa_300x300.jpg (8KB, 225x300px) Image search: [Google]
00I0I_bF9DCt9pRqa_300x300.jpg
8KB, 225x300px
Video Game on the "Oregon Trail" franchise, solo.
>>
Redpill me on tensorflow and neural networks in general, are they a giant meme? or are they useful?
>>
>>62369794
>What are you working on?
Code monkey level Java/JS/CSS/HTML work. Hey, it's a living.
Being able to sustain yourself while still in college sure is some accomplishment, isn't it?
Anyway, how do I make coding anything in JavaScript bearable?
>>
haskell!
>>
>>62369970
I've recently started using typescript. Its really nice (for javascript), except it forces you to use the full array of javascript tooling: npn, webpack and the rest
>>
>>62369960
Even shallow properly trained neural network outperforms everything else we've got on handwriting recognition and similar tasks.
They are a meme in the sense that specializing in NNs is like specializing in building rooftops only.
>>
>>62369970
good job lad
>how do I make coding anything in JavaScript bearable?
thoroughly learning it uronically helps (not just """good""" parts). using linter, prettifier, modern versions all that jazz. es7 is pretty neat all around, especially compared to monstrosities of the past

also: typescript, elm, etc. choose your poison
>>
>>62369872
What meme language is this?
>>
>>62370045
Scala
>>
>>62369872
The program now runs in ~3s instead of ~17s by implementing parallelism.
o(^▽^)o
>>
Daily reminder to never, ever read HtDP. You'll waste your time.

Stick with SICP.
>>
>>62370057
Thanks, anon.
>>
what kind of stuff can i program in forth?
>>
>>62370107
Why though
Sicp can be bretty overwhelming for complete beginners
>>
>>62370137
Anything :)
>>
>>62370185
SICP doesn't require an extraordinary degree of mathematical aptitude. It mentions things like integrals in the examples and exercises, but most of what you need to know for them is explained in the text. The book was intended for a freshman introductory-level university course after all. If you have a decent high school math background, you should be adequately prepared. That said, if you didn't enjoy math, there's a good chance you won't like SICP either. Bt, then again, if you don't like math, why are you interested in computer science anyway?

Never read HTDP. It's trash.
>>
>>62370245
Why is it that so many people taking CS don't want to deal with anything math related?
>>
>>62370386
if they could understand math, they wouldn't be wasting their lives in CS
>>
>>62370386
It's not too bad with math. Most CS students I know are completely hopeless with anything physics related, though.

>>62370396
CS pays much better.
>>
>>62370446
>CS pays much better.
Not really. Event the most shit tier job for mathematicians or physicists (analyst) is already pretty good compared to most CS jobs. If you get into research or higher positions in organizations (more common than you may think) it becomes even better.
>>
I'm having trouble trying to create four child processes for the same father, all of them with different ID's. I just can't understand how does wait works.

#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>

int main()
{
int pid,i,x;
//int status;
pid=fork();
switch (pid)
{
case -1:
printf("\n Error ");
exit(1);
break;
case 0:
for (i=0;i<4;i++)
{
pid = fork();
printf("\n Hello I am the child process ");
printf("\n My pid is %d \n",getpid());
}
exit(0);
break;
default:
//wait(&status);
printf("\n Hello I am the parent process ");
printf("\n My actual pid is %d \n ",getpid());
exit(1);
break;
}

}
>>
>>62370487
Damn, seems I chose the wrong major. Should've gone for the comfy math degree instead of wasting 5 years with CS sperglords.
Heard that they actually have girls over at the math department.
>>
Is lisp good language to learn?
>>
>>62370561
yes
>>
>>62370551
Indeed, and some are pretty cute (even smart). The degree is actually a challenge and it's not full of retarded geeks who dedicate their lifes to playing vidya. The only downside is some degree of tech illiteracy, but that gives you bonus points for the math/programming combo everyone is looking for.
>>
>>62370551
you didn't

if you don't have a legitimate 145+ IQ, you will not cut it in pure maths, not even joking. Good luck doing research. It is a complete noob trap. Jobs are good, but they go to the top 0.5%.
>>
I don't seem to understand.
What do?
>>
>>62370639
install gentoo
>>
>>62370632
I always wonder what my IQ is after seeing these posts. Pure math was hard, yes, but I dont think I'm particularly high IQ and I passed it fine. ps CS really does make you more money
>>
File: 1502032056584.jpg (69KB, 680x680px) Image search: [Google]
1502032056584.jpg
69KB, 680x680px
Learn Haskell.
300k starting.
>>
>>62370632
>>62370654
You don't need to be a genius to get a math degree and have a good job, just enough work. Oh, and who said pure maths was the way to go? Applied is where all the money is, although pure maths are way more interesting.
>>
So why all the hate for OOP?
Genuinely curious.
>>
>>62370671
>applied maths
forgot about this thanks to being on /sci/ for too long

Yeah, this is much more reliable
>>
>>62370245
>freshman introductory-level university course
yeah
in one of the best universities in the world no less
>>
>>62370632
>implying you have an IQ above 95, let alone 145, to tell us all about how it really is
>>
>>62370709
OOP is too mainstream, we /dpt/ hipsters don't like it
>>
>>62370709
Because it's shit.
>>
>>62370709
Abused and misused by code monkeys (pajeets and freshmen) at big companies in big projects. It has serious flaws in its major implementations too.
>>
>>62370709
Productivity triggers the NEET.
>>
>>62370709
It's hip to hate on everything popular.
>>
File: Screenshot_20170911_221032.png (13KB, 728x353px) Image search: [Google]
Screenshot_20170911_221032.png
13KB, 728x353px
Working on a stock ticker program that gets live Internet data in >QT using >OOP
>>
>>62369970
>how do I make coding anything in JavaScript bearable?
TypeScript
>>
>>62370733
I got a 2.9 in Berkeley pure maths before switching my major to Chem in my 3rd year. This was with a 132 IQ (WAIS-IV measured)
>>
>>62370778
Where do you pull the data from?
>>
>>62370778
now implement a cool graph
>>
>>62370795
From Yahoo Finance
The program downloads and parses CSV files

See: http://www.canbike.org/information-technology/yahoo-finance-url-download-to-a-csv-file.html
>>
>>62370806
Is that real time or 'real time'?
>>
>>62370709
OOP is fine, as long as it's an opt-in. Forced OOP languages are cancer.
>>
File: Screenshot_20170911_221533.png (37KB, 726x281px) Image search: [Google]
Screenshot_20170911_221533.png
37KB, 726x281px
>>62370822
They're as real as it gets
>>
>>62370843
>171.26 %
I messed up there
>>
>>62370831
wrong, languages should attempt to maintain paradigmic purity
>>
>>62370868
Except there is no good paradigm out there, so the best solution is to cherry-pick the good parts out of multiple.
>>
>>62370903
the result is a language like javascript, steeples or scala
>>
>>62370926
On the other side of the spectrum we have Java and Haskell.
>>
>>62370926
C++ would be fine if someone cleaned it up and got rid of all the bloat.
>inb4 rust
>>
File: 1463064892991.png (139KB, 270x360px) Image search: [Google]
1463064892991.png
139KB, 270x360px
>>62370903
>there is no perfect car, therefore i will scrap a bunch of osme acceptable and some terrible cars and combine the junk together with duct tape
>the resulting car will be perfect
>>
File: tfw-way-too-intelligent.png (41KB, 1280x1483px) Image search: [Google]
tfw-way-too-intelligent.png
41KB, 1280x1483px
>>62370787
I have a PhD in Pure Mathematics and Mathematical Statistics from MIT and an estimated IQ of 187 and I just wanted to point out that everything you said is flat-out wrong.
>>
File: FP masterrace.png (16KB, 371x394px) Image search: [Google]
FP masterrace.png
16KB, 371x394px
>>62370943
And Java is awful because of OOP, while Haskell is good because of FP.
>>
i need to learn C++ in 3 days for my summer session final

i've only done a third of the assignments (all are due also in 3 days)

how fucked am I
>>
>>62370943
the two best languages out there
>>
>>62370960
>there is no perfect car
At least there is perfect cdr.
>>
>>62370967
Obvious bait.
>>
>>62370965
I have a high school diploma and an estimated IQ of 1337 and I just wanted to point out that everything you said is pretty ok.
>>
>>62370774
>OOP
>productivity
We can exchange anecdotes and counter-anecdotes all day long, but is there any actual evidence that OOP is in any way, shape or form better than plain old procedural programming? I've yet to see any.
>>
File: FPBP.png (136KB, 850x252px) Image search: [Google]
FPBP.png
136KB, 850x252px
>>62370989
>>
>>62370974
It depends. How basic is the course? Do you have prior programming experience?
>>
>>62370960
>>there is no perfect car
>>the resulting car will be perfect
You contradict yourself.
>>
>>62370965
>Mathematical Statistics
brainlet
>>
>>62371005
I think your screenshooter is malfunctioning. It replaced "Procedural" with "Functional" for some reason.
>>
>>62371003
Most large "plain old procedural" style projects end up emulating some sort of OOP
>>
>>62371038
>i-i-i got a 2.9 in berkeley pure maths
>doesn't know that mathematical statistics is an actual field
That's why I always believe it when people boast their credentials on the internet.
>>
>>62371032
You're a fucking idiot, obviously the car is trash

>>62371051
That wouldn't even work. That would be PPBP and not FPBP
>>
>>62371058
What did daddy just tell you about exchanging anecdotes, anon?
>>
>>62371066
>mathematical statistics
brainlet
>>
>>62371081
All cars are trash, but some have good parts inside them.
>>
>>62370498
what do you expect wait do do?
what do you expect that code to do?
>>
Is there a porno based off of the SICP lectures, yet?
>>
Speaking about paradigm purity. Smalltalk is cute, cute!

https://www.youtube.com/watch?v=eGaKZBr0ga4
>>
Friendly reminder, that structs with methods, is the best kind of OOP.
>>
>>62371105
No you fucking idiot, some cars are good but your junk amalgamation built in the scrapheap won't be
>>
>>62371105
so do you buy 4 cars and build a disgusting frankenstein car out of their parts? no! the chassis of the camry isnt compatible with the engine of the lambo. any attempt to combine cars or language paradigms willy nilly will result in a horrible abomination
>>
>>62371124
i know someone who went insane making their own fork of smalltalk
>>
>>62371155
Friendly reminder that structs with function pointers are not "OOP". They're just structs with function pointers.
>>
>>62371155
There is literally no reason to have "methods" with your structs
>>
>>62371183
function pointer != method
>>
>>62371189
Are you retarded? There's an endless number of reasons to have "methods" with your structs.
>>
Why does C++ have nullptr, NULL, and 0 to refer to a null pointer?

Do C++ null pointers refer to something other than 0x0?
>>
>>62371175
No, you take the good ideas from the design of other cars and create your own.
>>
>>62371212
>function pointer != method
A method is just a function pointer in a vtable or embedded in the struct itself.
>>
>>62371155
you mean like function pointers
>>
>>62371222
an endless number of fictional and imaginary reasons that do not apply to the reality of programming
>>
>>62371155
Agreed. I like the Go way.

func (t Type) MethodName() is the same as func Methodname(t Type). You can also turn methods in to functions and functions in to methods this way.
>>
>>62371224
nullptr is the way to go
NULL and 0 are either old or too "primitive"

nullptr is just an instance of struct nullptr_t {}, which is trivially convertible to T* for any type T.
>>
>>62371224
NULL is a relic from C, a plain old macro that expands to 0 or ((void*) 0).
0 does the same thing as nullptr but isn't as typesafe and doesn't do "the right thing" in overloads. It expresses intent like the NULL macro without being potentially misleading or unsafe, so the advice is just to do nullptr.
>>
>>62371280
>>62371281
>NULL is old so it's bad

wow great argument guys
>>
>>62371263
>muh unsubstantiated, subjective opinions matter
They don't, anon. I don't know why your mommy never explained this to you.
>>
>>62371245
designing a new language paradigm is a good idea. do it often! stuffing four or five paradigms in a single language is madness.

for example javascript has four or five different ways to do class inheritance. just awful.
>>
>>62371300
Yes. The argument is that nullptr was created because NULL was not good enough.
>>
>>62371257
Those are implementation details. It can also be implemented as a hidden function, that takes an instance parameter.
>>
>>62371304
You're the one with the unsubstantiated opinion, you have yet to give a single reason
>>
null is considered beneficial though.
>>
>>62371311
The only argument I've been able to find is that 0 decays to an integer by default, but NULL is (void *)0, so that shouldn't be an issue.
Are you telling me doing stuff like if (!ptr) is also dangerous and outdated?
>>
>>62371336
>You're the one with the unsubstantiated opinion
No, you mental midget, you're the one with the unsubstantiated opinion, as expressed here: >>62371189. I'm just dismissing it on account of your severe mental retardation and lack of any arguments to substantiate your claim.
>>
>>62371337
"I call it [nulls] my billion-dollar mistake…At that time, I was designing the first comprehensive type system for references in an object-oriented language. My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn’t resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years."
- Tony Hoare, inventor of ALGOL W.
>>
>>62371311
i created a new null pointer just now called nullpointer, because nullptr isn't good enough. do i need to provide reasons why nullptr isn't good? nah
>>
>>62371342
NULL can't be (void*)0 in C++ as it would be incompatible with most pointer types, so it is either 0 or nullptr. This decay is an issue when overloading.

I don't have any strong opinion about (!ptr), but I prefer (ptr != nullptr).
>>
NO
OPINIONS ARE WRONG
EVERY PROGRAMMING LANGUAGE SHOULD CONFORM TO THE WAY I LIKE IT
EVERYTHING ELSE IS WROOOOOOOOOOOOOOOOOONG
>>
>>62371342
NULL could be either 0 or ((void*) 0), it's implementation defined.

>>62371337
optional types > implicit nullability
>>
>>62371442
>optional types > implicit nullability
This
>>
>>62371440
"I dont like thing"
SHARING YOUR OPINION IS BADTALK. NO SHARING OF OPINIONS ALLOWED
>>
>>62371442
>optional types > implicit nullability
muh safe space! i'm so personally invested in enterprise programming that i only write in enterprise readyTM languages
>>
>>62371409
>There are no reasons
>>there are unlimited reasons
>>you have an unsubstantiated claim

wtf? you literally claim something is great and that there is unlimited reasons, i claim there aren't any reasons and yet i need to come up with reasons? what logic is this?
>>
>>62371486
So bounds checking is for pussies too, right?
>>
>>62371490
>make moronic unsubstantiated claim
>someone simply overrides it with a contrary claim
>n-no! you can't do this! you have to prove me wrong!
Take your mental retardation elsewhere.
>>
>>62371530
you literally did this, you claimed they were great, show us your reasons
there are unlimited reasons according to you

the reason you're engaging in such triviality is precisely because you have no reasons, because there are no good reasons
>>
>>62371222
>>62371263
>>62371304
>>62371336
>>62371409
>>62371490
>>62371530
>>62371556
this is the cancer that killed /g/
>>
File: Screenshot_20170911_225907.png (19KB, 728x353px) Image search: [Google]
Screenshot_20170911_225907.png
19KB, 728x353px
While you were arguing I unfucked my shit so it displays the right percentages now, take a looky
>>
>>62371567
It's his fault for claiming it's great and there are unlimited reasons and then not fucking giving any, we could have been having a productive conversation 8 posts ago
>>
>>62371580
What libs do you use?
>>
>>62371593
Just standard QT and C++ STL stuff
It's my first QT project and I'm trying to figure things out
>>
>>62371625
post source
>>
>>62371556
>the reason you're engaging in such triviality is precisely because you have no reasons
No, the reason is to illustrate to you how fucking worthless your post was. You know, the one which started this entire exchange, in which you make a moronic claim that you can't possibly substantiate. As for proving you wrong, it's trivial: putting "methods" in structs is an easy way to implement polymorphism, and it should be fairly obvious that one can thing of endless examples where polymorphism is useful.
>>
File: immunity trump.png (84KB, 351x374px) Image search: [Google]
immunity trump.png
84KB, 351x374px
>>62371580
puts("No.");
>>
>>62371650
Parametric polymorphism is superior in every fucking respect. With a decent type system (rank n types) you can do the equivalent of what you want and more. Your idea is an incredibly limited form.

Consider the following:

optional<a> parse<Readable a>(String);
This is NOT possible with "methods with structs" style polymorphism.
It IS possible with proper polymorphism, including both regular parametric polymorphism and ad hoc trait/type class stype polymorphism
>>
>>62371584
>It's his fault
It's your fault for sticking around instead of removing your family and yourself from the gene pool.
>>
File: Screenshot_2017-09-11_14-07-35.png (100KB, 714x512px) Image search: [Google]
Screenshot_2017-09-11_14-07-35.png
100KB, 714x512px
I'm reading through Tour of C++.
Do people really do things like overcomplicate enumerated types and overload the ++ operator just so they can increment through all their enum labels instead of just using incrementing an integer?

What a disgusting language.
>>
>>62371703
That looks pretty sensible to me. Guess C++ gave me brain damage.
>>
>>62371650
>>62371698
e.g. (pseudocode)

Animal = exists a. (obj : a, makeNoise : a -> String)

[Animal] animals = [pack (someDog, bark), pack (someCat, meow)]

map (\animal -> animal.makeNoise(animal.obj)) animals

>>
>>62371698
>b-b-but in muh cherrypicked language there are better ways to do it
You're mentally handicapped. I have provided you with a reason to put function pointers in structs. C, for instance, doesn't have parametric polymorphism. Now sterilize yourself.
>>
>>62371741
>posts irrelevant snippets in his meme language
>thinks it somehow saves his moronic claim
Nope. See >>62371743.
>>
>>62371743
No you haven't, you've given me trash.
Having a function and a struct is not having a method in a struct, that's absurd.
Specifically, why is the limitation that the function take a pointer to the struct type as the first parameter, and be called in the form x.f(...), a benefit?
It isn't, it's a limitation because it's for a stupid addled version of something much better.
>>
Documentation generator still
Adding enum values
>>
>>62371766
What is the point of this post? You have just made a post and then linked it again in a second post. This is fucking stupid.

There is no good reason that a language should have structs with methods.
Having types that contain functions is useful, but your arbitrary limitation and syntax purely for the sake of your stupid object analogy paradigm is stupid.
>>
>>62371768
You, like almost every other Haskell "programmer", are literally subhuman. I have provided you with a perfectly legitimate reason for having "methods" in structs. No amount of dancing around will make you look any less like viable candidate for forced eugenics.
>>
>>62371782
Can you also use solarized light? The dark version is pretty cancerous on a lot of (poor) monitors.
>>
>>62371792
No, you haven't.

Imagine a language whose integer types do not permit even numbers.
Is there a good reason for this?
Almost certainly not.

To suggest that "it's better than not having integer types" is pointless, this is not a reason to have all integer-types being even only, simply because it's better than something else.
One thing being better than another thing does NOT mean there is a good reason to have that thing when there is something so obviously better.

In C, you can in fact pack function pointers with structs, anyway.
Your "polymorphism" is implemented based upon this, which is much closer to what I described. (But with strong typing.)
>>
>>62371842
>No, you haven't.
Yes, I have. If you're working with a language like C and you need polymorphism, putting "methods" in structs is a valid way to achieve that. End of story. Every attempt to by you to recover from this embarrassment will involve some form of moving the goal post.
>>
>>62370245

While math is deffinitley involved, it's often not extensive in certain areas of computer science.

I'm not very well at math. But I am trying to be better so I can completely understand and utilize what I am learning. Hard shit though lemme tell ya
>>
>>62371869
"Methods" are strictly worse than function pointer fields.
>>
>>62371887
lol
>>
>>62371842
Why would you purposefully and deliberately put function pointers into every struct?
Even if you throw in a pointer to a static global jump table, you're still wasting 8 bytes * length of your entire array on something that has no business being compartmentalized within a struct.
>>
>>62371887
>function pointer fields are strictly worse than function pointer fields
Please sterilize yourself. You are simply subhuman.
>>
>>62371904
We're talking about polymorphism.
Anon hasn't even tried to give a single reason to justify non-virtual methods.

>>62371909
No you fucking moron, methods are LIMITED, methods require themselves to be functions taking a pointer to the struct as a parameter. There is NO GOOD REASON for this limitation.
>>
>>62371923
Can you stop shitting and drooling all over the thread? Nothing you say is going to help you save face. I have provided you with a perfectly legitimate reason to have "methods" inside structs.
>>
>>62371923
Can you explain why I would ever want to use a virtual function?
It's literally a jump table.
>>
File: 1505080830938.jpg (85KB, 1107x617px) Image search: [Google]
1505080830938.jpg
85KB, 1107x617px
>starting to hate programming
What's some interesting field to switch into for an average programmer?
>>
>>62371954
Write something fun, like a game.
>>
>>62371945
As I said before, thinking of something WORSE does not count as a "good reason" for what you do, when there is something so plainly and obviously better.

What are you even trying to say? That yes, methods are utter bumfuck retarded OOP retard trash, but there is a reason to use them over braindead fuckvegetable doodoodadaland programming?
>>
>>62371954
>having your job as your hobby
when will they learn
>>
>>62371966
hahaha
>>
>>62371980
> >having your job as your hobby
Other way around. I don't really work, just do interesting stuff and get money for it.
>>
>>62371989
If you actually enjoy programming, writing a game should be more fun than the game, you probably don't even care if you finish it.
>>
>>62371954
Distributed systems.
>>
>>62371978
The typical Haskeller is a subhuman autist. Thank you for demonstrating this obvious fact once more. :)
>>
>>62371999
are you trying to get him to kill himself
>>
>>62371978
>plainly and obviously better
Explain how.
>>
>>62372023
Imagine a method.

Now imagine you got rid of the requirement that it takes a this pointer.
>>
>>62372030
>>62372023
In fact just look at traits or concepts or type classes (all the same thing, effectively)
They are a lot less limited, because you can e.g. dynamic dispatch on something that RETURNS the """"""object"""""", rather than just something that takes it as a param.
>>
>>62372030
>a function that is supposed to modify the struct is better without having access to said struct
Simply subhuman.
>>
>>62372059
Why do you need to modify the struct?
Why can't you dynamic dispatch on something that involves the struct but doesn't take it as a parameter?
>>
>>62371224
>>62371300
>>62371342
>>62371422
it's important to note that "decltype(nullptr)" aka "std::nullptr_t" is a distinct type, which you can use to your advantage when it comes to template specialization and function overload resolution. it allows you to avoid testing values at runtime in some contexts by migrating some of the logic to the type system
>>
>>62372059
>>62372072
To add, obviously you could still have functions that take a this pointer, the point is that they would be a subset.

More importantly, the vtable is passed to consuming functions and doesn't need to be locked into the struct or whatever it is.
(Which allows, e.g., a dynamicly dispatched constructor)
>>
>>62372072
Because static dispatch is objectively superior.
>>
>>62372110
muh bloated executables
>>
>>62372115
muh shit performance
>>
>>62372149
exactly, better nail those i$ hits :)
>>
someone plese talk about something oter than than this lame boring boilerplate argument
ironic that c users that love writing boilerplate constantly love repeating these fucking mind numbing arguments
>>
>>62372110
You've never written a HOF in your life?
>>
>>62372186
that's not ironic, that's exactly what you'd expect
>>
File: Illya 570.jpg (236KB, 1378x2039px) Image search: [Google]
Illya 570.jpg
236KB, 1378x2039px
>>62372196
irony is when the viewer knows something the character in the story doesnt
so in this case, irony applies
>>
File: 1409733279617.png (15KB, 350x352px) Image search: [Google]
1409733279617.png
15KB, 350x352px
CLion vs Visual Studio vs Visual Studio Code with a debugger extension?
>>
>>62372072
>>62372089
Here's a trivial example. Do it "better". In C. (Protip: achieving exactly the same result with double the amount of code isn't "better".)

#include <stdio.h>
#include <malloc.h>

struct thing_t;

typedef void behavior(struct thing_t*);

typedef struct thing_t {
int prop1, prop2, prop3;
behavior* behavior1;
behavior* behavior2;
behavior* behavior3;
}thing;

void foo1(thing* t) {
++t->prop1;
}

void foo2(thing* t) {
++t->prop2;
}

void foo3(thing* t) {
++t->prop3;
}

thing* create_thing(behavior* b1, behavior* b2, behavior* b3) {
thing* t = malloc(sizeof(thing));
t->prop1 = 0;
t->prop2 = 0;
t->prop3 = 0;
t->behavior1 = b1;
t->behavior2 = b2;
t->behavior3 = b3;
return t;
}

int main() {
thing* things[] = {
create_thing(foo1, foo2, foo3),
create_thing(foo1, foo1, foo2),
create_thing(foo2, foo2, foo3)
};

int i;
for(i = 0; i < (sizeof(things) / sizeof(thing*)); ++i) {
things[i]->behavior1(things[i]);
things[i]->behavior2(things[i]);
things[i]->behavior3(things[i]);
}

return 0;
}
>>
how do you do personal project management?
I like the kanban board principle, I also like the bugzilla-like bug tracking but I don't need the social aspect of it.
I think I once used trac with a kanban plugin, but not sure if that's the most efficient.

Syncable native client would be even better
>>
>>62372304
I'm not trying to defend methods, I'm the one attacking them
>>
>>62372348
Can you achieve the same thing in C without embedding "methods" in the struct or not?
>>
>>62372376
What are you talking about?
>>
>>62372329
I use a self-hosted kanboard instance
>>
>>62372402
Okay, so you can't. Thanks for playing, retard.
>>
>>62372420
I literally don't fucking know what you're talking about.
Did you forget your pills? This is real life, not another video game.
>>
>>62372438
If there's never a reason to embed methods in structs, please produce the same result as the code in (>>62372304) without doing so.
>>
>>62372482
What you just wrote wasn't methods.
You wrote code similar to what methods compile down to.
>>
Effective Modern C++ is a delight to read. It's so well-written.
>>
>>62372496
>What you just wrote wasn't methods.
They're just methods without the syntax sugar. Can you provide an example of how to do it "better" in C?
>>
>>62372531
No, they're what methods compile down to.
Putting a function pointer inside a struct is not a method.
Taking a pointer to that struct type as a parameter is also not necessarily a method.
>>
>>62372542
>it's not a method because it doesn't have the syntax sugar
Okay. You are a confirmed subhuman. Case closed.
>>
>>62372561
>the syntax sugar
So methods don't really exist
I guess the case really is closed
>>
>>62372268

I'll do you better: Sublime Text 3 with GDB and Valgrind.
>>
>>62372577
>if you don't use the dot syntax it's not a method
>that is unironically his argument
The """people""" that spawned you should be arrested and forcibly sterilized.
>>
Do you people actually program or do you just bikeshed on useless shit all day?
>>
>>62371703
>just incrementing an enumerator
show code
>>
>>62372599
No, I said there are very specific things that make a method.

Merely having a field that contains a function taking a pointer to a struct of that same type is NOT a method.

For instance, what stops me from calling x.behaviour1(&y)?
Nothing does. There's nothing saying that it's a "this" pointer.
>>
>>62372614
there's an example in the screenshot I posted
This is code written by Stroustrup, btw.
>>
>>62372611

Nobody here actually programs.

But that's okay, neither does anyone in industry.
>>
>>62372622
>For instance, what stops me from calling x.behaviour1(&y)?
>Nothing does. There's nothing saying that it's a "this" pointer.
Nothing does, but the usage in the example is specifically x->behavior1(x), so your """argument""" is moot.
>>
>>62372628
If you're complaining about imposing a group structure independent of the underlying values I think you don't understand the use case for enumerators.

You're bad.
>>
>>62372599
>>62372622
So if by methods, you just meant "a field that contains a function", which I personally would never call a method, then that is absolutely a useful feature, and evidently a feature of C. But not particularly OOP.
Combined with parametric polymorphism, with quantification, this can perform (in a type safe manner) all of the things that are usually done with methods in OOP - and more.

I think this would be a more sensible add-on to C, combined with void* based generics.
>>
>>62371703
i think most people would cast in that situation. it's an introductory book, they're just being illustrative. i needed strong typing for overload resolution but still wanted bitwise operators for bit flagging functionality but didn't want to write operator overloads for every type so i came up with this gem:

template<typename T, std::enable_if_t<std::is_enum_v<T>, int> = 0>
constexpr T operator | (const T& a, const T& b) noexcept
{
using U = std::underlying_type_t<T>;
return static_cast<T>(static_cast<U>(a) | static_cast<U>(b));
}


which just enables | for any two enums of the same type, no casts needed at the call site. similar deal for other operators
>>
>>62372596
Normally I do use sublime but because just doing terminal to compile and run. Never heard the last two, but if they're good debuggers I'll take'em. Are they long to setup. Not looking to spend all day today on such stuff.
>>
>>62372666
But you can't easily do that with a different param to a method.
In some languages you can't do that with a method at all.

It is simply a function taking a pointer to that struct as a parameter.
That you have decided to store such a function in the same struct or any other struct is unimportant.

If you disagree, then methods aren't really very OOP.
You store functions as data all the time in FP.
>>
>>62372705

GDB is the standard debugger to use on *nix systems, although it works on Windows as well. It is particularly useful for kernel debugging and debugging applications that target other architectures, since it can integrate with Qemu. It is used exclusively via the command line.

Valgrind is a profiler used to detect memory leaks and other bugs, although it unfortunately does not work on Windows. It can, however, be used to profile Windows applications run on Linux through Wine.
>>
>>62372685
>So if by methods, you just meant "a field that contains a function"
No, by "method" I mean a function associated with an object that is used to modify the state of that object, which my example demonstrates. I'm still waiting for you to show me your "better" way of doing it.

>In some languages you can't do that with a method at all.
I don't see how that's relevant. You can easily reproduce my C example in (e.g.) Self and Javascript and use the familiar dot syntax, but also apply the method associated with one object on a different one.

>That you have decided to store such a function in the same struct or any other struct is unimportant.
It is important, you mental cripple, because those function pointers represent behaviors associated with particular "things".
>>
>>62372806
I do have some distros installed and then some with vmware. Usually I use Xubuntu. Will it work like IDE debuggers where I can see step by step what's going on if I need to?
>>
>>62372828
But you don't necessarily have to modify its state in your C example. That's just a specific use.
>>
Can anyone explain to me about range based for loops in c++? I didn't even know it was exist until recently and having hard time understanding the implementation
>>
>>62372880
have you ever written bash for loops, or for loops in javascript?
something like
for (var i in obj)
will iterate through the entire object obj with i pointing to each of it's members.
You can also do weird shit like for i in { 1, 2, 4, 5, 6 } to iterate through this object literal you just provided.
>>
How important are arrays really? I'm reading a book that dedicates two chapters (around 200 pages) to arrays. I have not problem reading them, but I'm curious how important it is to know the in-and-outs of them. Are they something that is so integral that it's important I know know everything?
>>
Whats the dark souls of programming languages
>>
>>62372871
>But you don't necessarily have to modify its state in your C example
Holy shit, you fucking autist. Yes, you can fetch a method from one object and use it on another one, but that makes no sense in the context of this example, because you then have one "thing" acting like a different one. Those function pointers are, logically, methods. The fact that they're just function pointers is an implementation detail.
>>
>>62372923
200 pages seems like a lot, but arrays are probably the most important data structure in computer science
>>
>>62372923
arrays mean everything in computing
the memory in your computer is simply one giant array
>>
>>62372880
It's implemented in terms of begin() and end() iterators.

>>62372923
if it's a book on c, then it is important, because c arrays are weird.
>>
>>62372865

>Will it work like IDE debuggers where I can see step by step what's going on if I need to
If you have compiled your program with debugging symbols (-g flag in GCC and Clang), you can step through lines of C code, set breakpoints, peek at arbitrary variables, call arbitrary functions, etc... You can also step instruction by instruction, peek at registers, disassemble code at random addresses, dump the contents of random addresses, and more.
>>
>>62372930
Haskell
>>
>>62372933
I don't see it that way because I see any number of ways you could be using function fields.
And multiple ways they could involve the struct without taking it as a param, let alone implicitly this.
This is just a tiny sub domain of that usage, so to me, saying "this is why you need methods" is dumb, because I would take the larger generality.
>>
>>62372950
Haskell is a meme. Forth is more like it.
>>
>>62372959
I keep giving forth a chance, but it just seems like I would have to relearn programming all over again in order to solve problems using only a stack you pop from, even assembler is easier to visualize, it's all offsets and loop labels.
>>
>>62372880
under the hood it's looking for a begin/end iterator pair for the argument, either in the form of begin() and end() member functions in the object, or template specializations for std::begin() and std::end() for the object's type. so it works for STL containers and you can make it work for your own types as well
>>
>>62372955
>I see any number of ways you could be using function fields.
We're not talking about just "function fields", you autist. We're talking about functions that are associated specifically with a particular instance of a struct. You still haven't shown me a way to achieve the same thing in C without embedding methods in the structs.
>>
>>62372905
I did for loop in bash with c-style for loops since it was easier to understand.

>>62372940
if its only a simplification of the begin() and end() iterator, will it works with non-random-access iterator?
>>
What are the best books on data structures and algorithms? My class is dry and I really want to become a wizard at algorithms but it seems I'm going to have to do it on my own. Any recommendations?
>>
>>62373001
What are you talking about?
Having functions as fields includes the specific case of methods.
>>
>>62372987
>forth is hard
Yes, and it's also very rewarding once you master it. The possibilities with immediate words are endless. The only thing that comes close is Lisp.
>>
>>62372948
Never heard of this, but I'll look into it.

Thanks.
>>
>>62373018
#include <stdio.h>
#include <malloc.h>

#define CALL_METHOD(object, method) (object)->method((object))

struct thing_t;

typedef void behavior(struct thing_t*);

typedef struct thing_t {
int prop1, prop2, prop3;
behavior* behavior1;
behavior* behavior2;
behavior* behavior3;
}thing;

void foo1(thing* t) {
++t->prop1;
}

void foo2(thing* t) {
++t->prop2;
}

void foo3(thing* t) {
++t->prop3;
}

thing* create_thing(behavior* b1, behavior* b2, behavior* b3) {
thing* t = malloc(sizeof(thing));
t->prop1 = 0;
t->prop2 = 0;
t->prop3 = 0;
t->behavior1 = b1;
t->behavior2 = b2;
t->behavior3 = b3;
return t;
}

int main() {
thing* things[] = {
create_thing(foo1, foo2, foo3),
create_thing(foo1, foo1, foo2),
create_thing(foo2, foo2, foo3)
};

int i;
for(i = 0; i < (sizeof(things) / sizeof(thing*)); ++i) {
CALL_METHOD(things[i], behavior1);
CALL_METHOD(things[i], behavior2);
CALL_METHOD(things[i], behavior3);
}

return 0;
}


Can you show me a better way to implement this example in C or not? If you can't, we've found a perfectly good use case for methods. This is not up for any kind of debate.
>>
>>62371257
No you fucking retard, those are virtual methods.
Non-virtual methods are just functions that implicitly accept a reference to an object as the first parameter, usually named this.
>>
Just wrote Rust for the first time and actually got it to compile and do something I want it to after spending months trying in an abusive relationship with Golang and its garbage language design. This feels so good. I spent hours hacking away with no idea what I'm doing fighting bizarre sounding but vaguely interpretable compiler errors, and then when everything finally compiled I added println!() to see what I would get out and it worked the first time, gave me exactly what I wanted.
No stack trace, no bad dereferences, no runtime type violations. It just fucking WORKED
>>
>>62373073
>thinks anyone cares about the implementation details of sepples
You people are vomit-inducing.
>>
>>62371189
>>62371263
Do you just never pass structs to your functions or something?
What do you use structs for then?
>>
>>62373083
Okay Steve
>>
>>62373089
Who the fuck said anything about sepples, you retard nigger?
>>
>>62373063
I'm telling you those are just functions as fields.
If they took a pointer to a pointer and an int instead, then you couldn't even call them methods as a stretch, and then you could have them work on arrays and do it that way. (And possibly have even more dynamic behaviour! if you want it).

C doesn't really have methods, you said before you were "emulating" them or something like that. What's wrong with the C code you wrote?
I'm not interested enough in the specific case of function fields that can be called methods in order to want special syntax, observation, etc of them.
>>
>>62373090
I pass structs and pointers of them to functions just like I pass any other value to a function. I don't consider that function "attached" to the struct.
If you have two parameters, which is it attached to? Whichever happens to be the first param? Obviously the method idea breaks down there.
>>
>>62373105
Because this distinction between "virtual" and "non-virtual" methods is a sepples performance thing. There's no such thing as a non-virtual method in, say, Smalltalk.
>>
working on making a windows 10 laptop secure AF against malware, RAT and ETC. Just a week ago a lost all my cryptocoins, and my operating system.
>can cryptotrading using win10 be safe?
>>
>>62373132
>If you have two parameters, which is it attached to? Whichever happens to be the first param? Obviously the method idea breaks down there.
No it doesn't. If it doesn't make sense to make something a method, obviously don't make it a method.
Say you have a function foo_do_something(Foo*, int), obviously it makes sense to attach this function to Foo.
>>
>>62373167
Why make anything a method at all?
How do I know your function shouldn't be associated with the int?
It might be more reasonable to do that.
>>
>>62373123
>I'm telling you those are just functions as fields.
That's an implementation detail. Those functions are associated with specific struct instances and called only on them, and are, therefore, methods.

>I'm not interested enough in the specific case of function fields that can be called methods
Since you are unable to provide a "better" implementation of the given example, it illustrates an entire usage class for which methods embedded in structs are perfectly adequate.
>>
>>62373176
>Function has foo in it's name
>The function works on a Foo instance, using the int as just a parameter.
Use your brain.
>>
>>62373134
C# has the same notion.
So does Java, if you consider the absence of final to simply be an implicit virtual.
Plenty of OOP languages have methods which cannot be overridden.
>>
>>62373200
It's not an implementation detail, look at your next sentence.
This is a use case of function fields.
I don't see any reason to raise up your specific use case into some special language feature which then compiles to the function field anyway.
>>
>>62373203
That's not necessarily the case.
Moreover, why not say that there is some struct consisting of a Foo AND an int and that it is a method of that?
This entire thing is ludicrous.
>>
>>62373211
>methods are a use case of function fields
Yup. You are still unable to provide a better implementation of the given example that doesn't use methods embedded in structs.

>I don't see any reason to raise up your specific use case into some special language feature
Whether or not you see a reason to provide syntax sugar for method calls is your irrelevant and subjective opinion. The bottom line is that my example is a perfectly adequate usage of methods embedded in structs.
>>
>>62373203
>>62373236
The most obvious example

int compareFoo(Foo*, Foo*);
>>
>>62373210
>Plenty of OOP languages have methods which cannot be overridden.
As I've already explained, the distinction between "virtual" and "non-virtual" is irrelevant to the core concept of methods. It's just a compiler hint.
>>
>>62373245
>better implementation of the given example
Your EXAMPLE is methods and your IMPLEMENTATION is function fields.
You literally said earlier that it's a method because of how it's used.
What the fuck are you saying? That I give some other implementation of methods and this is somehow against methods or something?

>irrelevant and subjective opinion
Not true, because methods are restricted in what they can and can't do.
You are simply saying that you can use function fields for methods.
Your example is obviously contrived, so I can't really say "here's a non-method version" like having an array of 3 ints to increment.

As far as I am concerned, you are saying that function fields are more general.
Methods specifically aren't particularly useful, certainly not in any significant way.
Methods implies more than just having function fields, and so long as you are saying "you can just use a specific case of function fields to do this" there isn't really any benefit to methods over function fields.
>>
>>62373236
>That's not necessarily the case.
if it isn't then don't make it a method, duh. This isn't exactly difficult.

>Moreover, why not say that there is some struct consisting of a Foo AND an int and that it is a method of that?
I'm not sure what you're saying.
Then you'd just do something(FooAndAnInt*), where something would be a method of FooAndAnInt

>>62373252
Attach to the first one, taking in the second as a parameter:
struct Foo {
....
int compare_to(Foo *rhs);
}

This is a common thing to do, but operator overloading is better for this situation.
>>
>>62373293
It's not irrelevant to the OOP however, which is the point of calling it a method in the first place.
Thinking that it modifies the thing it points to and is associated with that type is "just a compiler hint"

>>62373307
>This is a common thing to do...
There's absolutely no reason for that to be a method and it contradicts your own justification.
I have no problem not thinking of things as objects, and simply thinking of them as parameters and doing things with them, possibly mutable, possibly not.
>>
>>62373293
Nope, it has clear semantics. Virtual -> overridable, nonvirtual -> non-overridable. It's a portion of the class's interface and not merely an optimization.
>>
>>62373302
>Your EXAMPLE is methods
My example is of structs with associated behaviors. My implementation is basically methods without syntax sugar.

>What the fuck are you saying? That I give some other implementation of methods and this is somehow against methods or something?
Nope. I'm asking you to show me a better way to implement structs with associated behaviors in C than using methods embedded in structs.

>Your example is obviously contrived
My example is actually very typical, and your utter failure and continual tap-dancing around it are perfectly predictable and obvious. Try not to start off by making ming-bogglinly moronic claims next time, Haskell shit.
>>
>>62373347
He just goes into "whatever it compiles to" whenever it's convenient.
>>
anyone knows a good multi platform gpss implementation?
>>
>>62373354
As I literally just fucking said, 1) that is a specific use case of function fields, whether or not you want to masturbate an entire fucking programming paradigm out of it is up to you, 2) your example could instead use an array of ints choosing which to increment (since that's what you always do, your example is in fact less efficient because the compiler probably won't inline the function call), and 3) you can't just swap between "how methods are implemented" and methods whenever you please. Methods have rules that prevent certain things, and adding methods to C means changing C, it doesn't mean keeping C as-is but some people using functions in a particular manner.

You are literally obsessing over a tiny use case of functions in structs.
>>
>>62373320
>It's not irrelevant to the OOP however
You can take any C++ project and change every last method to "virtual", and unless you were doing something monumentally retarded, it will still work.

>>62373347
You're confusing C++ virtual methods with Java's final methods.
>>
>>62373419
>You can take any C++ project and change every last method to "virtual", and unless you were doing something monumentally retarded, it will still work.
#define class struct
#define private public
#define protected public

What's your point exactly?
>>
>>62373384
>that is a specific use case of function fields
Yes, a use case called "methods", and so far you have been unable to offer a better implementation of my example that doesn't use methods.

>your example could instead use an array of ints choosing which to increment
And then I could make a slightly more complicated behavior and you'll be destroyed again.

>you can't just swap between "how methods are implemented" and methods whenever you please.
Never did. You're simply a lying subhuman. Those things are methods.
>>
>>62373419
Yeah you can change all "final"s to not finals too
>>
Currently learning Haskell and learning about typeclasses (wish the book went into how to write code to solve problems, but I guess we need to walk before we go into a brisk trot )

Is there a better way of writing this?
data DayOfWeek =
Mon | Tues | Wed | Thurs | Fri | Sat | Sun deriving Show

instance Eq DayOfWeek where
( == ) Mon Mon = True
( == ) Tues Tues = True
( == ) Wed Wed = True
( == ) Thurs Thurs = True
( == ) Fri Fri = True
( == ) Sat Sat = True
( == ) Sun Sun = True


It just feels very tedious to have to write out every single case where it's true. Isn't there a way I can do a C-type enum and check them as ints? Or is that considered unsafe? (Also, I have no idea how to write the default case -- How do I write 'otherwise = false' ?)
>>
>>62373453
>What's your point exactly?
The point is that it doesn't change the semantics. It's just an optimization hack, and some languages don't even bother with it.
>>
>>62373481
It's not an optimization hack. Access specification doesn't make your code run faster or slower. It's the definition of an interface.
>>
>>62373467
>Yeah you can change all "final"s to not finals too
That's not analogous because trying to override a final method in Java will produce a compiler error, while trying to override a non-virtual method in C++ will simply produce wrong results.
>>
>>62373458
>a use case called methods
Which are unimportant.

>and then i could change the example and the implementation would no longer work
genius

And no, that isn't lying

How's this then dumbass, I just make a function with type
Foo(Foo)

This doesn't alter the state and doesn't even need to take a pointer, I simply chain these results together.

>>62373476
For the default case, simply use _ at the end
(==) _ _ = False

By the way, you can derive Eq!

deriving (Show, Eq)
There's no need to write it yourself unless it's different
>>
>>62373485
>Access specification
Virtual functions are not access specification, you retard. Holy fuck... so many lowlives in one thread.
>>
>>62373494
>that's not analagous because one fails at compile time and the other fails at runtime
???
>>
>>62373495
>methods are unimportant in an example that relies on them
>no, i can't provide a better way to do it without methods
Lowlife.

>changing the content of the behaviors slightly is "changing the example"
Only from the perspective of your moronic alternative, which immediately breaks as soon as the behaviors change, clearly demonstrating why it is not "better".

>How's this then
Provide a working example.
>>
>>62373458
>>62373495
Regardless this all goes back to what I said
If you can obviously just have function fields, why would you choose to only have methods?
You wouldn't
>>
File: 1457742786990.png (440KB, 645x1260px) Image search: [Google]
1457742786990.png
440KB, 645x1260px
>No UFCS in C++20
Why does this language choose to stay behind other languages so damn much?
>>
>>62373544
I'm not wasting my time writing it, the point is just that you take an input Foo and return an output Foo, and then either modify the variables or simply connect the inputs and outputs. Effectively emulating state.
>>
>>62373083
Good man
>>
>>62373559
If they added UCFS they'd have to admit that C++ isn't an OOP language
>>
>>62373574
what
>>
>>62373559
Didn't they already fuck it up though with the proposed syntax?
>>
>>62373503
It's not analogous because one is a part of the enforceable contract of a class, and the other is basically an optimization keyword that produces broken code with the underlying assumption is ignored.
>>
>>62373584
at that point there'd be virtually no OOP left

>>62373595
It IS enforceable contract, final and virtual both are.
>>
>>62373588
>proposed
It'll stay proposed forever
>>
>>62373545
>Regardless this all goes back to what I said
What you said was that there exist no legitimate use cases for methods. I'm still waiting for you to provide an alternative implementation of my example that doesn't use methods.
>>
>>62373595
> and the other is basically an optimization keyword that produces broken code with the underlying assumption is ignored.
>what is override
>>
>>62369794

i was told programming socks improve production, does /g/ have any evidence to help me substantiate these theories?
>>
>>62373562
>i can't actually implement it but just trust that my vague drivel works
You lose.
>>
>>62373620
What I said is that there's no reason to have methods with your structs. Obviously we disagree about what methods are. You can wait all day for me to implement what you consider methods without implementing what you consider methods.
>>
>>62373638
"lose" what you fucking moron? This is a discusison and you've chosen not to apply the tiny amount of brain power it takes to consider what I said, which I happen to know works. It's not necessary for me to waste my time explaining it to you, I don't care whether you know or not. You've lost at life.
>>
>>62373495
Thanks, anon!
>>
>>62373663
No problem.
You can also derive Enum and Bounded, since you have a simple class that resembles an enum.

You can do Ord too which will order them in the way you've declared them, e.g.

Mon | Tue | Wed

Wed > Tue
Tue > Mon
etc

Bounded gives you

minBound :: YourType
(Mon)
maxBound :: YourType
(Sun)

Enum gives you succ and pred (succ Mon = Tue, succ Tue = Wed, etc. succ Sun is an error, as is pred Mon).
With both you can do

[minBound..maxBound] :: [DayOfWeek]
[Mon, Tues, Wed ... Sun]
>>
>>62373663
>>62373699
there's also Read, which will interpret your type from a string, i.e. "Mon" -> Mon, "Tue" -> Tue, etc, else -> error

If you don't really need these classes don't feel any need to derive them

Normally you use Eq, Ord, Show.
Ord is particularly useful for sets and maps (which are ordered for searching and insertion)
Show so you can see the results
>>
>>62373604
>It IS enforceable contract, final and virtual both are.
>virtual is enforcable
>sepples fags not understanding their own meme language
#include <stdio.h>

class Foo {
public:
void method1() {
printf("method1\n");
}

virtual void method2() {
printf("method2\n");
}
};

class Bar: public Foo {
public:
void method1() {
printf("method1 - override\n");
}

void method2() {
printf("method2 - override\n");
}
};

int main() {
Foo foo;
Bar bar;
Foo* foobar = &bar;

foo.method1();
foo.method2();

bar.method1();
bar.method2();

foobar->method1();
foobar->method2();

return 0;
}

As you can see, it just silently breaks, because virtual is an optimization detail, not part of the class contract.
>>
>>62373659
>"lose" what
Your dignity. Your moronic claim has been proven thoroughly wrong and your only retort is "methods aren't methods". Sterilize yourself.
>>
>>62373713
>it just silently breaks
No, it visibly changes the behaviour
>>
>>62373713
>what is override
>>
>>62373729
>i am the standard through which all words are defined

Methods came from OOP down, they didn't come from functions up.
>>
>>62373646
>You can wait all day for me to implement what you consider methods without implementing what you consider methods.
I didn't ask for you to implement what I consider methods. I asked you to write a C program that produces the same effect (each "thing" struct has a unique set of associated behaviors) without using methods.
>>
>>62373762
Yes, and I gave you two examples of 1) taking an int array, and 2) Foo(*)(Foo)
>>
>>62373734
>visibly changes the behaviour
And by that you literally mean "produces incorrect behavior without any warning".
>>
>>62373762
>>62373776
No doubt whatever you want could be done another way, you could if you liked embed things to be done in an AST of sorts and then control precisely what can be done, not that this matter.s

>>62373780
No, because you've made a user error, and it's not a compiler error. The compiler is doing as intended.
Non-virtual methods are doubly retarded anyway.
>>
>>62373776
>taking an int array
That solution is inferior because it breaks immediately if the behaviors are changed even slightly.

>Foo(*)(Foo)
That's just vague drivel. Not a working solution. You will continue desperately trying to save face for hours but somehow you will never find the time to implement your supposed solution.
>>
>>62373800
>No doubt whatever you want could be done another way,
Okay, then show me a way that is better than using methods. Still waiting. :)
>>
>>62373800
>No, because you've made a user error, and it's not a compiler error. The compiler is doing as intended.
Yes, the compiler produces what is essentially broken code because you forgot to turn off an optimization that is on by default and then did something that violates the assumption behind this optimization. The fact that this is the "expected" behavior doesn't change anything.
>>
>>62373808
>it breaks if behaviours are changed even slightly
I was working with the example you gave me.
Now let me modify the scenario.
Instead they should take the entire list of 3 foos as a parameter. This is just a slight change to the behaviour, isn't it?
But suddenly it's no longer a method, and you need to "refactor" the whole thing to make the entire list a fucking object.

>>62373808
>>62373823
You refuse to acknowledge anything that isn't written up and stamped. You should be able to see that these concepts work, the Foo(*)(Foo) example being so analagous to void(*)(Foo*) that you can write a function that takes this as a parameter and then alters the pointer input according to it.
>>
>>62373846
Non-virtual methods are not an optimisation.
You are approaching it from COMPLETELY the wrong direction if you think that.
God knows what you're imagining for static "methods".
>>
>>62373849
>I was working with the example you gave me.
Okay, but your solution is inferior because it breaks when the behavior is changed.

>Instead they should take the entire list of 3 foos as a parameter. This is just a slight change to the behaviour, isn't it?
No idea what this incoherent drivel is supposed to mean. You can change the function signature of the behaviors and have them accept any number of other arguments. This doesn't change anything.

> You should be able to see that these concepts work
You will drivel on about how your solution "obviously" works for hours, but you will never provide a working solution. Funny how that works with double-digit IQ subhumans. :)
>>
>>62373937
>I can change the behaviour but you can't
ok

>i don't understand
ok

what about static and non-virtual methods then?
are they not methods?
>>
>>62373861
>Non-virtual methods are not an optimisation.
Then what is their purpose? We've already established that they are not a class contract, because the compiler will silently let you violate them. What's the use of having a method other than the one from the object's class get called when you use the name of said method with an object that is an instance of said class?
>>
>>62373977
The purpose is some retarded OOP shit of putting code and data together, fuck if I care about it.
>>
>>62373960
>refactoring when changing types
>refactoring when changing the body of a function
>somehow equivalent
You are subhuman. Every post of your proves it.
>>
>>62373977
>We've already established that they are not a class contract, because the compiler will silently let you violate them.

>what is override for the third time
>>
File: file.png (7KB, 314x178px) Image search: [Google]
file.png
7KB, 314x178px
well done dpt
>>
>>62374028
You didn't even reply to the bit I didn't give up on getting through to you.
>>
>>62373988
>The purpose is some retarded OOP shit of putting code and data together
Alright, you cretin, but I just gave you an example where the correct association between the code and the data breaks as a result of the assumption behind the static binding optimization being violated.
>>
>>62374034
>implying i'm wrong
>what is atomic
Anon BTFO.
>>
New thread:

>>62374078
>>62374078
>>62374078
>>
>>62374035
It's mostly one guy.
If OOP had never existed we wouldn't have to suffer this.

>>62374059
I just told you it's not an optimisation.
A non-virtual method is not determined by subclass or dynamic dispatch. What you do when you inherit and change that is you are referring to a different one that has shadowed the previous one.
>>
>>62374035
>method that common
OOP is winning?
>>
>>62374052
Are you going to provide a superior example showing how to associate struct instances with a unique set of behaviors that doesn't use methods?
>>
>>62374090
Are you saying that non-virtual methods don't exist?
>>
>>62374084
>I just told you it's not an optimisation.
Then I'm asking you again, mental cripple: what is it? What's the purpose of that behavior?
>>
>>62374117
I KEEP TELLING YOU BUT YOU NEVER LISTEN
>>
>>62374107
I'm saying that your parents need to be shot for spawning you. Non-vir
>>
>>62374035
(((struct)))
>>
>>62374130
Non-virtual methods don't involve function fields at all.
They are simply the association of a class with a function.
If non-virtual methods are really methods, then the method part is the association between the class (or subclass in the case of virtuals) and the function, in which case your example is not a method, because the function is free.
>>
>>62374128
So the purpose of non-virtual methods is to act exactly like virtual methods except for when you forget the "virtual" keyword and wrong calls are generated?
>>
>>62374151
>If non-virtual methods are really methods
Non-virtual methods are only methods when they produce identical results to virtual methods.
>>
>>62374163

virtual -> associated with class AND instance (i.e. subclass), work "on" an instance
non-virtual -> associated with class, work "on" an instance
static -> associated with class, no instance involved

as an example, a static method can be called without any instance, unlike a virtual
this is a substantial difference that can't possibly be chalked up to optimisation
>>
>>62374202
Non-virtual methods are an optimization. This is undebatable. Fuck off.
>>
>>62374243
Wrong.
Non-virtual methods cannot do polymorphism.
>>
>>62374243
You're wrong, they aren't.
This is undebatable by the way.
Oh, and if you think this is not undebatable, you're wrong, because that's undebatable too.
>>
>>62374262
"Non-virtual" methods are just methods that sometimes fail to get called, and when that happens, it's always a bug. That's it. No more, no less. Their existence is a leaky optimization.
>>
>>62374290
That's the dumbest thing I've ever fucking heard.
Try using them before you say this stupid shit.
>>
>>62374274
Take your double-digit IQ somewhere else, monkey. Your moronic claims have been repeatedly demolished and your subhuman mind just isn't capable of processing this.
>>
>>62374302
>I will keep claiming you're wrong when I clearly have no understanding of what static and non-virtual methods even do, and continue to engage in nothing but ad hominem
ok you do that
>>
>>62374297
>another sepples retard who doesn't understand how his disgusting language works
This is the only case where virtual and non-virtual methods diverge:
#include <stdio.h>

class Foo {
public:
void method1() {
printf("method1\n");
}

virtual void method2() {
printf("method2\n");
}
};

class Bar: public Foo {
public:
void method1() {
printf("method1 - override\n");
}

void method2() {
printf("method2 - override\n");
}
};

int main() {
Foo foo;
Bar bar;
Foo* foobar = &bar;

foo.method1();
foo.method2();

bar.method1();
bar.method2();

foobar->method1();
foobar->method2();

return 0;
}

Whenever this happens, it's a bug.
>>
File: 1476072654556.png (651KB, 677x601px) Image search: [Google]
1476072654556.png
651KB, 677x601px
>>62374290
>"Non-virtual" methods are just methods that sometimes fail to get called, and when that happens, it's always a bug
>Their existence is a leaky optimization
Nigga what?
>>
>>62374313
>sepples retards not understanding how sepples works
What else is new? Other than performance reasons, non-virtual methods have no right to exist. You will repeatedly fail to provide any valid use case for observable divergence between virtual and non-virtual methods.
>>
>>62374323
Jesus christ you fucking retard.

method2
is stored as a function pointer in a virtual table

method1
is just a regular free floating function that takes a Foo* parameter

and a static method is just a free function
>>
>>62374328
Provide a valid use case for observable divergence between virtual and non-virtual methods. Protip: you can't, and you probably don't even know when this divergence happens.
>>
>>62374342
class Foo {
static int method1() { return 3; }
int method2() { return 3; }
virtual int method3() { return 4; }
private:
Foo(){}
}

You cannot create an instance of Foo without fucking the type system.
You can call method1, but you can't call method2 or method3.

Foo::method1();
// 3
>>
>>62374345
Provide a valid use case for observable divergence between virtual and non-virtual methods. Protip: you can't, and you probably don't even know when this divergence happens.
>>
>>62374363
Another example

class Foo {
int method2() { return 3; }
virtual method3() { return 4; }
}

class Bar : public Foo {
virtual method3() { return 5; }
}


If you call method3, it will have different behaviour depending on which subclass, e.g. Foo will return 4 while Bar will return 5.

Method2, meanwhile, always returns 3.
What you did was name shadowing.
If you instead did

x.Foo::method2()
or whatever the fucking syntax and name was

You'd get the foo method, that was SHADOWED and not OVERRIDEN
>>
>>62374363
I'm sorry, that is not an example of a valid use case for the divergence between virtual and non-virtual methods. Try again, monkey.
>>
>>62374357
>Provide a valid use case for observable divergence between virtual and non-virtual methods
Performance. This is a perfectly valid reason.

>and you probably don't even know when this divergence happens.
Of course I do. I know my own language lmao.

And no it isn't a bug. By making a method non-virtual you are declaring that you won't treat the method as virtual.
The real bug is using a non-virtual method as if it was virtual, like the retard you are.
>>
>>62374386
>two are fucking impossible and the other is not
>two functions take Foo* as a parameter and one does not

You are out of your ass retarded
>>
>>62374385
I'm sorry, that is not an example of a valid use case for the divergence between virtual and non-virtual methods. Try again, monkey.
>>
>>62374406
YOU ARE SO STUPID YOU DON'T EVEN UNDERSTAND A PARADIGM FOR STUPID PEOPLE
>>
>>62374403
>performance is a use case for the divergence between virtual and non-virtual methods
Completely incoherent.
>>
>>62374412
So many unironic subhumans. Thank you for disproving the meme of human rights. Forced sterilization and eugenics are the only solution.
>>
>>62374418
Of course it's valid.
Performance is always a valid reason for everything.
>>
>>62374429
https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_72/rzarg/cplr139.htm
>>
>>62374429
>Forced sterilization and eugenics are the only solution.
I agree, to get rid of stupid people like you.
>>
>>62374429
https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/rzarg/cplr036.htm
>>
>>62374433
Performance is not a valid use case for the divergence between virtual and non-virtual functions. Your statement isn't just factually incorrect, it's the natural language equivalent of a type error... Your mental retardation is mind-boggling.
>>
>>62374436
>>62374460
>still can't provide a valid use case for the divergence between virtual and non-virtual methods
You will continue to fail. It can't be done. Non-virtual functions are an optimization.
>>
>>62374475
No they are not.
Static methods are associated purely with the class and not with an instance.
Non-static methods are associated with an instance.
Virtual methods are associated with the subclass, and they dispatch from the instance too.

In your example earlier, using the correct syntax you can in fact call Foo::method1 on a Bar object
>>
>>62374492
>they are not.
In that case, you should be able to explain when the divergence between virtual and non-virtual methods is desirable in and of itself (e.g. provide a non-contrived use case for it). Of course, neither you nor your mentally handicapped buddies will be able to do so.
>>
>>62374524
The divergence is that one is associated with an instance and one is not.
They are different conceptually.

Static methods, for instance, can be called without an object or instance at all.
>>
>>62374524
>>62374536
Effectively if you consider the way methods group functions inside of classes, i.e. scoping and access and such, that's it's own thing distinct from virtual inheritance and such
So you can see that someone might take that and apply it to regular functions that "have something to do with that class" but don't have anything to do with particular instances

e.g. if you have a class with an internal array of a fixed size, you can have a static method that returns that size - you shouldn't need an instance to query that
>>
>>62374536
Are you going to provide a use case for this divergence? Come on, we both know you can't. This is demonstrated by the dozens of times you have avoided this question so far.
>>
>>62374557
I (quite unfortunately) know C++ better than you ever will. Are you going to provide a use case for this divergence?
>>
>>62374561
>>62374574
I have already given you an example where one function can be called and another cannot.
>>
>>62374580
That's not a use case showing that this divergence is somehow useful or desirable. Try again, monkey.
>>
>>62374606
Yes it is, but I'm not wasting my entire time on brainlets like you.
Goodbye.
>>
>>62374606
>>62374624
oh, one last thing

I mean that it is different, I'm not saying it's useful.
After all, we both know methods are useless.
>>
>>62374634
>I'm not saying it's useful.
So you admit your inability to show how this divergence is ever useful or desirable. Thanks for playing, monkey.
>>
this is the most autistic and pointless argument I've seen on dpt
>>
having c++ issues need URGENT help sned backup on my location

even when I've cast the variable that's storing the result in as a double, fmod() keeps giving me a fucking integer. about to tear my hair out and im too autistic to figure out what exactly I need to google (i've already tried). thank
Thread posts: 365
Thread images: 20


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.