/dpt/ - Daily Programming Thread - OOP EXPLAINED EDITION

What are you working on, Sup Forums?

Previous thread: [BONUS] David West explains OOP in two interviews:

youtube.com/watch?v=s-hdZZzMCac

youtube.com/watch?v=bW5K5cJ-AVs

Other urls found in this thread:

pastebin.com/kNzNeqet
worrydream.com/EarlyHistoryOfSmalltalk/
lists.squeakfoundation.org/pipermail/squeak-dev/1998-October/017019.html
blogs.msdn.microsoft.com/oldnewthing/20030910-00/?p=42583
wiki.gnome.org/HowDoI/GNotification
wiki.gnome.org/Design/OS/MessageTray/Compatibility
wiki.gnome.org/Design/OS/SystemStatus
freedesktop.org/wiki/Specifications/systemtray-spec/
twitter.com/AnonBabble

OOP is shit designed for brainlets

/thread

Building some powerful tools for online activist groups. Probably only going to give them or sell them to a few groups though.

What is the best way to learn functional programming and good procedural programming. My university only teaches OO and only c++.

good programmers will use whatever paradigm is most appropriate for the task

bad programmers is you

Transfer to a different university?

It was designed for use in coorperations because it was near impossible to organize big projects other wise. That being said if it's just you working on the program you probably don't need to use OOP but it might help with readability for 3rd parties.

>because it was near impossible to outsource big projects other wise
ftfy

>near impossible to organize big projects other wise
OOP causes big projects to become even bigger.
>readability for 3rd parties
OOP causes readability problems, it sure as fuck doesn't solve them.

I'd like to but there aren't any good schools in my area. I'm going to have to move states or move across the state to the only decent school. It's honestly really pissing me off. They insist on c++ but all the professors and TAs hate it and can't answer any questions you have. They complain about it all the time and talk about how much better Java and C sharp is.

go through this:
pastebin.com/kNzNeqet

As far as paradigms go there is nothing better than OOP

Even so why bother arguing over this issue when code gets processed in the same way anyway

>I'm going to have to move states or move across the state to the only decent school
Boo-fucking-hoo, nobody cares, grow up, moving isn't hard.

It causes readability problems and projects to become bigger when you aren't using project management correctly. I work as a project manager and we use a mix between RAD and Waterfall, this means there is plenty of documentation and communication between dev teams which means we can develop and prototype very fast and keep the program slim without project creep.

OOP only causes projects to bloat if you've got shitty project managers.

>talk about how much better Java and C sharp is
sounds like the rot is terminal

Want to know how I can tell that you don't understand OOP or any other paradigms?

>Bad OOP is bad
I've been writing code professionally since 2000 and I've come a long way since then. OOP has been around throughout the entirety of my career and I've never once seen it properly implemented.

The SOLID principles appear simple but really learning them and learning from them appears to elusive to so many.

There are examples of outstanding OOP design out there, System.DateTime comes to mine. The ratio of bad OO design to bad functional design are 1:1. There's always some dick in Marketing that has a shitty dev in pocket who will push a poorly designed change at 5pm on a Friday.

I have finished purchasing my copy of SICP so believe me when I say that functional programming is the way to go. Fuck OOP and all this MBA-driven corporate garbage.

Thank you
Okay no need to be mean. Do you really thinking transferring would be the best idea?

Or you could have used Lisp instead and not spent years trying to find the elusive "properly implemented OOP" (which, by the way, doesn't exist).

>Do you really thinking transferring would be the best idea?
I don't know. I just think that "moving is haaaard" is a piss-poor argument for not doing it. There are better arguments both for and against.

>Want to know how I can tell that you don't understand OOP or any other paradigms?
Be kind, I'm only 6 months in to learning programming

So don't post things like
>As far as paradigms go there is nothing better than OOP
Don't worry, after a few years of experience you'll be as bitter and jaded as I am.

Where do I learn good oo design then? I know c++ and java but I never got to work with a team or on anything bigger than a few dozens of kloc. OOP always felt elusive to me, I never got that "a-ha!" moment.

Do many people who are forced to use Java have drinking problems?

Sorry anons.

Still looking to see if there are any other Ardunio users here.

>It was designed for use in coorperations because it was near impossible to organize big projects other wise.
No, it was not, and that was not the reason it came about either. Try reading the actual history of OOP from it's inventor:
worrydream.com/EarlyHistoryOfSmalltalk/

Further more, what many people call "OOP" these days, bares little resemblance to the original ideas that created it, and stuff like Java/C++ don't do much to fundamentally justify their brand of OOP.
lists.squeakfoundation.org/pipermail/squeak-dev/1998-October/017019.html

And it's worth noting that OOP also came about during a time before we knew about using Functors/Monads/etc in programming, which solve all the same problems OOP was trying to tackle and more.

A lot of people (including me) feel this way about OOP. After years of programming I've come to the conclusion that dumb people are sucked into the OOP thing and it's probably for the best that you kind of know it's a meme.

That doesn't mean you need to throw out OOP languages, just use them and their abstractions where they make sense to you. It's only as bad as programming without it.

>That doesn't mean you need to throw out OOP languages
We must burn them all.

No mercy for OOP. It is completely worthless and devoid of merit. It has stunted computer science and software for decades.

ok, so who here works at NWO, or at least is a jew, and is willing to get rid of OOP?

What's the best book to learn C# if I already know C++ and Java?

For performance, use C. For theorem proving, use Agda or Coq or a similar language. For anything else, use Lisp.

>remember taking an OOP and Java class in high school
>try to remember why that was the case
>AP CompSci teaches that crap

yuck

>For performance, use C++
ftfy

Java, C#, C++, JS and Python have no academic merit and should not be taught in degree programs.

C# in a nutshell

How does one recommend agda/coq for theorem proving, yet not recommend an ML-like language for "functional programming"?

No, use C, and use as little of it as possible.

>AP CompSci
Honestly, why? If you want to go to CS math and physics will benefit you more.

No, use C++, and use as much of it as possible.

Whats wrong with c++? It's all my school teaches. See

Regarding the whole C/C++ thing for performance: there's this common lie that C++ programmers spew that exceptions don't have a penalty anymore and that standard library containers are valid for high-performance code. This is all BS.

And there's a more annoying lie that C programmers say, C++ is inherantly slower than C. This is utter BS, you can write faster code in C++ with better high-level constructs and less LOC.

OCaml, ML, and Haskell are useless for functional programming because their type systems can be subverted and/or they are impure. might as well just use lisp, its macros are easier to use than template haskell at least

>It's all my school teaches
Are there really schools that only teach one programming language?

>standard library containers are valid for high-performance code
They're better than what you could come up with.
I don't think you realize that the containers are optimized based on type traits.

>relying on what the school teaches
Learn the language of your own accord!

>NWO
Come on, you should know damn well by now that this whole theory is a joke and the people actually trying to pull the whole world's puppet strings (ie. billionaires like the Koch brothers) are working at cross purposes and have no hope of successfully controlling absolutely everything without it blowing up in their faces and turning into chaos.
But I'll go ask Bob Mercer what he thinks. BRB, performing a blood sacrifice to access his private pocket universe.

Yeah I've looked through the course catalog. One class mentions using python for scripting. There aren't any classes focused on any languages. It's c++ or the highway.

It seems almost like a dereliction of duty by the school.

The containers are one-size-fits-all, you don't have to be an expert to come up with better code (for a given situation) but you do need a grounding in algorithms, optimization, and high performance programming. I'm not saying one can easily come up with better general-purpose containers. They're good for what they do and I don't generally reinvent the wheel with them, because I don't generally need to.

remember how long it took for the stl to get a hash table?

Is it? When you learn one language (especially C++) learning others (especially from C++ to C#/Java) is easy.

And you could have learned C++ without the school too. But the job of the school is to teach you

This is a good enough example because I found myself implementing a hash table for something recently, and it performed slightly better than unordered_map. Although a bigger difference was implementing my own hash function, but it's a given you need to do this, they really are going to depend on the usage.

I wouldn't mind learning only c++ if the professors actual liked and we're knowledgeable about it. It seems like they're forced to use it by the administration for some reason.

Maybe I'm being excessively biased because of the way I was taught but I think teaching one and only one language is setting students up for failure. Imagine a school that only taught PHP. Its grads would be absolutely screwed in the job market, or if they tried to learn something like C# or Java. Knowing PHP and nothing else would probably be a hindrance rather than a help.

I'm just pointing out the school teaching one language is most of the work. Teaching others is like a bonus.

PHP is an edge case. C++ is actually a good language. They can quickly adapt.

My impression is lecturers and TAs always moan about what they have to teach. It's less encouraging with C++ though. If you stick with that school and C++ then I recommend getting a copy of 'Programming -- Principles and Practice Using C++', it's the most positive account of C++ you're going to find.

>The containers are one-size-fits-all
Prove it.
Because as I've just said, they are monomorphized and optimized based on type traits.
For example, in std::vector, if your type doesn't throw exceptions, then the implementation will use an optimized version of the method used to expand the underlying storage because it doesn't need to make sure that the state of the vector is in a consistent state if an exception is thrown during copying.

>PHP is an edge case
PHP was hugely popular and an even bigger mess about a decade ago. Perhaps in a decade we'll look back at C++ the same way.

Actually the job of the school is to produce a network and provide people with the necessary tools to be successful in their endeavors. A school just teaching one language fulfills that entirely. Making excuses as to why one doesn't also continue learning outside of school/projects just highlights why so many grads are utterly failing. Schools aren't meant to hand-hold (well obviously outside of schools for autists - actual autists not this meme shit around here "hurrdurr i get nervous around girls im an autissttttt").

Most schools don't even make the language decision arbitrarily. I've only ever seen Java, C#, C++, C, and Python as choices and each one of them are phenomenal making it really easy to learn alternatives.

>the job of the school is to produce a network
Corporate/greasy ladder bullshit. Schools are there to educate.

My school teaches Scala for first year programming courses. True cancer.

Schools should teach Agda as a first language.

Well for one thing I don't know how many institutions teach PHP solely, I feel like that was never common.

this

vector is the most solid container, obviously. See my early comment about unordered_map though. Even vector isn't always ideal though. I can think of situations where vector is the closest thing you'd need for something but falls short of a custom implementation, especially considering the requirements of vector as an implementation. For example, a situation where a lot of small arrays might be needed, something like the small string optimisation would be nice but the guarantees of vector rule this out.

The point is that the containers are solid, but you can usually do better if you're optimising for a more specific problem domain. I'm not saying throw out the standard library, just be aware of how they work, their limitations, and when it's appropriate to bother with something else (rarely, depending on line of work).

ok, so clearly you're not familiar with the reasoning behind dependent typing (i.e. """theorem proving""") either then, and are just listing it off like a meme.
Being able to somehow """subvert""" the type systems is irrelevant, because the type systems are there to help you reason about your programs, not to be some kind of chastity belt. You could just as well "subvert" java and write a bunch of native C calls, or "subvert" C by mixing it with a bunch of assembly, but why would you? Similarly, why would you complicate your program by representing everything as an ambiguous hashmap or (((list))) instead of using algebraic datatypes with class constraints that you can trust will always hold? The reason types can make certain things harder, is because not all possible representations of things are mathematically sound constructs. And just because a language provides an escape hatch where you *can* avoid specifying such mathematical reassurances, doesn't mean you *have* to use it, nor that it'd even be a good idea to use it, so the whole argument is ridiculous.

You do realize networks exist outside of corporations lmao?

I had to use them for my senior design project about a year ago, were you looking for answers to questions about them?

c++ is the greatest language of all time

go to sleep bjarne

Just people to talk with about them. I'm no student, and I have no experience with any real sort of programming.

What's worth more to an academic? A school that teaches multiple languages, or a school that teaches one language and important theory?

This is like the difference between a math teacher that shows one form of long multiplication but also teaches algebra, versus a math teacher that teaches 3 methods for multiplication.

it truly is
only comfy language

Peculiar but not that bad. On the bright side, at least your frustration with the language might encourage you to pickup others outside of class.

Oh, well we used them to control a sample collectors on small watercraft. Nothing to serious, but it was fun, what do you think about them?

This.

The two are not mutually exclusive.

Yes but the point is that "more languages" just pales in comparison to the quality of the other content.

Teach the other content through the other languages.

Yeah that would be the best of both worlds. But the whole thing was about whether it's worth leaving a school for only teaching one language, and a language that the lecturers and TAs are cynical about at best. My verdict's still the same: maybe. But it's not damning, honestly it sounds kind of typical.

How do I make an Linux systray applet?
GTK+ 3 has deprecated GtkStatusIcon and every function that works with it.
The only implementation of wxWidgets, that works properly, is built on top of GTK+.
Qt can do it, but fuck Qt.
Would be nice to write my own little systray library with blackjack and hookers, but I have no idea where to start, I've never written a program longer than 700 lines before.

Well I'm making looking to make a simple gear reader uses a single 8 digit display and several reed switches to toggle between the readings.

For my first project at least. I want to sort of get to a point I can have an entire LCD dash display that shows different readouts for a vehicle.

I'll tell you but only if you post more qts.

If you do write your own library call it the notification area.
blogs.msdn.microsoft.com/oldnewthing/20030910-00/?p=42583

The docs actually say:
>GtkStatusIcon has been deprecated in 3.14. You should consider using notifications or more modern platform-specific APIs instead. GLib provides the GNotification API which works well with GtkApplication. Also see this HowDoI.
>wiki.gnome.org/HowDoI/GNotification

Ok, but I only have non-lewd ones.

>but I only have non-lewd ones
That's okay. This is a blue board anyway.
Keep em coming, and I'll tell you.

But those are notifications. And I need a pulseaudio applet (there already is one, pa-applet, I just need to get rid of all the deprecated code). Can GNotification do that, or does it work like notify-send?

Sounds like you won't, but I'm actually pleased there's someone with my kind of autism, so here you go.

>Sounds like you won't
You got me.
I don't actually know the answer lol.

I was just posting what GNOME had to say about this. If you read the docs it's clear the notification area ('systray') has been deprecated because it's liable to be over-used. If it's actually worth of appearing then it might be a candidate for what GNOME is calling the system status area.

wiki.gnome.org/Design/OS/MessageTray/Compatibility
Here you'll see volume icon etc. are integrated into system status area, removed from notification area. They give the rationale for deprecating the notification area.

wiki.gnome.org/Design/OS/SystemStatus
This is where a volume icon would go. It's possible (for GNOME anyway) you'd want the volume stuff to work with the existing volume icon.

Too bad.

That's the problem, I'm not using GNOME, just a panel, tint2. And since tray icons seem to work everywhere, I figures there must be a standard way of telling a panel to display one.
Is this it?
freedesktop.org/wiki/Specifications/systemtray-spec/

Yeah probably, remember a lot of unix desktop stuff is broken af and inconsistant.

But the answer to "how do I do systray stuff" being "don't" is legit. It's probably the wrong choice for whatever you're doing. Maybe if you said more about what you're trying to acheive...

Why isn't this code working?
> Project Euler 125:
> The number 595 is interesting because it can be written as a sum of consecutive squares:
> 6^2 + 7^2 + 8^2 + 9^2 + 10^2 + 11^2 + 12^2 = 595
> There are exactly 11 palindromes below 1000 that can be expressed as a sum of consecutive squares, and their sum is 4164.
> Note that 0^2 + 1^2 = 1 is not included, as this problem is concerned with the squares of positive integers

package main

import ("fmt"
"time")

func isPal(n int) bool {
s := fmt.Sprintf("%v", n)
rev := ""
for _, c := range s {
rev = string(c)+rev
}
return rev == s
}

func main() {
start := time.Now()
var squares []int
for i := 1; i < 32; i++ {
squares = append(squares, i*i)
}
sum := 0
for span := 2; span < len(squares); span++ {
for j := 0; j < len(squares)-span; j++ {
n := 0
for i := j; i 1000 { break }
if isPal(n) {
fmt.Println(n, "is a palindromic sum of consecutive squares")
sum += n
}
}
span += 1
}
fmt.Println("Found sum", sum, "in", time.Since(start))
}


Output:
77 is a palindromic sum of consecutive squares
434 is a palindromic sum of consecutive squares
55 is a palindromic sum of consecutive squares
595 is a palindromic sum of consecutive squares
636 is a palindromic sum of consecutive squares
Found sum 1797 in 69.232us


I suspect something is wrong with my palindrome checking algorithm, as all the stack exchange posts I saw for reversing strings were way more complicated..

>Count the number of "xx" in the given string. We'll say that overlapping is allowed, so "xxx" contains 2 "xx".
Can someone help me out with this in C#? For some reason my brain turned off. Also this isn't homework, just part of some warmup that came with an online course. My guess is converting the input to an array but I always fuck that up somehow

Depends how you're going to do it. But what exactly is your issue? You forget how to work with strings? Can't speak for the rest of Sup Forums but I'm not going to write this for you.

At the moment mostly converting user inputted strings to arrays. I changed my mind on what I was asking halfway through the post so I get the confusion

using System;
class MainClass {
public static void Main (string[] args) {
string str = "xaxxaxxxaxaxxxxaxx";
int occurances = 0;
for (int i = 0; i < str.Length-1; i++) {
if (str[i] == 'x')
if (str[i] == str[i+1])
occurances++;
}
Console.WriteLine(occurances);
}
}

Start at char 0. Look at the next character. If they're both "x", increment your frequency.
Iterate this over to one less than the total length, since you can't look ahead on the last char.

Well I wasn't expecting anybody to actually type it out but I appreciate it, this helped a lot since my interest is in learning how to do it rather than getting the end result. Didn't even know I could use [i] without making an array

Your palindrome checker looks fine here. I suspect most of the model solutions online are specifically avoiding converting to string representation.