/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

pastebin.com/8wVMSGYj
twitter.com/AnonBabble

Defecating in a ceramic bowl.

Programming.

Coding.

This

Developing.

I am learning C++ but when would I ever use my classes for programming?
I mostly do alogirthms, sorting, searching but none of these involves making my own class.
I am sad.

Conceiving.

contemplating

I'm wondering if you're coming from C or assembly language. I use classes very rarely, too.

Creating.

Shitposting.

Do you use structs? Structs are classes too.

The program below shows that if you have a destructor then your should have copy constructor and copy assignment operator or else undefined behaviour is imminent.
How do I understand this. I get segmentation fault but why?

#include
class Hasptr{
public:
std::string *p;
int i;
Hasptr(const std::string& s = std::string()):
p(new std::string(s)),i(0){}
Hasptr(const Hasptr& temp);
~Hasptr();
};
Hasptr::~Hasptr(){
delete p;
}
Hasptr::Hasptr(const Hasptr& temp){
//p = new std::string(*(temp.p));
p = temp.p;
i = temp.i;
}
void function(){
Hasptr *dummy1 = new Hasptr("LA");
Hasptr dummy2(*dummy1);
std::cout

Yeah, but I primarily write in C, and C structs are not classes from C++.

Even if I have to make openGL programs I rarely use classes or struct.
Are these for large scale softwares only?
C++ is my full time. C was just begining.

>How do I understand this. I get segmentation fault but why?
because you're dereferencing a null pointer

Yeah, I get that. I started straight onto C++ as a kid and never went through the legit C stuff. Still applicable in C++.

Structs do really great work when it comes to complicated data structures (imagine doubly linked circular list or header of some file format, like .tar).

Buffer overflow x64.

Here is a nice wallpaper I made for you guys.
Modify and make a good one for me.
main(_){static long long x = 9000; putchar(x--%2?92:x%3?47:63); x>0&&main(_);}

I am making my own openGL implementation.
How can I make this public and open source?

you're making your own drivers?

...

>I am learning C++ but when would I ever use my classes for programming?
That is like asking why you would ever use a function instead of writing everything in the main loop.
>I mostly do algorithms, sorting, searching but none of these involves making my own class.
So you are a first year CS student.
There is a lot of algorithms that benefit from making classes.
Search algorithms often rely on classes.
There you often use a class that encapsulates a state.
This makes it easier to do operations on a state.

As for sorting, you might want to make a class so you can make comparisons of something different.
C++ allows you to declare what operators mean in relation of objects, eg, you can declare how to print them with a string stream, how to compare them etc.

It is also a good thing when you are making data structures.

If I have a list of int arrays, how do I go through the list and remove the first item in the current array? (C#)

No.
By implementation I mean windowing toolkit.

>How can I make this public and open source?
You make a contribution file that describe how people can contact you and how to contribute and a license file that describes what people can and cannot do with the code.

Most people just make these two files, write them in markdown and publish the code on something like gitlab or github.
You can host gitlab yourself, but unless you have a reason to do this, you might as well use a free server that can take responsibility for your data.
git is distributed anyway, so even if the servers go down, you still have everything until they went down and you can migrate to another server.

(loop for x from 9000 downto 1 do (format t "~[~[63~;47~]~;92~]" (mod x 2) (mod x 3)))

I have a csv file like

a, 21
b,20
c,19

I want to store these values in a list like
list = [a = 21, b = 20, c = 19]

and do a quicksort with it

the quicksort part is done
what I don't know how to do is how to transfer the csv values into a list and do the operations there without losing the "label"

I'm using python

Yeah. I should make a dog class.
Sort dogs according to his color,
height, name, etc.

Started learning Common Lisp a few days ago as my first language.

Mainly for jogging my brain and out of hobbyist interest. So far I can say that I should have done this a lot earlier. I haven't felt so mentally alive since years. I'm actually having fun.

Thanks Sup Forums.

DirectX naming convention
ID3D11CommandList


Is this stupid?
I find OpenGL's naming better.
glEnableVertexAttribArray(...);

Is DIrectX written by pajeets?

Does anyone know how to measure the relations of several 3d points in the real world?
I need to make a calibration, but in order to do this, I need to make a coordinate system of the object I am measuring.
I can use a ruler, but that is really inacurate, especially since I need 3 dimensions.

If I have a list of integer arrays, how do I go through that list and refer to the first element in that integer array?

Inheritance is the purest form of metaprogramming.

I am insanely fucking retarded, don't bully me. How do I check if AxA matrix (2d-array, actually) is a magic square? Of course it doesn't work, I don't actually know what I am doing.


bool ma(int** a, int row) {

int i, j,
k, sz;
int *sum = new int [row * row];

memset(sum, 0, 6);

for (i = 0, j = 0, k = row - 1; i < row; i++, j++, k--) {
sum[0] += a[i][j];
sum[1] += a[i][k];
if (sum[0] != sum[1]) return false;
}

for (i = 0, k = 2; i < row; i++, k++) {
for (j = 0; j < row; j++) {
sum[k] += a[i][j];
if (sum[k] != sum[k - 1]) return false;
}
}

for (j = 0, k = 0; j < row; j++, k++) {
for (i = 0; i < row; i++) {
sz = sizeof(sum) / sizeof(int);
sum[sz + k] += a[i][j];
if (sum[sz + k] != sum[sz + k - 1]) return false;
}
}
return true;
}

>refer to the first element in that integer array?
(car list)

I've already pointed out the issues with this one.
Fix it.

GL doesnt have to include numbers so it helped. Then again MS really could have thought a little harder and just leave out the numbers. But thats asking a lot

what language?

Or something useful, whatever.

int size;
int** list;
... // Somehow obtain your list here
for (int i = 0; i < size; ++i) {
int* first_ref = list[0]; // Pointer to first element of the array
}

Why not read some vector algebra and matrices?
I guess that would help you.

list[0]

scrap that, this is going to be insanely difficult for me

I have a csv file like

2015, 20
2016, 29
2017, 39


I want to store the last column (20, 29, 39) into a list as integers

how do I do that /dpt/

Whoops, s/list\[0\]/list\[i\]/g

dude
int* listRefs = list[i];

You want to have it generic.

I think they meant this in their question:
(mapcar 'car x)

data = []
for line in file:
v = line.split(',')
data.append(v[len(v) - 1)

How did you guys teach yourself devops?

Fixed myself

Ah yes, the beauty of Rust

1. read line
2. split on ','
3. convert to integer
4. append to list

I'm sure you can figure out how to do all 4 of these things.

nice this is exactly what I want
also no need to bully me

>My friend was saying in order to support 4k resolution your video game should be 4k.
Is this correct statement?

as much as people hate on the syntax it describes things that can't easily be described without becoming ugly. It's probly very close to the best possible syntax for a very ugly problem set.

>also no need to bully me

I wasn't bullying.

>How would you get bullied by CIA?
We are all CIA operatives.
We are monitoring your activities online.
You seem to be nice guy but careful not to use Sup Forums too much.

programming related how?
>>>/sqt/

What language has the best OOP syntax?

Common Lisp

Go

Does no OOP at all count?

smalltalk probly, I've only known the shitty OOP though.

dummy2 is constructed using data members that dummy1 "owns";
when dummy1 is deleted so is dummy2s shared data.

>. It's probly very close to the best possible syntax
Not even, its just an awkward bastard of functional and imperative

Literally none of the punctuation in that image is meaningful.

what doesn't look meaningful? It's not far from C++ syntax in that example. Again I find it really weird when people shit on Rust syntax and they haven't even gotten to the weird stuff.

Go. I hate the bullshit of nesting all functions inside of the object.

Improved:
Coords const char.write(Grid grid, Coords cursor) {
grid[cursor] = this
cursor.move_within(Movement.Right(1), grid.bounds())
}

Already a million times more readable and I barely changed anything.

C++ syntax is also awful.

I find Rust very interesting, I like watching videos on it, its just not a language id ever use.

No

Sure but that means something completely different. It's unfortunate that the situation is incredibly complex but the meaning is meaningful.

I feel you, especially on Rust stable which lacks a ton of features you'd want to use anyway. The real question is:
Is it harder to do 100% best practices or learn a new ugly guaranteed safer syntax?

If C is supposed to be small and easy to implement why hasn't nobody made language that's C with little harder to implement compiler.
You know have all the good stuff.
C ABI
better macro system
standard library that defines optional features depending on platform, for example on system that support filesystem you could use the optional standard api
type inference
namspaces that don't require name mangling

I am learning c# and i got to chapter on classes, so to practice i decided to create a simple console "fighting game". User creates Player and monsters, receives random HP and attacks the monsters

Now, i wonder how to implements "rounds" of fight, where you have 1 player and for example 3 monsters, how do you make them perform attacks in some special order (depending on their rolled initiative)? Do i put them in some data structure like Queue or Stack? After they perform attacks and no one is dead, how do i repeat the process?

Currently, this is what i have:
pastebin.com/8wVMSGYj

Codeine.

>Microsoft® Daily Programming Thread 95
why?

There are plenty of compilers with convenience extensions. The things you want can be done through those means.

Most people will sacrifice some best practices for readability as long as it doesnt cause more headaches than its its worth. Which I think is the problem with rust and its railroading with safety. But who knows, its still young and they have a very nice development system.

Hi Sup Forums
In Bourne Shell (sh), how do I match a pattern in a test, like this:
text='somejunk_foobar_otherjunk';
if [ "$text" = "*foobar*" ]; then
printf 'It matches!\n'
else
printf 'No matches.\n'
fi;

I know that this is not how to do it, so how can I do it, in sh alone? If that's not possible, then how can this be done?

Yeah readability is king. I 100% get that and that image posted with code is a really tough example. Any time you're dealing with references and casting it's going to be painful unless you turn your 1 line of function call into like 10 lines of commented code.

> how can this be done?
Perl

Perl obsoletes bash but brings about catastrophic readability and reusability problems. It will 100% work forever until something changes but nobody will be able to comprehend it.
>easier to rewrite from scratch than to decipher the original and modify it

>perl
If I had to use external programs, I'd just use grep.

Does anyone have a guide to writing memory safe c11? mostly targeting embedded systems.

Is it possible to return functions in only certain languages? What is it called, for a language to be able to have functions which returns a function?

>What is it called, for a language to be able to have functions which returns a function?
Useless.

Usually they call that something along the lines of "First Class Functions" as in they're a language-syntax supported datatype of the primary importance

you mean currying?

>people use software written in python
Why? You wouldn't drive on a bridge made of rotten wood.

How else can I download YouTube videos?

Python these days serves as a perfectly adequate glue lang to stick libs to each other. It's not significantly slow IF and only if you have compiled libraries. It's not my particular cup of tea but coming from perl I understand it.

>perfectly adequate
Just like shitting into a latrine is a perfectly adequate means of defecation, right?

No. We should demand better. We should refuse to use shitlangs.

I suppose that is the same.

I was going to ask "are there languages which take this further, returning families of functions" but then with the currying comment I realized that once you are able to return one function, you can return a "function which returns a function" etc.

I vaguely remember also when I was looking at this stuff before, getting confused on currying vs partial application, and I think it relates to this, and I remember mental-noting "this seems fundamentally important, come back to this"

But there is software that is written in python that just works. (for example )
If you want me to stop using that software, then port it to a language that you like and stop complaining.

my problem with python is that I want R to completely run the stats/visualization/computationally light sci arena, but disgusting python is so bloated its fat arms are squeezing out my sweet lovely R

Can C structures contain pointers to functions as members?
If so, can I use something like
some_struct.a_function(some_struct)

to simulate languages like C++ with OOP?

Glue doesn't really need a lot of adequecy. If it sticks tab A into slot B it's good enough, whatever the performance. I'd rather use something with some slick JIT or something but it is what it is. I hate pythonfor unrelated reasons(whitespace autism)

First Class Functions are sort of a lisp/funcprog thing, I'm not anywhere near expert at it but it's a direction to go.