/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?


Previous Thread:

Other urls found in this thread:

tutorialspoint.com/cplusplus/cpp_classes_objects.htm
defmacro.org/ramblings/lisp.html
twitter.com/SFWRedditImages

how do I declare a new object in C++ without using new?

thank you for using an anime image

how do I delete an object in C++ without using delete?

I posted this in the previous thread, but here seems pretty nice.

What does /dpt/ think of a Tox powered podcast where we talk about our projects? We all join a group chat, negotiate a time, record our version of it, and distribute it somehow (torrent, upload to website).

If people like the idea, i'll set up a Raspberry Pi ToxBot and post the ID here

class IHopeYouLikeCplusplus
{
const char* message = "Hey! Hope you're having a great day!"
}

int main()
{
IHopeYouLikeCplusplus a1;
}


Source: tutorialspoint.com/cplusplus/cpp_classes_objects.htm

Nande?

Malloc and free

Paddle paddle{...};
auto paddle = Paddle{...};

If it's a field you want to define in a constructor:
Object::Object : paddle{...} { ... }

malloc and free should work just like they do in C
You can also just use the stack, but that might not fit your use case.

Thank you for using an anime image, OP.

I'd like to know too.

You don't, pretty much. It works like - if you want to put it on the stack (as a local variable), you don't use new. If you need a pointer to it, you require the keyword new.

Maybe I'm feeding a troll.

That'd be kind of neat, but I wouldn't participate personally if it's intended to be recorded and indexed publicly.

If an object has a destructor, it automatically is destroyed once it goes out of scope

How do I suck dick without being a faggot?

maybe I need to put an example.

I don't want to create a pointer for just a simple value of my object.

>Using large icons on the taskbar

Do you have bad eyes or are you incapable of pointing at small things

>That'd be kind of neat, but I wouldn't participate personally if it's intended to be recorded and indexed publicly.
I'm also the BasicTV guy. I would take these episodes and broadcast them as they came out.

Are you asking how to define your constructor?
Paddle::Paddle() { ... }

You can construct that SDL_Rect like so if it's a field of Paddle called rect:
Paddle::Paddle() : rect{0, 0, 100, 100} {}

Will reading SCIP actually make you good at coding or is it just for turbonerds who want to understand fundamentals they'll never actually use.

why do you put rect between : and {}?

Just a fair warning, these questions you're asking are somewhat vaguely worded, and low enough level that they're covered by basic tutorials; they might be irritating some people because of that.

By "simple value" my best guess is you want it to be on the stack (to learn about C++, you need to know what the stack/heap and pointers are) as a local variable, in which case, you would do it like the first code snippet in .

Might be the default size in Windows 7, but I can't remember anymore.

It's a meme lol

I dont think you know how to ask this question very well. But i think you just want something on the stack? If so I think you can do padle A(...);

yeah, I want the arguments of the constructor to change the rectangle value without using a pointer.

It's called the initializer list. You can also do
Paddle::Paddle() {
rect = SDL_Rect{0, 0, 100, 100};
}

but the initializer list is recommended because doing it in the constructor itself will not work for classes that don't have a default constructor (as C++ will try to default construct all the fields if they're not constructed in an initializer list before running the constructor).

I'm confused because in Java and C# you can easily call new on everything you make, but on C++ there's no need to call new on everything.

thanks, that answer my question.

Yeah but like /lit/ meme books are also good books a lot of the time

Gonewild ripper with Python

Give it a reddit account, it pulls down all nsfw posts they've made that are hosted on reddit, imgur, gfycat, and eroshare.

Functionality is done but it has no interface, no error handling, no logging. I have to call it from the repl for now.

that is a really cute picture of karen

One of the pieces of audio I used to test BasicTV on the live stream was an audiobook copy of Gravity's Rainbow

10/10 would stream again

IJ is terrible tho

SICP will teach you how to program, not write code.

If you don't use these "fundamentals" in your coding then you're not worth your own salt as a programmer.

should I give up on C++?

>coding for any reason other than ez money with minimal human contact

Java and C# take away a lot of your power that you get from pointers. Pointers in computers are very important and powerful at a low level. But the benefit is you dont have to worry as much about the intricacies of pointers and the mistakes you could make. In c/c++ you can declare things without new because you decide how you want to use your variables. Either on the heap or on the stack which have their own befits/drawbacks.

Object object;
Object objectFromConstructor(args, go, here);

But you haven't even done anything.

Calling new in C++ technically does the same thing that the keyword does in C# and Java - memory is allocated from the heap and the object is constructed at that memory location. In C++ though you can statically construct objects ie. from the stack rather than the heap. Stack allocations is the same thing as using primitives, you just do:
typename foo; // calls default constructor

typename foo(x,y,z...); // constructor with arguments


when you use new in C++, ie. heap allocation, you also have to later explicitly use the delete keyword to free the memory (something which is done by the garbage collector in Java and C#). Tbh you should do some tutorials on dynamic memory in C++.

You dont have to use an initializer list thats just the hotest new meme on the block. You can also use a java style of constructors.

c++ is too hard.

Since you're starting out with C++ you should probably avoid new/delete and stick to smart pointers (unique_ptr, shared_ptr) if you need heap allocation. new/delete may seem straightforward, but you need to be thinking of exceptions and copy semantics whenever you use them.

FFS it's telling you what you need to change. You should also think about getting glasses since you can't tell () from {}.

To add to this make sure your destructors take care of anything dynamically allocated within your class itself otherwise you will still run into memmory leaks.

learn an easy language like Haskell

...

It doesn't work.

This desu desu

Are you even trying?

c++ is too hard 4me

lad, we told you already, the constructor should look like
Paddle::Paddle(int x, int y, int widht, int height)...

It's not void, and it's a member of the Paddle class so you do the Paddle::

Go back to C# if you don't want to use C++, then.

I think you just enjoy asking dumb questions and not actually thinking for yourself desu.
You should, like, fix that attitude.

m8, yesterday I coded pong in libgdx in like five minutes.

It's been two hours and can't get a stupid rectangle on screen in C++

I just wanna elicit a response from a web server and print it, why doesn't this work?
#include
#include
#include

using boost::asio::ip::tcp;

int main(int argc, char **argv)
{
try
{
if (argc != 2)
{
std::cerr

Just nitpicking, but it's unfair to lump Java and C# together here. In C#, you can do most of the pointer-related stuff you'd ever need safely with IntPtrs/Marshalling/etc. For the rest, you can use the unsafe keyword, at which point you just get C++ pointer addressing/dereferencing semantics and arithmetic. Also, C# structs are heap-allocated value types with automatic boxing/unboxing.

so in initializer list, you don't do equals, just do it like
Paddle::Paddle::(blah blah):
rectangle(blah,blah)
{
}


Now the next thing you should do before you continue shitting the thread up is DO A TUTORIAL or at the very least practice doing some basic algorithms or some shit so you can get hang of the language.

/dpt/, have you ever asked yourself, what the fuck were your parents thinking?

*stack-allocated

oh yea sorry I forgot C# has an unsafe mode, haven't used C# much. All I remembered is that java and C# are nearly the same language at least for syntax. But yea he was asking it like he never used unsafe mode in C# since he's trying to avoid pointers altogether and doesn't realize there is an alternative to calling new for every class.

Dad was thinking in binary, mom in quarternary.

Please respond.

...

Java and C# were pretty much the same language around 2005ish. Since then, C# has come a long way, and Java has not. In particular, C# is made by people working down the hall from the people who make F#, and they are all friends with each other and they share ideas for features and the F# ML nerds are always suggesting stuff like "hey, what if... tuples" and the C# bros listen and they add it to the language. Whereas Java is developed by Oracle.

What's the point of asynchronous programming?

But why wouldn't you just do things synchronously so they're easier to understand?

>I have to call it from the repl for now.

I think that is the best interface. I always make libraries then implement a really simple cmdline utility around it if it's really really necessary.

>asynchronous
basically things happen at the same time

Bascailly doing expensive operations in some other thread just to not lock the current one. This helps a lot to, for example, UI responsiveness.

Do you not know what the prefix a- means?

So it's event driven programming with threads?

I'm finding it really hard to wrap my head around all this. Everything's all different, the only "async programming" that seems to actually work is network programming, everything else just isn't compatible. For example I still have to get window events for user input.

I know what it means, maybe I worded that incorrectly. I meant that things happen at the same time independent of one another, as opposed to synchronous programming where things happen together.

multithreaded applications are wonderful for speed
IMHO it is better to understand internal workings as partitioned off and specialized blocks, and it can really help speed up the program.

For example, i'm working on networking for BasicTV, and the two things that still need to be done is connection making and making requests for data. Now, if 10,000 nodes exist on the network at any given time, which ones should I contact for the information?

Every single piece of data that gets read into the socket has its ID cataloged and for every ID that is requested, it goes through all of those IDs and finds the IDs that are closest to it in the linked list. Every ID has to be looked up in a table, and a lot of them have to be read back from the disk. Then the process repeats to travel a distance up and down the linked list from that point.

>For example I still have to get window events for user input
Whatever information needs to be transported ought to be done through some FIFO buffer between the two threads

To always make forward progress instead if needlessly waiting and blocking on things.

Why would I want to learn metaprogramming and what is metaprogramming?

defmacro.org/ramblings/lisp.html

generally just programming at a higher level

>What is metaprogramming
Metaprogramming is writing programs to write programs. One common example is C macros.

>Why would I want to learn metaprogramming
Personally, it helps make redundant code less error prone, more uniform, and easier to maintain

Metaprogramming is when you manipulate the syntax itself.

>Whatever information needs to be transported ought to be done through some FIFO buffer between the two threads

I mean about the API. You can epoll on a socket fd but you can't epoll on files and also not on X/wayland/windows/whatever events I think. Signals make the entire thing infinitely worse. It's just a mess.

Honestly sometimes it feels like the best way to solve communication problems is to do it like we humans do it: messaging. 0MQ good for this?

Wear a skirt, make sure the balls don't touch, and say no homo before and after.

Why are you using TCP sockets in Asio to do what libcurl was made for?

Window managers will generally queue up events so that, instead of blocking on the next event, you can check if there even is a next event before getting it. In Windows this is accomplished with PeekMessage.

long time no see Sup Forums

I need to search the archive for a thread, not sure if it made it to archive or was deleted but it relates to happenings and is important.

I need to search via information that I can only see when I mouseover "view", because I dont remember the thread title, or the words in OP.

I know I am going to need to go deeper than just curl | grep 'regex' in order to search content of relevant threads. Has anyone ever done a search like this, or have a script for something like this?

>when I mouseover "view"
can you give some examples?

like I remember words in the thread that were important that could be candidates for searching for the correct OP.
I know the date and approximate time.
I know the approximate number of responses to the thread

These are all things I could use to narrow down a search to an appropriate number of human browsable threads from thousands to less than 100

Best I can say is try and download every thread that ever existed and git gud at regexp

do you know of an easy to implement spider that could do the download part for me?
Downloading them all by hand alone would be more labor intensive than just looking through the thousands of threads

I made something like that for farming Sup Forums threads about Pizzagate. It just downloads all links from a website.

I think you would benefit more from a recursive wget (set the depth pretty high). Find as many websites that would have that archive and download them all.

this is recent, it should still be on the Sup Forums archive. So it doesnt need to be big, it just needs to be fast.

If you really need fast, then axel downloads multiple files at one time to get past per connection quotas (only works when they are the limit).

I've been working on a simple Makefile generator for out of source builds.

>VStoddler
Yes of course

I just made a project of two C++ files to check how linking worked, and g++ compiles the programs but fails to link them, gives me a undefined reference to error.

I even tried $ g++ -c for both files and then linking them, but it doesn't work. What the fuck do I do?

$ g++ splitTest.o split.o -o myProgram
splitTest.o: in function 'main':
undefined reference to void split

Is a lisp interpreter the same thing as a compiler?
Also, I'm reading SICP and using scheme, is everything with scheme done at runtime? Like I just type commands into terminal and the interpreter spits things back out at me? It feels really weird not writing some type of text file, and not compiling it.

Project Euler 10...

A little stuck since I'm still using the Sieve of Eratosthenes to make primes.

What is another way of generating primes that's better, but still implementable for a beginner/brainlet?

REPL, yes exactly.

You can compile LISP code though. You can also write it and load it too.

If you are new to all of this try Racket. It makes things easier for newbies to understand.

if the candidate prime you are checking is n

you only need to check upto
if (yourPrimesList[i]

Crazy.
I'll check it out Racket, too, thanks.

Will pic related teach me how to write a kernel and a shell?

import std.stdio: writefln;

void main() {
const uint to = 10000;
auto sieve = new bool[to];
uint[] primes = [];
foreach (uint i; 2 .. to) {
if (!sieve[i])
{
sieve[i] = true;
primes ~= i;
for (uint j = i * 2; j < to; j += i)
sieve[j] = true;
}
}
writefln("Primes below %s (%s found):\n%s\n", to, primes.length, primes);
}

It's shit.

please use local imports

void main() {
import std.stdio : writefln;

So is your mom, but you don't hear all those men complaining.

I'm sorry, senpai!