/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

gitlab.com/BobBarker/hoverbob
youtube.com/watch?v=1i4-e1okZtw
youtube.com/user/CppCon/videos?view=0&flow=grid&sort=p
matt.might.net/papers/might2010mcfa.pdf
twitter.com/SFWRedditGifs

Just finished my C assignment and moving onto microprocessor stuff
enjoying it a lot

whats something challenging you should be able to program before you can even think of calling yourself a programmer

>inb4 fizzbuzz

Daily reminder that D was made by a gypsy romanian, therfore it's shit by definition

Yoz have to kode with Karlie

people don't use sepples when a GC is acceptable, so a sepples replacement with a GC is as terrible an idea as sepples was in the first place

An optimizing compiler for your own high-level programming language.

@62363687
>falseflagging this much
I see you're getting creative with shilling, Andrei.

How do you design a database schema?

With pencil and paper

a series of wooden blocks and straws

put everything into 1 table like a pajeet
extra points for redundant columns

Learning C++
Confused with opOverloading
#include
using namespace std;

class Point {
private:
int i{0}, j{0}, k{0};

public:
Point(int x = 0, int y = 0, int z = 0) : i{x}, j{y}, k{z} {
cout

#
>employed where

>opOverloading
Its not something you should be using anyway

>Its not something you should be using anyway
Found the Java brainlet. Good boy. You should stick to "never do this, always do that" mantras if you're incapable of good judgment.

It's very convinient. I have to master it

Why? In certain cases it's an amazing tool to improve code readability. C++ streams use it really well.

>// This is not a friend! How can main see this?
It's public.

Anyway, operator- should not mutate the current object. It should return a temporary object. Do something like this instead.
Point operator-() const {
return Point(-this->x, -this->y, -this->z);
}

why the fuck do matlab arrays start at 1

C++ streams are a crap example of operator overloading.
user's using a Point class. That's arithmetic, so operator overloading is sensible and appropriate.

Well, I am doing this because unary -- is not allowed afaik

>It's public.
Oh thanks

cout

mathfags dont like 1 indexing

*0-indexing
fugg

I'm a mathfag. It's not about "liking" what I choose to like, it's math.

That being said, 0-indexing is correct.

Hmm, I get it
Thanks. Can you explain this?
friend istream& operator>>(istream& instream, Point& p) {
char l_paren, f_comma, s_comma, r_paren;
int temp_i, temp_j, temp_k;
instream >> l_paren >> temp_i >> f_comma >> temp_j >> s_comma >> temp_k >>
r_paren;
p = Point(temp_i, temp_j, temp_k);
// p here is a reference variable
// It points to a locally created instance of a class
// p should be refering to the local object, which gets destroyed
// Why isn't p invalid?
}

p continues to refer to the remote object. The Point is a local, temporary object.
p = Point(temp_i, temp_j, temp_k);
This line is equivalent to this.
p.operator=(Point(temp_i, temp_j, temp_k);
The compiler automatically generates this function if you don't specify it yourself or delete it.
The function copies the values of all the members of the temporary object onto p.

What's the difference between an object and an instance of a class?

They are the same.

Alright. Thanks user. :)

>What's the difference between an object and an instance of a class?
All instances of a class are objects but not all objects are instances of a class. Class-based OOP is a meme and there are superior alternatives.

>0-indexing came about because its easily translatable to a pointer + offset
Exactly.

Even when you are trying to specify a point in the axis, you really are specifying the distance from 0.

int* array0;

>Look up rule of 5
Thanks for that

But how do you ensure it's optimized then?

struct Butts{
int data;
};

void init(Butts* b){
b->data = 100;
}


class Butts{
int data;
Butts(){
data = 100;
}

Is there a difference?

Help needed.

sigprocmask(2)
>The use of sigprocmask() is unspecified in a multithreaded process; see pthread_sigmask(3).
>Each of the threads in a process has its own signal mask.
>A child created via fork(2) inherits a copy of its parent's signal mask; the signal mask is preserved across execve(2).

pthread_sigmask(3)
>A new thread inherits a copy of its creator's signal mask.

So if I call sigprocmask on one of the threads in a multithreaded process, the behaviour is unspecified but if I call sigprocmask on a single threaded process and then run new threads, it's not? Is thread's signal mask inherited from the parent thread or does it get a new one?

>You have to call a constructor on a class, you may not init a struct
>You can return an error value from an init function, you can only throw an exception or set an internal flag from a constructor

One has a public constructor, the other doesn't

data is default public in structs and private in classes

I unironicaly hate romanians tho

I'm trying to self teach myself programming. It's not easy. I'm following cs50 on some freeshit site. It's nice, but no one wants to learn C. Are there any self taught programmers lurking? How did you learn? I find it interesting if you're just naturally talented.

I learnt programming from very 0 by myself back in school days(got my CS degree later). I don't know whether it's the best way but I just picked a programming language and read a book(it was Java one, a regrettable choice). I just don't like any any online courses. If I could back in time I'd tell myself to start from SICP or K&R C programming language

>no one wants to learn C
I did.

>How did you learn?
Books, tutorials, asking for help on forums as a last resort. Nothing special or surprising. The trick is staying motivated, and what did it for me is always trying to apply a newly acquired piece of knowledge to write a program that does something that interests me. I started making little game-ish programs early on using only colored ASCII characters. That was always fun.

Reading and rereading books that my brainlet brain couldnt understand the first time, taking that cs50 harvard class, taking a few other free courseware classes, falling for the sicp meme, watching both the old sicp lectures and the one by brian harvey, many small toy programs, many college courses but I was already self taught in most of what matters, now it's just drudging through UML Software Process memes.
Went from using Visual studio to writing makefiles(Cmakelists) in vim.

Gotta learn pointers and recursion my man, learn C or at least C++.
Go find out why some cases of recursion don't blow the stack.
Learn about referential transparency.

So, is this shit any good for learning?

0-indexing is useful if we assume that index means memory offset. Otherwise, why would we use it?
>have N elements
>can't have Nth element

>C
But there's no TCO

>google cs50
>harvard webite
>click syllabus
>they literally have a tl;dr written with big red letters
The current state of CS. No wonder why we're ridiculed.
I thought Harvard was a good university, at least good enough for me to hear about it, being a non-American. wtf is this shit?

>How did you learn?
I played Roblox, so my first language was Lua. Then I played with some meme framework for GTA:SA modding in Lua/C#.
Then we had some "C++" in high school, or as I've recently taken to calling it, C plus iostreams. There was a student circle where we "learned" Java but it was just that we asked the teacher how to write something and the next day he would print us some code in Java and tell to rewrite it in an IDE and compile without any explanation.
At that time a friend showed me GNU±Linux, so I learned very little of Bash on my own.
Then I took the university that first taught me C on the first semester and then x86 assembly and Java on the second and I think this is an optimal start. You learn how shit really works. C teaches you the very basics, assembly shows you how shit really works and Java teaches you about abstracting that shit to make it easier to comprehend and how not to do this. Then you can pick up an interpreted language like Python or Lua.
You might want to try functional programming too. We started with SML but I can't tell if it's good cause the professor didn't give a single flying fuck about us and he just let everybody pass almost unconditionally. If somebody can confirm it's good to start with SML please do. Otherwise I would recommend Haskell. At least it seems more useful than SML in real world.

>I find it interesting if you're just naturally talented.
Talent is a meme; there's no such thing. It's just a matter of how well you understand the subject (how much you are willing to understand it), and the time and attention spent on it. You only need to practice. Start from a small project like a calculator app and slowly build up even to stuff like a simple 3D game engine or a compiler for your own language, whatever you fancy.

I'd recommend to learn software design and have a solid background in maths.

Can you make private data in struct?

Yes, use
private:

Just as you'd use public

bump

private keyword works fine.
Structs and classes are exactly the same thing in C++, the only difference is that structs are implicitly public and classes implicitly private.

But how would you put data or initialize the element?

>Talent is a meme; there's no such thing.
>t. talentless hack
I hate to inform you, but some people are naturally more adept at programming that you will ever be, and no amount of practice is going to bring you up to their level.

time to write a constructor

Keep telling this to yourself and achieve nothing lazy fuck.

But you can make it only with classes, can't you?

struct A {
private:
int x;
int y;
}

A a;
int* ptr = (int*) &a;
//set x
ptr* = 1337;
// set y
ptr++;
ptr* = 8008135;

No. You can make a constructor in struct just fine.

Nope.
Like said, there are only two major differences between structs and classes in C++.
>Members of a struct are public by default. Members of a class are private by default.
>A struct is public-inherited by default. A class is private-inherited by default. I don't know why the fuck this is the case because you almost always want to public-inherit a class and rarely want to inherit from a struct at all.

This is the cutest lain in the history of lainposting, maybe ever.

Link me to your favorite C++ lecture on YouTube. I always find them motivational.

I've seen people argue TIS-100 is actually a better game. If you like the idea of ASM try out WireMod for Garry's Mod and it's basically a simulated robotics toolkit (eg. gitlab.com/BobBarker/hoverbob )

WireMod was a lot of fun. E2 was the first time I had programmed.

But this is a hack which assumes we have data in struct placed together. What if data won't be placed such way?

Go read the C and C++ standards to see what guarantees are made about struct layout if you really care.

What if there are nested structs?

>Class-based OOP is a meme and there are superior alternatives.
Such as?

>There may be unnamed padding between any two members of a struct or after the last member, but not before the first member. The size of a struct is at least as large as the sum of the sizes of its members.

Prototypal inheritance I guess

youtube.com/watch?v=1i4-e1okZtw
:^)

Or pick one of these. Acton is a good one
youtube.com/user/CppCon/videos?view=0&flow=grid&sort=p

>anyone who calls me out on my bullshit is somehow lazy
Keep lying to yourself.

Prototype-based OOP. Far more flexible and expressive.

Are you talking about basically just using interfaces?

I don't think I ever read a proper book. I started around 10 years old or something, just learning from tutorials on the internet. Over time I developed my skills with more tutorials, actual experience working on projects, blog posts, StackOverflow, official documentation and reference material, etc.

No.
With prototypal inheritance, objects inherit from other objects and classes don't exist.

What's that?

I don't follow.

Isn't an object just an instance of a class?

Huh? Why is that better? And what languages work like that?

In a classical OOP language, yes. Different languages don't follow that model.

You're right. I wrote currently most popular operating system as soon as I popped out of my mom's cunt and I finished by lunch time. I was just bantering with ya.

Can you explain this interaction in another language that you're referring to?

How come when I call getopt(), "./prog -ab" works as expected, but "./prog -a -b" only gets the first option?
There's no real difference between my code and the code in the getopt(3) example.

Javascript is the most famous example, except that's kind of fucked.

>you don't think everyone starts on equal ground and everything depends on training?
>that means you think people are born knowing how to program!
It's neither, brainlet. Some people are more predisposed for certain kinds of tasks than others, so they pick up the necessary skills more easily and are able to master them to greater degrees.

Every object has a prototype. Every prototype is an object. If you try to look up a property that the object doesn't have, the property is looked up in the prototype instead.

Prototype based OOP is the ultimate meme of programming languages. Its programs cannot scale neither to machine nor to the human brain, it is unstructured, takes immense complexity to reify or do any kind of analysis and it's impossible to write an efficient compiler for.
>more expressive
That's a myth.

>muh subjective and unsubstantiated opinions about how hard it is matter
They don't.

>i-it's not more expressive
It objectively and undeniably is.

Why hasn't someone made a O(n) CSV parser?

O(log n)*

You want substance, fine. Reifying a prototype based program need context-sentive control flow analysis (call-path at least). EXPTIME complexity. In practice, not applicable to maximum call paths of length k=3 or more.
matt.might.net/papers/might2010mcfa.pdf

>read n lines in log n time
How?

I wonder how many C programs would break if you replaced int with int16_t (which is perfectly valid btw)

>completely failing to provide evidence that prototype-based programs are inherently incomprehensible and inefficient
Your paper does not back up your claims. Try again.

>I wonder how many C programs would break if you limited their integers to +/-32,767
wtf I hate C now

>never programmed in my life
>started CS
>read half of the book in two weeks
>can do fizzbuzz no problem

Why is it considered difficult?

quantum algos