/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

web.eecs.utk.edu/~huangj/CS302S04/notes/oo-intro.html
godbolt.org/g/V8j4x4
youtube.com/watch?v=s-hdZZzMCac
en.wikipedia.org/wiki/Constructionism_(learning_theory)#Computer_programming_languages
youtu.be/s-hdZZzMCac?t=558
cl.cam.ac.uk/projects/raspberrypi/tutorials/os/index.html
jsandler18.github.io/
web.stanford.edu/class/cs140e/
staff.um.edu.mt/jskl1/talk.html
twitter.com/NSFWRedditVideo

Threadly reminder to use `#![feature(nll)]`.

I disagree and I still defend my point that it came from industry R&D, emphasis mine:

>He had a vision of a personal computer that would provide graphics-oriented applications and he felt that a language like SIMULA would provide a good way for non-specialists to create these applications. *HE SOLD HIS VISION TO XEROX PARC* and in the early 1970s, a team headed by Alan Kay at Xerox Parc created the first personal computer called the Dynabook. Smalltalk was the object-oriented language developed for programming the Dynabook.

web.eecs.utk.edu/~huangj/CS302S04/notes/oo-intro.html

If I have a value in 0.5-3.0 range, how would I map the value to its inverse value? So that 0.5 would correspond to 3.0 and 3.0 to 0.5.

Lisp is the most powerful programming language.

Powerful as in kW*h wasted on useless dynamic checks? Sure, but I'm pretty sure overall JS is more powerful.

>it came from industry R&D
The conception of OOP that came from industry R&D, represented by Smalltalk and Self, is dead. What survives today is Simula derivatives like Java, shilled heavily by academics.

I think you got it backwards.

>industry shilled Smalltalk and Self
>academia shilled Simula
MAXIMUM BRAINLET

Or you could just use one of the other C books, preferably a """""""""modern""""""""" one. K&R is not the only source, maybe you just need to hear/read a different explanation. It's happened to me when i starting learning FP.

FP will never survive outside of academia.

>quotes that people frequently misinterpret
I just want to smack people in the face with the pages where they source their beloved 'premature optimization' quote.

nvm figured it out

You are simply subhuman. Please tell me all about how Xerox PARC was an academic institution, rather than industry R&D. Then you can tell me all about how academics prefer to deal with dynamic and message passing rather than statically typed taxonomies, and how painful it was for them to accept Java and start shilling for it heavily. Then you can tell me all about how we're actually using Smalltalk/Self derivatives. And then you can get sterilized, because you shouldn't reproduce.

Haskell is already really popular in niche sectors, and for some reason, Ausland. Clojure is as well.
Weblets attempt to write functional JS. Or use type-safe functional alts. And pattern matching and other popular functional tools are making their way into imperative langs. The future is functional and purity, better get used to it brainlet.

need to do some low level hacky shit in C#; is there a way to do something like this at build time:
#IF X64
using PointerType = uint64;
#ELSE
using PointerType = uint32;
#ENDIF

class Stuff
{
PointerType ptr;
};

might just drop out of uni desu

trying to do anything on my own exposes how much of a brainlet I am. Getting good grades is irrelevant because I will clearly never be 4000 IQ so I might as well drop out and seppuku because the alternative is being a web dev or
>software engineer who can't program
like the rest of the """drones""" I thought I was better than for 1 and a half years

at least you'd get money for it

>What are you working on, Sup Forums?
Programming practice, that's what.
>C: shitty text-only "game" with a Zelda-ish theme
>Python: sports standings display program; gets data from a data source that lets you get previous seasons for free, and current season if your use is non-commercial
>with news that Windows Polaris will ditch much of win32, wanna get into (React)OS dev/WINE dev to preserve the ability to play muh olde win32 gaymes

Anyone here knows OpenCL? I have a C++ program that I want to run in my CPU and GPU at the same time, can I just use OpenCL to concurrently execute the for loop that is in use 99% of the time? It's just number crunching with some random number generation, so it's just pretty much C code anyway, I can just use it as the OpenCL kernel right?

That's exactly how you do it.

using System;

#if X64
using PointerType = System.UInt64;
#else
using PointerType = System.UInt32;
#endif

class Stuff
{
PointerType ptr;
};

I've heard that if you start programming in rust that your penis starts to shrink. Is this true?

>Because you edited the code to remove all the side effects for elision to be possible?
The conditions for this are not difficult to achieve.
If the destructor does nothing given that the object is moved-from, nothing needs to be done. This is the case for nearly every object that has a move constructor and a destructor

That said, I have had too much faith in the compiler and it seems what I have said isn't completely borne out in practical examples.
godbolt.org/g/V8j4x4
For whatever reason it appears not to be able to infer that it's unnecessary to test foo's data pointer.

Also there's platform dependant type called UIntPtr which you probably should just use instead.

>b-but muh Xerox
Sure it was created inside Xerox, but it was still made by academics. Its original intent was even just to be a learning language. You should stop talking about stuff you know nothing about, you are embarrassing yourself.

>how painful it was for them to accept Java
Because Xerox fucked up the Smalltalk licensing, so it was all their own fault. The reason Java was created was because they refused to license Smalltalk to Sun under the terms Sun wanted, so they went and commissioned Java.

Listen to David West talk about the history of it, you brainlet: youtube.com/watch?v=s-hdZZzMCac

The vast majority of CS majors can't program. They either cheat or rely on high exam scores instead of interesting projects.

>i-i-it was created by industry researchers seeking to address industry needs
>b-but the researchers actually had formal education, s-s-so it was an academic project
The level you'd stoop to is just incredible.

>Its original intent was even just to be a learning language
Now this is just a blatant lie, and if pressed to back it up, I'm sure the most you'll come up with is "b-b-but they also thought it had potential for educational purposes, so it's actually primarily that".

money is fucking shit

>ignoring the video
Are you serious dude? He's literally giving you the view of the creator of the language.

Nothing about the video backs up your retarded views. Maybe you should watch it yourself.

>seeking to address industry needs
I don't know why you keep pushing this lie. It wasn't, it was literally just a research project that ended up becoming successful and was sought by the industry, but then Xerox fucked up the licensing and Sun commissioned Java.
See the difference here? Smalltalk, an academic project that the industry liked; Java, a project that was right off the bat commissioned by the industry.

>b-but the researchers actually had formal education, s-s-so it was an academic project
en.wikipedia.org/wiki/Constructionism_(learning_theory)#Computer_programming_languages
Do you know what "constructionist learning" is? Do you think it's a very industrial term?

>Now this is just a blatant lie
Fuck off. At this point you're either just plain ignorant or outright trying to deceive. Either way, I'm not interested in talking with you anymore, so I'll just ignore you from now on.

Literally just the first 10 minutes are enough to blow you out of the fucking water really.

sometimes you just need to quit responding lads. No one will care whos right.

>No one will care whos right.
I'm not either of them but this is just stupid.
There's value in discussion. Though the quality of participants matter and they're probably just bigots.

You can keep screeching your (probably intentional) misinterpretations, and I'll just keep calling bullshit, but the objective and undeniable fact remains that industry R&D researchers came up with actual, useful non-Simula variants of OOP, while academics are still shilling for Java and other statically typed cruft because it plays much more nicely with their theoretical conceptions.

youtu.be/s-hdZZzMCac?t=558
This guy is so full of shit.
How would that make any sense? How do you enforce discipline through no restrictive mechanisms?
I mean sure you could assume Bjarne is just bad at fulfilling his goals. I'm sure he is in fact. But not this bad or unrealistic about the consequences of what he has done.

You lost all credibility when you lied and got exposed, troll. Get the fuck out.

>if a keep screeching it, that makes it more true
What did I lie about, fucktard? Were Smalltalk/Self developed by academic institutions? Which release of Smalltalk was intended primarily for teaching purposes?

is there any way to change the referenced object in seppels?
for example:
class Foo{
Bar & bar;
public:
Foo(Bar & x) : bar{x} {}
void swap_bar(Bar & y); //function in question
};

int main(){
Bar a, b;
Foo foo(a); //set the "bar" in foo to reference a
foo.swap_bar(b); //swap the "bar" in foo to reference b
return 0;
}

Is there any way to implement the void Foo::swap_bar(Bar &y) or that is only possible with pointer??

Use pointers, or the meme that is std::reference_wrapper.

Use pointers. Sepples references are a mistake.

Just use a pointer.

No

If I were a sepples programmer I'd tell you to use std::unique_ptr.
I think.

>teachers should teach smalltalk!
>not teaching what is used most in the industry


there goes your argument

Nope. If class Foo is not responsible for the lifetime of Bar, a simple pointer is all you need.

I wasn't sure of the goal here.
If I were a sepples programmer isn't weak_ptr what I want then?
I just feel weird thinking a sepples programmer would be so cruel as to put innocent raw pointers into classes.

I don't know where you've been getting sepples advice from. Raw pointers should be the default for any non-owning pointer.

create 2 arrays
normal _array: values 0.5 - 3.0
inverse array: values 3.0 - 0.5
once you get a value, exemple 1.1. get 1.1 position on normal array, then look for the value on the same position on inverse array

What's the point of weak_ptr then?

So you mean you can't explain what I "lied" about? Is it because Smalltalk/Self weren't developed by and for an academic institution? Or is it because you can't find the release of Smalltalk that was intended primarily for teaching purposes? What about BORM and all the other 90s memes with derivatives that corporate managers still swear by? Where did that originate? Was in academia, by any chance? Say, do all these fancy chart-based methods play nicely with prototype inheritance, dynamic typing, dynamic redefinition of classes and other stuff prominently featured by Smalltalk/Self? What's the academic theory behind that? You "people" are blatantly fucking retarded.

const was mistake
references were mistake
green threads were mistake

Look up "ownership semantics"

It prevents dangling pointers.

To break cycles in a shared_ptr graph. It participates in ownership.

ESL are the biggest mistakes.

A regex like this

[^abc]+

matches f, o, lz in afbolza

How can i do that for strings?

Something like [^poop pee]

blablapoophahapee

should match blabla, haha

so basically [abc] but for strings, not just single characters

have a pussy pic in return

These days universities mass produce graduates like. You are just a product of a (((system))) too dumb to do anything but most menial jobs. You had a chance too study hard and be good instead you just followed guidelines and took it easy, you found your place in society dont be so upset

Any good papers to read? Not much going on at work today

Threadly reminder that the entire body of "theory" on how to design "object oriented" systems originates with industry. Had it been academic work, it would've been written with highly dynamic programming environments in mind, like Smalltalk, the true academic's choice, so it's clearly he product of industry. Academics HATE Java.

>Academics HATE Java.
Is there any uni that uses Java past the first year introduction courses?

You match a character set with negative lookahead maybe.
.+(?!poop)(?!pee)
I believe. Untested. Not a regex expert or anything of that sort.

>Is there any uni that uses Java past the first year introduction courses?
Of course not. Academics HATE Java. Didn't you read my post? If it looks like academics love Java, it's just because industry is FORCING them to teach Java to their students and to base all of their work on software """design""" on Java-like OOP.

>hate Java
Awful. They cucks us with our wives (management) and leave us with a paradigm, OOP. And now they're taking no responsibility and have conceived functional programming. When that one is in the crib they will just move on.

This needs to stop.

what

>computer science academics and software "engineering" academics from the 90s are the same bunch
Amazing argument, user.

int *ptr(int &&x)
{
return &x;
}

void foo()
{
&0; // fails to compile
ptr(0); // works fine
}
god sepples is retarded

How do I keep the aspect ratio of generated ASCII? All pics seem kind of widened along the Y axis, even though it's the correct number characters for width and height.

What's the cause of this?

>address of r-value
>address of lvalue
These are different.
I do understand your complaint though. It's something you'll never find addressed in sepples. Sorry.

Your font you fucking moron.

Make the spacing between horizontal"pixels" the same as the veritcal ones.

scale the image beforehand

use a font that's the same width and height?

I'm considering just putting this trash behind me and using plain C but there's a few features I'd like to use like constexpr and templates.

that will consume the entire string and then at the end looks if the lookahead isn't there which it of course isn't since it's an end of the string

Space character kind of fixes it, but makes the picture much bigger if I use 8x8 blocks.
Like monospace? Doesn't chrome use it when you open a text doc with it? Isn't it fixed-width font?

std::vector return_vector(void)
{
std::vector tmp {1,2,3,4,5};
return tmp;
}

std::vector &&rval_ref = return_vector();


I really don't get how C++ move stuff works behind the scenes. In this example, tmp is allocated on the stack. rval_ref supposedly steals tmp without doing any copies. But, as soon as return_vector() returns, wouldn't everything in its stack frame be invalid? I mean, as soon as you make another allocation to the stack that memory is going to be potentially overwritten.

I really doubt the runtime is doing any kind of fragmented stack magic which wouldn't even make sense. Does the compiler like, read ahead and see you're doing a move and allocate tmp on the calling function's stack frame? That seems like it'd be error prone if you start getting fancy with pointers and stuff.

>framebuffer
check
>pixel drawing
check
>colors
check
>line drawing
check

next up: font

First of all, are you happy with why this code isn't doing anything dangerous?
std::vector return_vector(void)
{
std::vector tmp {1,2,3,4,5};
return tmp;
}

std::vector vec = return_vector();

how close are you to making a gf? 0-100%

depends on the size of you're cock

>takes image data that assumes square pixels
>renders it using rectangular blocks that are taller than they're wide
>why does my picture look stretched vertically?

whatcha making, user?

p.s. nice headphones

>>renders it using rectangular blocks that are taller than they're wide
No, I use squares. Anyway, the problem was the lack of space char after each character, because I googled and it doesn't seem that fonts with equal dimensions even exist.

OS development on a raspi.
Did this a few months ago while following step by step:
cl.cam.ac.uk/projects/raspberrypi/tutorials/os/index.html
arm asm is shit and now trying to convert everything to C. When I get stuck i try to get help here:
jsandler18.github.io/

Are you going to share the code in the end user?
My raspberry pi will arrive in 2 weeks and doing this kind of thing will be a fun project

? In that case it copies tmp to a temporary variable then uses the temporary object to copy construct vec, so you're doing two copies. Is move still creating a temporary object? I was under the impression that it was supposed to eliminate all copying.

I saw this practice problem for printing out a staircase, where input n is the size, so like:
#
##
###
####
My implementation has O(n^2) runtime. Is it possible to make it O(n)?

My thing is running on a raspi1 only atm. The so called "mailbox" and therefore the framebuffer works different on the raspi 2 and above.
You could refer to those links: Also osdev wiki has a barebone C kernel and stanford even has a rust course now for the raspi3
web.stanford.edu/class/cs140e/

Oh, well, I guess it does still make a temporary object like normal and you're moving that. Book I was reading was poorly worded.

>need to do a thing in Qt that involves making a diagram drawer
>"ugh this is going to suck"
>find out that Qt's Graphics View framework exists
>it handles the boilerplate for me, and even provides an example project that's basically what i want to write
>and with great docs

my love for Qt increases each day.
now just a week of hating Qt while i figure everything out (periodically getting stuck on random bullshit) and then we'll be back to 100% love again.

there are n(n+1)/2 # characters and n(n-1)/2 spaces

I'm just checking how happy you are with how function return values work with respect to copying.
> In that case it copies tmp to a temporary variable then uses the temporary object to copy construct vec, so you're doing two copies.
This is correct, which is what I was making sure of.

Consider this example.
std::vector return_vector(void)
{
std::vector tmp {1,2,3,4,5};
return tmp;
}

return_vector();
The temporary return value is initialized by calling the copy constructor std::vector::vector(std::vector const&). This is wasteful, because it will be allocating extra memory with new.

Leveraging move semantics would look more like this.
std::vector return_vector(void)
{
std::vector tmp {1,2,3,4,5};
return std::move(tmp);
}

return_vector();
The temporary is initialized with the move constructor std::vector::vector(std::vector&&). std::move allows a && reference to bind to tmp, and && takes precedence over const& for overloading.
The move constructor acts on the assumption that it can invalidate the argument, so the existing buffer allocated with new can be owned by the return value temporary instead.

You could also do this:
std::vector return_vector(void)
{
return std::vector{1, 2, 3, 4, 5};
}

return_vector();
The result of calling the constructor directly like that is a temporary object, which will bind to a && reference without needing std::move. Because we can't refer to this object anywhere else, it's cool if we invalidate it.

>No, I use squares.
Public education in action. I can't fathom how someone can be this stupid... and 5 minutes from now he'll be arguing with someone about the merits of programming languages.

>she doesn't use squares
are you some kind of rectanglefag

I'm working on shitposts instead of doing work I should. Admit it, so are you.

>What survives today is Simula derivatives like Java
Simula OOP is based on own variables and coroutines. C++ and Java are not block structured like Algol. In block structured languages like Algol and PL/I, static/own variables stay alive after the program ends, until its environment is destroyed. When the program is restarted, these variables keep their values. Automatic/local variables are destroyed when a procedure returns and reinitialized on reentry. They can have multiple copies on the stack. This is where "reentrant code" comes from. This was the behavior expected by the creators of Simula when they invented classes and OOP. Old school CS taught that Algol blocks are responsible for OOP and closures, but I didn't understand how until I learned how static/own variables are supposed to work.

>A quasiparallel system (QPS) in Simula is basically a block (typically but not necessarily a prefixed one), whose body creates some objects that together with the main block made up the system of quasiparallel coroutines. Because Simula (unlike for example Pascal) is a true block oriented language, block (that generally means a QPS) can occur at any place in the code as a statement. It means, that a QPS can contain local (nested) QPS's, that can also contain local QPS's, etc. This simple rule gives a way to create incredibly complex structures with consequences, that so far have not been fully utilized and not even understood. The next program outlines a possible use of a nested QPS in the chess control. Next chapter shows a simulation program with nested simulation.
staff.um.edu.mt/jskl1/talk.html

>Java
>plays much more nicely with their theoretical conceptions.
Java is responsible for destroying theory and setting back statically typed OOP by 30 years. Java lowered the reputation of OOP among academics and industry too. Compare it to Eiffel.

>shitty shitty shitty
the virgin non-native vs the chad Ænglisc speaker

Who dis semen demon

Do you know what a fucking square is? I mean, even if you're visually-impaired and can't tell a square apart from a rectangle by looking, it's obvious what his problem is, but those characters are very distinctly rectangular.

So every rectangular is a square? Are you legally a tard?