Follow

C++ 

what if you had a language that passed all variables by value instead of by reference meaning that declarative passing of objects to other functions results in often-expensive copy operations for the arguments to and return value of each function call. so we use pointers for everything. except explicit pointer logic is extremely error prone so instead we should use objects which handle the pointer logic for us. also we need to invent references, which are like pointers but they're different, and add implicit conversion of objects to their references to the 1998 update to the language specification so you can pass these wrapper objects to functions without copies now. but also we need to invent rvalue references so you can pass rvalues to functions as well. btw do you know what an rvalue is? oops wait, these rvalue references so happen to fuck the taxonomy of value categories for the language so now you need to know what an xvalue is teehee

C++ 

@wallhackio the first sentence is just swift, but they changed the rest of it to “now what if we let the compiler optimize all of that away”

re: C++ 

@Lady C++ compiler writers actually did optimize some things before the '98 update but they added more to the language anyway because, ya know, C++

re: C++ 

@wallhackio i’m not expecting C compilers to do the whole “actually we wait to make a copy until we are sure the object is going to be modified” dance but i do at least hope they are smart enough for “if this function never modifies the object and the object is not extern and only visible in a single thread, you don’t have to copy it”

re: C++ 

@aescling @wallhackio swift takes the novel programming language approach of “what if we let computers do the things computers are good at and just let humans write sensible code”

re: C++ 

@aescling @wallhackio you could argue javascript did this first but arguably javascript is pretty bad at letting computers do anything

re: C++ 

@Lady @aescling could you elaborate?

re: C++ 

@wallhackio @aescling javascript has pretty much always operated under the pretense of “we will present a (comparatively) simple and understandable mental model to programmers and simply invest a lot of time and resources developing compilers that can optimize that to be fast”. the problem is that javascript gives its compilers very little information, and the fact that the runtime environment is a browser where anyone can open up devtools at any time and muck around places real limitations on how many optimizations they can do.

swift follows the same principle of “present a simple and understandable mental model, then rely on the compiler to make it fast”, but it is designed in such a way as to give the compiler a vast trove of information to work from, and when run as a static binary the possibility space is a lot more known.

(also javascript takes a stance of “you can change anything unless you explicitly prohibit it” while swift takes a stance of “everything is immutable unless you explicitly enable changing it”, which sure does make optimizations easier)

re: C++ 

@Lady @aescling you're making me want to try Swift

re: C++ 

@wallhackio @aescling i’m ideologically opposed to languages which aren’t developed by a standards organization but swift is good

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.