/dpt/ - Daily Programmmmmmmming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

stackoverflow.com/a/468105.
en.cppreference.com/w/cpp/container/vector/operator_at
en.cppreference.com/w/cpp/container/vector/at
scs.stanford.edu/~dm/home/papers/c -new.html
twitter.com/NSFWRedditImage

Linear types will save systems programming

How are you meant to handle program-crashing errors in C++?
For instance this crashes when it runs:
vector vec;
vec[0] = 2;


Why does it crash it and how can I handle the error, if at all? Does it implicitly throw an exception or something??

Exponential types combined with /dpt/-POO will destroy all notions of programming.

getting git to work with my bitbucket account. I hate that shit but want to learn it properly

>Why does it crash it
Because you never put anything at that index.

>how can I handle the error, if at all?
I think that's just a plain segfault or memory corruption. I haven't used the piece of trash that in C++ in years, but I'm pretty sure you need to use `get` for bounds checking.

Agreed. Working on a language with linear types and rely-guarantee references.

Depends on what exactly you want. Printfs are likely to be atomic. Check this SO answer for more details: stackoverflow.com/a/468105.

cuckity cucks

it's undefined behavior. if you want to be safe use the "at" method
and shouldn't you initialize the vector?

>When will part of a program "naturally" throw an exception?
It won't typically, what you have are function in the standard library that are specified to throw certain exceptions. What you're using there is std::vector::operator[], which does not say it throws any exceptions if you read en.cppreference.com/w/cpp/container/vector/operator_at . std::vector::at() on the other hand will throw a std::out_of_range — en.cppreference.com/w/cpp/container/vector/at

>I used to work as a programmer, but I eventually gave up because I couldn’t find a job, and ended I trying to make a living selling fantasy novels. Maybe this last fact shows that I’m not a great programmer (though there might be other factors in play). I love Rust because it makes me feel more confident about the code I write, and the strict compiler compensates for my lack of discipline.
Threadly reminder.

It depends, and you should check the documentation. Some functions will behave unexpectedly if you feed them bad data, while others will perform checks throw or return error values. C++ is concerned about speed and it's faster not to have safety checks interrupting useful computation everywhere.

Some stuff comes in checked/unchecked pairs. static_cast will fuck up your program in an undefined way if downcasting fails, while dynamic_cast will return an nullptr (for pointers) or throw an exception (for references).

If you ask 1 question, instead of telling us your lifes story.
you might get an answer.

>better post my culture wars garbage in this thread too

man I wish I had a job :D

std::use_cpp should throw a std::missing_memory_safety exception.

>waaaaaaah i can't post Sup Forums shit on the rust github

Trying to build a website using elixir & phoenix. It's going slowly since mvc is new to me and it's complicated working with ecto to write to and query a database

>t. inexperienced, gender-confused, sexually-disoriented, disabled, ugly, oversized-bodied, racially inferior, ethnically "diverse", underage, Mexican Wicca cult follower

>mexican wicca cult follower
That made my day user. Thanks.

fucking with compilers online

>get a job
>no time for shitposting or my fun side projects
eh

at least you have a job

Modding Terraria with tModLoader. It's fun! Trying to make an entire biome but for sone reason it won't load my backgrounds..

malloc is inefficient

>discussing the efficiency of a function signature
>discussing the efficiency of anything in an unqualified manner
The absolute state of /dpt/.

yes, the function signature precludes efficient implementation because free does not take a size parameter

>the function signature precludes efficient implementation

int foo( const double& p1, std::optional& p2 );


How efficient is my func guys?

this much self-awareness. unironically admirable.

>How are you meant to handle program-crashing errors in C++?
By not making them in the first place. You can't meaningfully recover from them.

>Why does it crash it
Because this vector has zero elements in it, which means vec[0] doesn't exist. Which means you are writing out of bounds.

>and how can I handle the error, if at all?
You can't. You need to check before making the error in the first place.

>Does it implicitly throw an exception or something??
No.

Not at all. You should return a const reference to a const int.

...

The same rule also implies that /lgbt/ stays in /lgbt/, user. Go home now.

Lol. You have to go back to >>Sup Forums now because that was comical.

Being nice to people is not /lgbt/. Calling people cucks for behaving like a civilized person is Sup Forums
Now fuck off back to your daycare board.
Out.

good goys

>Being nice to people is not /lgbt/
And yet it's always a faggot talking about it.

Any problem?

>Be on Sup Forums.
>Claim not to be a faggot.
If your not one of us, get out.

But all jokes aside.
we are on /dpt/.
Stay on topic.

reminder that linear types are a natural way to model inert physical objects
u take thing
now thing is in your hand
u put thing somewhere
now it's there
because it's now there, it can no longer in hand

Keep your friends close and your enemies closer.

>enemies
LMAO

What operations are well-defined for pointers and intptr_t?

Is this sort of thing guaranteed to have the same effect?
int *ptr = get_ptr();
intptr_t intptr = ptr;
intptr += sizeof (int);
ptr = intptr;
int *ptr = get_ptr();
++ptr;
What about more complicated operations like bitwise logic?

The fact that Rust is a librul bluepilled shitlang run by tranny niggers is on topic because it's Rust.
A discussion on the supposed merits of good manners is not on topic on any way.

im listening

Good books on procedural generation? Dwarf fort inspired me

Is it worth to use gcc 7?

The Rust shills are evolving primitive reverse psychology tactics.

>gcc
you don't even need the '7' to know the answer is no
fossfags get out, pc master race, rms is a fatty

can you red pill me on rust?
I see more and more knowledgeable people switch to it.

i want to start learning to program.
What language should i pick first and are there any good books/guides for it?
thanks senpai!

the best C compilers are foss

>The quality of posts is extremely important to this community. Contributors are encouraged to provide high-quality images and informative comments.

So, which compiler do you use for non "x=3*4" programs?

htdp!

Why do you want to program?

Learn it yourself and find out.

It's fairly difficult to deal with.
I think it follows the principle of "if it compiles, it runs"

>Learn it yourself and find out.
You really think Sup Forums is capable of learning Rust?

I'm not a Rust shill, I use C and Scheme exclusively. High level compiled languages rub me the wrong way.
I am however a falseflagging liberal, if that's what you meant by "Rust shill."

Rust shills employing primitive reverse psychology tactics, or a /dpt/ autist trying to emulate them? I honestly can't tell anymore. Good night, fellas.

Read your sickpea, user!

That's right, go back to Sup Forums and cry. Loser.

Fuck off

>You really think Sup Forums is capable of learning?

huh didnt know that

it was honest to god question dont be so paranoid

>You really think Sup Forums is capable of learning Rust?
You got yourself in a pickle there. If you dumb it down enough to for it to be accessible to blacks, it becomes accessible to Sup Forums. If you don't, you're clearly racist. What will you do, Steve?

Yeah. Last time I tried Rust, I found the borrow checker and the lifetime hard to deal with. However it helps you write programs in a way that it reduces the time wasted on debugging.

No!!!!
rrrrRRRREEEEEEEEE FSF IS BAD FUCK YOU!!! FREE MARKET ECONOMY!!!!!!SOCIALIST GO BACK TO RUSSA

Just report, hide and continue.
Don't feed the troll.

>it helps you write programs in a way that it reduces the time wasted on debugging.
By keeping programmers who can't use malloc and free correctly in fizzbuzz territory, where Rust is most applicable.

Usage of malloc has been deprecated by C++ a decade ago.

I don't like you. At least datafag was entertaining.

>If you don't, you're clearly racist.
Actually it's the other way around, you're clearly racist if you accept the premise that the difference in average intelligence between races is sufficiently profound to justify dumbing anything down for blacks that can already be understood just fine by whites.

C++ has been deprecated by sanity before it even existed.

>trying this hard
You are adorable, aren't you

Usage of malloc is only deprecated by C++ in C++ itself. C++ does not have the authority to deprecate malloc in C.

>if you accept the premise that the difference in average intelligence between races is sufficiently profound to justify dumbing anything down for blacks
You mean the way they accepted this premise when they lowered the requirements for blacks to get into universities etc.? You're underestimating the power of double-think and mental gymnastics.

C++ has deprecated C itself, user. Don't you see how the usage of C is decreasing? If not you are in clear denial.

>really believing that programs don't need the heap anymore

>You mean the way they accepted this premise when they lowered the requirements for blacks to get into universities etc.?
Oh right, I forgot some liberals still think blacks are socially disadvantaged by the fallout of forced immigration and slavery. I'm one of them who doesn't. I believe that fallout has mostly dissipated, and what damage remains is in their culture and family traditions, which it's now their responsibly to work to correct, not ours to step aside for.

scs.stanford.edu/~dm/home/papers/c -new.html

C will be eternal.

>What is RAII

>C++ has deprecated C itself, user.
C++ does not have the authority to deprecate C.
>Don't you see how the usage of C is decreasing? If not you are in clear denial.
Of course I do. However, popularity is irrelevant to the question.

>Of course I do. However, popularity is irrelevant to the question.
Aww
RIP C
RIP malloc

>a shit

int *foo = new[777];
delete foo;

Dependent on exception handling, and garbage.

You're just jealous your trashlang doesn't have RAII while both C++ and Rust has it.

Dead != deprecated.
C and malloc are still valid, and when literally no one uses them, they'll be valid even then, until the standard says otherwise.
If you disagree, you don't understand what "deprecated" means in computer science.

They should ask for virtual memory pages and use custom allocation beyond that.

That's actually std::arrayfoo; thank you very much.

>his language has two different delete operators
>his language silently corrupts memory if you use the wrong one
>he expects his language to be taken seriously

>crash

>exception handling is bad
>proceeds to use setjmp()
Cniles are a funny bunch

Setjmp is worse though. How did you get from "don't use exceptions" to "do use setjmp"?

>thinking any of the problems inherently affecting C++ exceptions also affect longjump/setjmp

Because that's how you cniles emulate exceptions. LOL