/dpt/ - Daily Programming Thread

Smart pointers edition

All the benefits of garbage collection and essentially no negatives. Why don't you code modern C++ yet Sup Forums?

Old:

Other urls found in this thread:

tips.fbi.gov/
sel4.systems/
twitter.com/NSFWRedditVideo

It's not even past bump limit nigger

>modern C++
You mean Rust? C++ doesn't have borrowing.

>thread allocated too early
>yet to be properly deallocated
>loss of image quality
>misleading comments

so this is "modern C++"

auto&& x = new unique_ptr[5];

>All the benefits of garbage collection and essentially no negatives.

Yes, except it's not like garbage collection, because it's not garbage collection.

It's reference counting you retarded retard

>no negatives
>garbage collection
I think you just tubgirl'd yourself

a GC pointer is a kind of smart pointer user

Been trying C as my first language, but it's boring. Is Python a better first language?

Haskell

If you want to quickly get something fun on your screen, Python is probably better. Check out PyGame.

Exactly. Real garbage collection is much better and you should use Boehm's.

Garbage collection is useful. That said, I think it should be limited using regions, and collections shouldn't be done automagically.

Nice try, I know you're trying to meme me.

>much better
>randomly slows your computer down

>randomly

It's not random so much as it's choosing the best possible moment.

You've never developed anything with real time constraints?

Damn, you've caught me

If you can't clean up after yourself go back to Java

Nobody on /dpt/ has developed anything hard realtime.

>Smart pointers

if you know how to program you don't need this shit

What kind of questions you were asked during job interview?

>Not using scoped memory pools

>types
if you know how to program you don't need this shit

Anyone know where I can get a 1 gbit unmetered VPS?

tips.fbi.gov/

its not a meme
will force you to think in immutable contexts
helpful for c

Downloading videos and uploading them to YouTube for ad money

>be "smart" programmer
>think I can get away with doing everything myself
>spend 90% of cognitive effort keeping track of shit that the type system could do for me and get nothing done

>meanwhile
>actual smart programmer uses as many tools as possible to reduce cognitive load
>of course, he only picks tools that don't sacrifice code clarity or runtime performance, etc.
>is far more productive than me, just not as smug

>entire post is greentext

>poster belongs on reddit

Have you done your SICP today, Sup Forums?

Who are you quoting?

Scheme is still trash

somebody teach me pointers right now
I honestly need this

All I ever see on /dpt/ is wherever haskell is mentioned, they're trashing it.

Blub paradox.

WRITE TESTS

CLEAN YOUR CODE

&x = address of x
*x = value at address x

tests are inferior to proofs

No negatives, except every time you copy a shared pointer or it goes out of scope you incur at least one pointer dereference to update the reference count, oh and either you can't use them with multithreading or they incur an additional cost of waiting to lock a mutex, oh and you have to deal with cycles using weak_ptr yourself because shared_ptr alone can't handle them, oh and when an object's reference count goes to zero and it gets freed it can set off a chain of such actions because it might be the only object with a reference to another object so an object going out of scope is no longer constant time.

Smart pointers are worse for most situations.

Tests are easier to write.

It's not perfect, but testing using generators isn't so bad.

Ho sorry, you're a code monkey.

You mean SHARED pointers. Shared pointers are given way too much attention, they should be a last resort. You rarely need them.

Never trust Sup Forums. Especially /dpt/.
This is the thread who still swears desktop application and tools should always be written in C.

SICP is a meme.

Proving the correctness of any sizeable program is intractable. Meanwhile, it's easy to get 90+% test coverage.

>Proving the correctness of any sizeable program is intractable.
sel4.systems/

so, *&x = x

Yes.

yes

Yes, fair enough. Unique pointers by themselves aren't all that useful, though.

Functional programs are proofs.

how do addresses work?

Test coverage makes clients happy. Proofs don't.

They're proofs that their type is inhabited.

>documentation and compile-time checking aren't useful

>They're proofs that their type is inhabited.
Which, under totality, is a proof of the proposition that the type corresponds to.

it's a memory address (just a positive integer) and a type (the type you get when you dereference it using *)

&x = address of x
obviously, and don't forget
*x = value at address x
why do you even come to /dpt/ if you don't know this

You write one on an envelope before you put it in the mail and USPS will make it appear at that address.

Fine, fine. Unique pointers are less useful by themselves. Happy?

Invoking the Blub Paradox is a worthless non-argument. It can be used to argue for anything. It used to be used for the extremely-permissive Lisp, now it's used for the extremely-restrictive Rust and Haskell. All you're saying is that you don't have a real argument.

It's very easy to start using Haskell and see how poorly designed it is. I don't want to think about operator precedence just to see what arguments are passed where, I don't want to pollute the surrounding namespace when I add fields to records, I don't want to read code with 2-letter names, I don't want to wrangle 5 different string types, and I don't want to remember a myriad of language extensions so that I can fix the problems that actually have solutions.

I'm looking to learn Scheme so I can use it as a scripting language in muh game enjin.

>extremely-restrictive [..] Haskell
Haskell is hardly restrictive.

>sel4.systems/
It has slightly over 900 commits. It's probably tiny.

I'm not saying Haskell is perfect, I'm saying /dpt/ doesn't know how to criticize it properly. You just did, and I accept that.

Seriously, why would anyone make the default String type be a linked list?

For pedagogical purposes, sure, make your own prelude where String is defined as [Char]. But the current situation is madness.

>Which, under totality, is a proof of the proposition that the type corresponds to.
Having types for some things != having proof of anything close to all of the interesting properties of a system

Not that user, but a couple things that annoy me are that the typeclass hierarchy is a mess (Monad has fail, MonadPlus is two things combined into one), and that I'd really love to be able to annotate things as total.

>Seriously, why would anyone make the default String type be a linked list?
it's a lazy recursive list

Mathematicians disagree.

Will bcachefs deliver on btrfs's failed promises, and finally being a ZFS replacement to Linux?

Dependent types, user!

You can prove that a sort function's output is sorted, you can prove that a binary tree remains balanced.

That's even worse!

the idea behind records is accessing data easily
if you don't want it polluting the namespace
you can always make a module with types and import it qualified
>operator precednce
I"ve never had the problem, but even then, just :i function in ghci and problem solved
there's also explicit ( )'ing

You can also prove that there won't be memory errors, you can prove that a recursive function will terminate, you can prove that a program will respect real time deadlines, etc.

>let's make our standard library less useful because new learners might find it confusing otherwise!

>Dependent types, user!
>You can prove that a sort function's output is sorted, you can prove that a binary tree remains balanced.

I mean yes, but who uses those languages?

And you can't tell me they're not verbose.

>That's even worse!
No it isn't. It makes perfect sense and suits Haskell.

It would be a completely retarded decision to decide for String to be anything other than [Char]

They asked me where I got my T-shirt then how much money I wanted.

>you can prove that a program will respect real time deadlines
...really? How can that cope with OS interference? Even if you assert that it's not allowed to suspend you, you still have to worry about virtual memory stuff, surely?

>who uses those languages?
Not an argument.

>And you can't tell me they're not verbose.
Automated and interactive theorem proving make things a lot better.

Well, you can only make assumptions about things outside of your control. And you really can't do hard real time on top of an OS not designed for it.

Then why is the standard advice to use Data.Text instead of String?

It's not, unless you want to do lots of demanding text operations.
Which most people don't do.

>don't want to read code with 2 letter names
not an argument towards the language

>5 different string types
thats a semi-argument, but even then, its not that hard to remember which are supposed to be used for when
>>rememebr lang extension
>not just keeping a log of what pragmas you use

Ah, I see. You're not talking about regular programs running on Windows or Linux.

>I don't want to wrangle 5 different string types
type classes

That's what hard real time is. Soft real time, like games, that's where you need profiling when it comes to performance.

I'm sick of all these one- and two-letter symbol names. Who possibly understands what !=, ^, ||, +, &, etc. mean?

>>don't want to read code with 2 letter names
>not an argument towards the language

A language and its ecosystem are intertwined. I still want to read other peoples' code, even if I opt to write mine in a totally unidiomatic way.

P
E
R
F
NOT
R
M
A
N
T

The thing about ad-hoc overloading in Haskell is that it can only be done with type classes, so operations with the same name always do, more or less, the same thing, especially if there are laws in the type class.

Unfortunately, Haskell can't enforce these laws by itself...

>2 letter names

Did "pi" confuse you?

>Unfortunately, Haskell can't enforce these laws by itself...

But I thought type systems were magic. ):

In C++14, why is it so hard to find an example of constexpr being used properly, to make something fucking useful like a simple integer LookUpTable based on an array?

Type classes are static dispatch normally, you have to opt-in to dynamic dispatch.

Haskell's type system isn't magic enough, but types in general can do it.

There was a guy claiming he had just a week ago

is rust actually worth learning? no meme answers please

Anybody can claim to have done anything.

Yes. I suspect you will consider this a meme answer, though.

No.

Nope.

>no HKT
>no higher-order polymorphism
>no effects system

He would have no reason to lie

He would have no reason to tell the truth