/dpt/ - Daily Programming Thread

Previous Thread: What are you working on, Sup Forums?

Other urls found in this thread:

youtu.be/rX0ItVEVjHc
medium.com/@cscalfani/goodbye-object-oriented-programming-a59cda4c0e53#.ij6w8e72f
github.com/FiloSottile/whosthere
news.ycombinator.com/item?id=10004678
en.wikipedia.org/wiki/List_of_algorithms
github.com/Arkq/bluez-alsa
twitter.com/NSFWRedditImage

OOP

Overly
Occurring
Paradigm
s

Reporting all Maki threads on Sup Forums

So if I want to make sure my code runs both under python 2 and python 3 should I use xrange?

I understand there's no xrange in python 3 (or rather the python 3 range works like the python 2 xrange), but if I just use "range" in my code then running it in python 2 increases memory use very significantly.

Should I make some sort of wrapper to run either xrange or range depending on sys.version_info? Or does it already exist?

this.

That's just Python list comprehensions

Inheritance and object oriented programming is a thing. I referenced their specific syntax where you make virtual (c++ language) function calls by invoking functions on a base reference type. Dynamic dispatch, inheritance being required here unless you overload '.'. (i haven't tried)

Member functions is not an OOP thing though. There's no connection other than that member functions and OOP methods which act on the objects share syntax in most languages.
Doesn't warrant response.

Inheritance isn't from OOP, inheritance is just a form of subtyping

So what's wrong with OOP?

How do I stop Pajeet?

Objects passing messages isn't the only form of thinking

Never said it was 'from' OOP. Doesn't matter because OOP requires a inheritance relationship between objects. So inheritance and OOP is a thing. Why are you being so pedantic though?

Too much to detail in a short discussion in /dpt/. Its more efficient to have a proponent say what's good about it and start the discussion from that end.

You can model Cat

I spent the last two days going though the program I implemented bit by bit and just re-implementing each major fragment in every way I could imagine and benchmarking that on some tests.

I've learned a lot and shaving off fractions of a second here and there I ended up with a ~2x speedup overall.

I don't know any programming, but I just wanted to drop in and say that this is a good picture.

It always surprises me that there are so many of these little 1% boosts that you can double performance

Thank you

I was more thinking in the context of useful programs.. Sure OOP is ok for simply modeling something.

optimization is the root of all evil

Oh. No, I can't come up with anything in that context.

Probably due to efficiency gained from not pulling in data unnecessarily into the cache. If some of those small boosts make them waste less cache space that can be pretty huge.

Good programmers worry about data structures and their relationships, and that's exactly what OOP focuses on.

That's just subtyping, it's not particularly OOP
Row polymorphism and existential types are other forms of subtyping*, usually not present or not recognised by OOP.

*some people will disagree violently

That's not OOP

Write it in C and transpile to Python

OOP focuses on abstraction over data. Code over data especially.
youtu.be/rX0ItVEVjHc
Here's a talk by someone who makes games go fast because he thinks about the data.

Try programming OOP with the restrictions he lays out early in the video.

>x oriented y
This is literally the new meme.
I've seen so many examples.

What's a good resource for learning Emacs Lisp? I'm tired of having to google for solutions to make these shitty plugins work, I just want to fix them myself or write my own.

>inb4 read the manual

medium.com/@cscalfani/goodbye-object-oriented-programming-a59cda4c0e53#.ij6w8e72f

In short:
Modules > classes
Functions > methods
Interfaces > superclasses
Generics > virtuals

Its a common way of expressing programming principles. Each has to be judged on their own merits. But I agree that applying almost any principle to every situation can be harmful. He's speaking in the context of applications that have to run well in low resource environments. Like phones, consoles, home PC's etc.

first class type classes > type classes > modules > classes
monads > functions > methods
type families > type classes > interfaces > superclasses
existentials > generics > virtuals

Yeah but the stuff I said can actually exist. Nobody knows how to implement a monad in real life.

well you can implement it one of two ways

1) a type class / an interface
2) an effect system

you need functions with the following signatures

a -> m a
(a -> b) -> (m a -> m b)
m (m a) -> m a OR (a -> m b) -> (m a -> m b)

How would you guys go about implementing an SSH client?
Just to send some text-based commands and retrieve responses

Believe it or fucking not, there is no good library for it in Java

LOL

>yfw the overwhelming majority of meaningful contributions to software AND hardware where by academics

>yfw modern software developers LITERALLY live in a fairy aether powered by the fevered dreams of CS PhDs

Academics haven't contributed a single thing to hardware OR software that survived to the present day. It's always been engineers working within the demanding environment of industry who got things done.

Shame so much had to be fixed and practically all significant contributions are being replaced for one reason or another.

Making a poor solution early doesn't make you better.

golang has good libs for this, apparently. there are some custom programs made in go:
github.com/FiloSottile/whosthere
there are more examples here IIRC
news.ycombinator.com/item?id=10004678

>>yfw the overwhelming majority of meaningful contributions to software AND hardware where by academics
hahaha, wtf

this. and phycisists, and sometimes econ people. but mostly EEs

>Aristotle
>Archimedes
...
>Newton
>Descartes
...
>Church
>Turing
>Ritchie
>McCarthy
...

>endless shelves upon shelves of papers on data structures, algorithms, processor systems, parallelisation strategies, etc, etc, etc, etc, etc

You don't understand. He uses Python, a language untouched by the last 30 years of research.

like how people think academics don't run programming

microsoft research Cambridge dudes literally put generics in C# and then later linq

>virtually all cryptography
>everything dijkstra ever did
>99% of en.wikipedia.org/wiki/List_of_algorithms

Literally everything.
Academics.

Guyses how do I make a client server program in C over IPv6?

what kinda question is that
just learn into sockets fagit

>Python
As if. I use C, because I've got a pair.

>fevered PhD students
Also those more recent ones are infact being replaced where people care. Not for poor effort honestly. But there's so incredibly much junk that you CS retards throw at software in a non productive way. FP being one of those things. Certainly one of the smallest problems. But memory being cheap is simply a lie. Storage is cheap. Active memory isn't. If you have a problem that suits those constraints that's fine. But you generally don't.
>parallelisation strategies
Which solve nothing because they're effectively pseudo code software written for the software aether. Try implementing that stuff and then realise how a naive strategy which just considers the situation you're in solves the problem much better. Even if I think you're being retarded I have enough faith in you to beat that trivial standard.
>data structures, algorithms
Most of which prove to be entirely useless for anything but the most trivial cases. Go down a list of the most popular algorithms and datastructures and you find that aside from a few like a hashmap they're largely useless. And in the case of things similar to a hashmap they offer convenience aside from predictability (which can be very useful in real time platforms, super specific)
>processor systems
Don't know enough about that to comment. But with how much happens in CPU tech (if that's relevant), I kinda doubt the source is academia rather than engineers themselves.

>I got a pair
I hope you're being sexist because there's no bragging about using C. That's all we got because you infiltrated the language development field and took over.
Disgusting user. I thought they had you expelled for saying this kind of crap at university.

I hate to break it to you, but

1) Academic doesn't mean FP.
2) FP doesn't mean careless about memory.
3) Data structures are not useless.
4) Algorithms are not useless.
5) Virtually everyone you call an "engineer" has a masters.
6) There are endless other examples. You couldn't begin to read every paper that has contributed significantly to programming.
7) >parallelisation strategies >aether; SIMD, AVX?

And every comment you've made has no doubt been made by someone else about something you consider important.

I read your post four times and there wasn't a single coherent thought I could get out of it. Maybe you should write your posts in English on an English-language imageboard.

Sure is Blub paradox in here

C was invented by a man far more intelligent than you, it wasn't a trivial invention and the developments since then weren't trivial either

You're standing on the shoulders of giants, mocking them

If I had a nickel for every time someone said that a specific set of features didn't constitute OOP, I'd have quite a collection of nickels.

and then they invented Go

OOP doesn't actually exist.

OOP is a chimera and a frankenstein of features stolen from everything

The only thing unique to OOP is "design everything as objects passing messages"

Which was a colossal mistake.

for what pvrpose?

It's a language specifically designed for writing servers in large teams and code bases and is great for that.

>attributes SIMD to academia
>engineers have PhDs
So? They do engineering. They apply engineering. Everyone I know regret taking a degree to some degree. With good reason. Better ways to learn, better things to learn. You get to know the wrong people. Tends to be the common complaints.
>FP is not academia
No FP is not all of academia. Its a fine example of academic ideas though.
>datastructures and algorithms are not useless
Perhaps this wasn't communicated well... They don't solve problems well at all. They're obviously not 'useless' since you can apply them. They reach a goal eventually. But that doesn't make them good. And that was my complaint.
>FP doesn't mean careless about memory
That's not my experience with functional programming languages, functional programmers and 'memory is cheap' is certainly something I hear mentioned a lot.
Makes it hard to believe these people touch computers in the real world >> I conclude they're probably academics
>many examples
Yes and we can't go through them all. But I've written software for a long time now and aside from how impressive compiler optimization can be there's very little I can feasibly attribute academia in my day to day life. Pure math people, they're a group of people I thank a lot. But CS PhD's. Not so much.
I did write English. Perhaps elaborate on what you didn't understand? This just looks like a petty insult from the point of view of someone who knows what he said.
Likely. But that doesn't make them right. And it doesn't make you less wrong.
I'm not mocking C at all. It was appropriate for its time. But that's a great example of a poor engineering job. We need something better now and it's not like they couldn't have thought of it. Perhaps it was never intended to last. I can forgive that.

Does anyone know if there's a way with classic higher order functions to just sum a list from left to right until I hit a limit?

For example, lets say I have the list (1, 2, 3, 4, 5) and I want to sum until the sum is greater than five, it should return 1 + 2 + 3 = 6. It doesn't have to be a list, could be a stream or any other traversable collection.

I couldn't think of any reasonable way with map/reduce/filter and such. I'm just wondering what the best functional way to do it is, since the imperative way is both very simple and very efficient.

>it was appropriate for its time
Well. I take back this immediately. I don't know if it was. But that's the excuse I can give it.

>trivial problem
>has to ask /dpt/
Here's your answer: They have no answers that are better than simply writing a trivial implementation yourself.

My current obsession is to get bluetooth headset working without pulseaudio and of course with the bluez5. Since such a feature has been dropped from the current bluez I'm making a rebirth of this functionality as a standalone application. Here is the code: github.com/Arkq/bluez-alsa

What do you think about this? Any suggestions, notes? Is it worth spending some more time on it?

I'm just spreading a word, maybe someone will find it useful.

>>engineers have PhDs
>So? They do engineering.
no reply needed

>attributes SIMD to academia
>Single instruction, multiple data (SIMD), is a class of parallel computers in Flynn's taxonomy
I guarantee that the overwhelming majority of developments made by engineers are the product of some form of research, or of spontaneous ideas by people who've been well educated

>That's not my experience with functional programming languages, functional programmers and 'memory is cheap' is certainly something I hear mentioned a lot.
>Makes it hard to believe these people touch computers in the real world >> I conclude they're probably academics
Have you considered that _maybe_ they aren't doing the same tasks as you? Maybe the things you do aren't the entirety of the real world"?
Also you're saying you don't like academics because if you see something you don't like you blame academics

>it was appropriate for its time
>poor engineering job
pick one

I'd welcome Bluetooth sans Poetteringware.

I don't think you read my question. I can trivially implement a solution with imperative constructs, or an equivalent recursively defined function.

My question is: am I simply overlooking an abstraction for this? Why is something like reduceUntilCondition not a commonly used higher order function?

Oh, and there's no reason you couldn't construct a functional language that strongly restricts memory usage, boxing (if it has any), etc.

There are millions of optimisations and methods employed by engineers that have their bases in academics.

Because it's just not that commonly needed? It's not rocket science user

last . takeWhile (

This is what I was looking for.
Don't accept leaky abstraction.

be careful if you're not using a lazy language

I wrote some AIs for turn-based games before but never one for a game with double blind simultaneous resolution. How do you even approach something like that?

strictfags BTFO

because in haskell, because it's lazy

>last will forcibly evaluate an entire list to evaluate in order to get the last element
>takeWhile will only evaluate elements up until it gets a False
>scanl will lazily evaluate over an entire list producing a new list

hence you end up with:
takeWhile will call scanl to get a new element from the (potentially infinite) list, "last" will evaluate it until it terminates (when takeWhile gets a False)

so obviously it won't work with infinite lists in a strict language, but the issue is that in a strict language it's inefficient if it's not recognised and optimised

"""infinite"""

basically in a strict language, scanl will go over the entire list

obviously limited by memory, storage and registers

obviously limited by memory, storage and registers is what I was going to say but then I realised you could be operating on infinite input, e.g. reading data from the environment & producing an output continually

lewk

Hva er det? Kan du gi meg en forklaring?

yes, poo in the loo.

xD

Jeg har allerede gjort det i dag. Nå foler jeg meg tom.

So what's the best way to find all the position of all occurrences of a string in a longer text in Python?

mystring_pos = [match.start() for match in re.finditer(mystring, mytext)]

This seems to work quite well, but is there a better approach?

Use norsk# instead of Python.

Never heard of it.

And I'm working on an existing code base.

It's really easy to port programs to it, and it runs on .NET so it has great performance.

Das ist ein RGB-LED-Streifen, welchen ich über ein Arduino nano ansteure.
Da der mehr als 5V benötigt nutze ich ein motor controller der für 12v funktioniert und ich so auch den µC versorgen kann damit

OOP IN LOO

xDDDDDDDDDDDD

kys

>it runs on .NET so it has great performance

There's re.findall()

That returns matches, not their positions so I would just get a list of my string repeated several times.

How do I diff a changed file in the staging area on my local master branch against the same file on the remote origin/master branch?

Vilket språk är bäst för att programmera Rpi med? Jag har köpt en touchscreen och vill göra en interaktiv 'app' där man kan lägga upp 'jobb' som sedan kan checkas av när de är klara.
Tänker mig att jag lär behöva 5+, så de skulle nog behöva en slags server som tar emot 'jobb' och skickar ut dem till alla enheter.

Skall jag skriva programmen i C eller Python? Vilket lämpar sig bäst tror ni?

Just make it a set() afterwards to remove dupes :P

Never mind, I got it it's git diff --staged filename