Old thread: Moment of silence for C's death edition.
/dpt/ - Daily Programming Thread
Other urls found in this thread:
youtube.com
isocpp.org
en.wikipedia.org
twitter.com
Sure, fa.m : ^ )
Good, thing is, you can just pick any meme language you like and I will just continue using C for embedded systems because that's the only language for which a compiler exist on my platform.
C repos existed for years before GitHub and even git itself were created. That chart means nothing.
Wow, Swift is already more popular than Objective-C? Nice.
nth for we made it to top 50
i know a lot of people who have had to work with Objective-C because of their work/platform and every single one of them, without exception, hated it with a burning passion. so i'm not at all surprised that people are eager to adopt an alternative
>D
>Better than Go in every single expect there is
>Yet not popular
JUST
We'll get there lad. Go just has a huge corporate backing.
aspect*
How do variant types look in D?
Objective C is the ugliest language ever made.
ADTs?
auto v = Algebraic!(int, double, string)(5);
Ocaml or Rust would like a word.
>We'll get there lad
don't hold your breath mate. don't get me wrong, it seems great. but it's been around for 15 years. i think if it was gonna achieve liftoff it would have done it by now
>5'11''
Manlet cuck.
Have you SEEN C++ yet?
i'm trying to format a bunch of data into json but i have a problem when it comes to std::string containing \"
std::string foo{ "test\"" };
the problem is that when i write that to a file as json, it shows up as
{
"someprop" : "test"", //note the extra "
}
which breaks the json because the json format is supposed to be
{
"someprop" : "somedata"
}
how do i fix this? i can't just insert a \ because that's just gonna escape the already existing \. please help
wait nvm it came to me the moment i hit post
>but it's been around for 15 years.
it was unknown for more than half of that, it doesn't really matter. It's an objectively superior language. Sooner or later it will find it's place as more people try it. Or not, I kind of hope it never finds C++ levels of popularity because i fear it getting an ISO and big corps like M$ fucking with it.
Better C with recursive macros and type inference when?
I have to count the number of 'brother' strings: LALALA and GOGOGO are brothers, because they both have the same structure (ABABAB), but GOGAGO is not a brother string. Similarly, HHHAAA and FFFOOO are brothers, but FFFOOOX is not. Here's my code:
with open(path_to_file) as f:
for line in f:
letters = list(string.ascii_lowercase)
new = []
x = list(line)
dictio = {}
for i in x:
if i in dictio.keys():
new.append(dictio[i])
else:
# list index out of range here!!
dictio[i] = letters[0]
new.append(dictio[i])
letters.pop(0)
new = ''.join(new)
foo[new] += 1
Basically what I do is rewrite every line using letters a-z, so that the structure will be the same for brother strings. But I get a list index out of range when the string in question uses all 26... Any help?
>I have to count the number of 'brother' strings: LALALA and GOGOGO are brothers, because they both have the same structure (ABABAB), but GOGAGO is not a brother string. Similarly, HHHAAA and FFFOOO are brothers, but FFFOOOX is not
you could use C++ with literally just constexpr (for recursive "macros", only semantically-aware/type-safe/more debuggable/etc) and auto (type inference) and otherwise just write C-style code (minus the few features in C but not C++, a couple of which you can still do with compiler extensions). you'd still be better off for it. personally i'd recommend also using *basic* templates to cut down on redundant code (shit like a vec3 of ints/floats/doubles without macros or writing things multiple times), and lambdas for much more robust/expressive code, but that's just me. worth noting that i'm a very experienced C++ programmer and what i just described is literally what i do for much of my code. you're by no means required to use a given feature, and you absolutely shouldn't use features just for the sake of it when they're not actually a good fit for your use case. C++ is what you make it. you're not gonna pay for anything you don't use, and some things (especially constexpr) can easily even yield more efficient assembly than comparable C without even having to rely on macros
just working on a problem, dude, care to help?
So for line in file, you want to count the palindromes, correct?
not palindromes. The strings with similar structure: ABCD and EFZN have the same structure, because there is a 1-to-1 mapping between them. ABC, ZYX, POD, they are all similar, 3 non-repeating elements. ABABAB and FOFOFO are 6 alternating elements.
>Solutions proposed
GC
Uglier syntax than ATS
Name mangling
nonstandard ABI
Anything but what people want from C
What if you have the following:
>JKJK
>LALA
>LMAO
>QWER
Is the answer 2 or what?
...
>nonstandard ABI
Not 1 person cares
>bu.. bu.. but muh vectors in standard library and templates!
>nobody cares about ABI
>WÄÄÄÄH MOOOM
You sepplesfags are the worst.
>nonstandard ABI
How is this an argument in two thousand and fucking seventeen? Who the fuck statically links manually when inter-language interfaces (such as for Python or JNI) exist.
Also
>C++
>GC
what the fuck?
JKJK and LALA have both the same structure(ABAB, or 1212), and LMAO and QWER both have the same (ABCD or 1234)
>No proper argument
As I said, not 1 person cares. Just as useless as the "ISO standard" gimmick.
Thanks, dipshit. You managed to not answer my question at all.
Actually, modern C++ is reference counted.
>attempting to expose type-specialised C++ vectors to external code / code compiled by a separate compiler
Name one (1) scenario where this would be what you want to do.
Reference counting is not garbage collection.....
lol sorry. The answer is 4, because you count the number of strings with a similar structure. if you had JKJK, LALA, BOBO, LMAO and QWER, the answer would be five, because 5 of those sentences have at least another sentence with the same structure.
It's actually worse.
>It's actually worse.
It's actually not comparative because they are two different things. You're grasping for straws.
You're a moron if you use shared_ptr for everything.
Modern C++ isn't strictly smart pointers.
Automatic Reference counting or ARC, is a form of garbage collection in which objects are deallocated once there are no more references to them, i.e. no other variable refers to the object in particular. Each object, under ARC, contains a reference counter, stored as an extra field in memory, which is incremented every time you set a variable to that object (i.e. a new reference to the object is created), and is decremented every time you set a reference to the object to nil/null, or a reference goes out of scope (i.e. it is deleted when the stack unwinds), once the reference counter goes down to zero, the object takes care of deleting itself, calling the destructor and freeing the allocated memory.
>legacy pointers
Not modern C++
You're a fucking moron if you exclusively use smart pointers.
Wrong.
youtube.com
Modern C++ advocates regularly encourage the use of raw pointers.
I know what reference counting is, it's not the same as a garbage collector.
>hurr durr but it says in this text that it is a form of it
What people generally mean with "garbage collection" is that your code is temporarily suspended (usually in a non-deterministic fashion) so that a separate runtime-thread can clean up references that are no longer needed. Usually, like in the case with the Java GC, this means searching through references using BFS, which can be quite costly for latency-sensitive applications.
Also, see and Reference counting are used for shared pointers.
>legacy pointers
Nobody implied this, there are auto_ptr/unique_ptr and weak_ptr, and a wide variety of different pointer types in Boost.
Herb Stutter is not the authority of what is modern sepples.
Yeah, for cases where it does not make any difference, basically micro optimization. Do you think I haven't watched that video?
>Herb Stutter is not the authority of what is modern sepples.
He and Scott Meyers, have a fuckton more authority on what C++ is than you have, some random brainlet on Sup Forums.
Automatic reference counting delivers a more consistent performance, no pauses, but slows down your application as a whole as every assignment of an object to a variable, every deallocation of an object, etc, will need an associated incrementation/decrementation of the reference counter, and taking care of reassigning the weak references and calling each destructor of each object being deallocated. GC does not have the performance penalty of ARC when dealing with object references; however, it incurs pauses while it is collecting garbage (rendering unusable for real-time processing systems) and requires a large memory space in order for it to function effectively such that it is not forced to run, thus pausing execution, too often.
ARC also becomes problematic when objects are shared across multiple threads requiring atomic incrementation/decrementation of the reference counter, which itself presents a whole new array of complexities and problems.
auto_ptr has been deprecated and no one uses unique_ptr
>and no one uses unique_ptr
Wrong.
>Except for you
okay
...what?
>GC
i have absolutely no idea what you mean by this
>Uglier syntax than ATS
my point was that it could be C syntax plus "auto" and "constexpr" if that's what you wanted
>Name mangling
>nonstandard ABI
extern "C". namespaces/templates/function overloading are optional
if you were using C-style code, which was the context of my post, excluding them is trivial
the point is that you would *still* benefit from even literally just auto and constexpr
>Actually, modern C++ is reference counted
top kek
>Reference counting is not garbage collection
>It's actually worse
topper kek
>Automatic reference counting delivers a more consistent performance, no pauses,
Yes
>but slows down your application as a whole as every assignment of an object to a variable, every deallocation of an object, etc, will need an associated incrementation/decrementation of the reference counter, and taking care of reassigning the weak references and calling each destructor of each object being deallocated.
So only use it where it is appropriate then. You know, nobody forces you to use shared_ptr for everything.
>ARC also becomes problematic when objects are shared across multiple threads requiring atomic incrementation/decrementation of the reference counter, which itself presents a whole new array of complexities and problems.
See above.
>no one uses unique_ptr
That's just plain wrong.
>a prominent board member with decades more experience and competence isn't an authority
I don't even use sepples, but you're a baka m8.
>Herb Stutter is not the authority of what is modern sepples.
Actually, he fucking is: isocpp.org
>extern "C". namespaces/templates/function overloading are optional
that's most of the reasons to use C++ out of the window.
Ref counted cucks utterly BTFO
what's the chance of randomly generating two identical base62 32digit numbers within a minute of each other if at max, i might generate a 100 per minute?
there's no way that this would happen right?
explains why the language is so shit and why everybody who uses it are massive faggots.
>See above.
Doesn't solve the problem at hand, honey. Go read more books and watch more anime with traps and lolis. It'll increase your IQ by 5.
Reference counted pointers in C++ are something you have to use explicitly, whereas garbage collection is something that is generally implemented as an implicit feature of the runtime.
In other words:
If garbage collection is impacting the performance of your code, you're using the wrong language.
If reference counting is impacting your performance, you're simply a bad programmer.
why don't you test it out yourself?
>Pass Upwork's C# test with score of 3.5 out of 5
>Pass Upwork's C test with score of 3.4 out of 5 (ranked above average)
Am i a faggot and should i kill myself?
>Doesn't solve the problem at hand, honey.
The problem is "solved" in that shared_ptr are thread-safe. The standard library uses uses atomic compare and swap operations for a lock-less implementation. You're just retarded for being unaware of this fact.
Exactly.
Smart pointers (or reference counting) means you have a way to automatically delete your data on your heap, where garbage collection is a process you run to remove data when convenient.
Having a destructor is very convenient because you don't have to explicitly write every time you want to clean up after itself, you just write how to clean up.
Garbage collection is worse in every way.
>If reference counting is impacting your performance,
Reference counting is not free of cost, child. It's not a black magic. Reference counting slows down your performance bit by bit and it only grows.
>when objects are shared across multiple threads requiring atomic incrementation/decrementation of the reference counter, which itself presents a whole new array of complexities and problems.
Increasing and decreasing a counter atomically is literally babby's first concurrent program, you humongous retard.
>Am i a faggot and should i kill myself?
Yes, and this is a blue board.
>Reference counting is not free of cost,
So DON'T. USE. IT. WHERE. IT. ISN'T. APPROPRIATE.
This was meant for
>Smart pointers (or reference counting) means you have a way to automatically delete your data on your heap, where garbage collection is a process you run to remove data when convenient.
>Having a destructor is very convenient because you don't have to explicitly write every time you want to clean up after itself, you just write how to clean up.
>Garbage collection is worse in every way.
Did you have a stroke between these two sentences?
Nobody is holding a gun against your head and forcing you to use a shared_ptr where you should use something else. As I stated in my original post, if reference counting is an performance impact for you, you're applying it where you should do something else (in other words, you're a bad programmer).
>So DON'T. USE. IT.
Not modern C++, my boy
Can tackling increasingly complex programs and algorithms improve thinking and programming ability or is it mostly determined by IQ?
The chance of that occurring is approximately one out of every 2272657884496751300000000000000000000000000000000000000000 number generations.
But the people who tell you to use modern C++ say you should only use shared pointers where necessary.
>you must use shared_ptr everywhere
Not using shared_ptr for everything is literally one of the items in Scott Meyer's books.
No, the era of `new` and `delete` is over.
>Scott Meyer's books.
Deprecated.
>complex programs
>algorithms
How about you focus on making something simple, manageable, and useful first? Identify a business or academic need and solve it.
BTFO'd
The alternative to shared_ptr is not new/delete.
...
Incrementing an integer and decrementing an integer every time you call new / delete is nothing compared to how long it takes to interface with memory.
I welcome you to write two examples in c++, one with raw pointers and one with smart pointers where you can measure the difference.
>book is literally called Effective Modern C++ and contains C++14 and C++17 examples
>deprecated
>How about you focus on making something simple, manageable, and useful first?
I have though. It's mostly what I've been doing as a code monkey. What I wonder though is whether I can become more, as to be honest all the best programmers I've seen were incredibly intelligent and I don't think I can reach that level with practice alone, though I am willing to dedicate a lot of time.
Python is disgusting. Why do so many people use it? The syntax is shit and it's also slow. Yet here we are with whole server frameworks running in Python.
See and
That's an over simplification though.
>Legacy pointers
Deprecated
But it is, at least for the 99% of the cases
Nobody said anything about C-style pointers you fucking idiot. See In C++ you also have this thing called references, which is used wherever passing a reference is needed but constraints are needed.
the *whole point of my post* (which was a response to ) was that if one *didn't want to use* most of C++'s features, and simply wanted essentially "C with recursive macros and type inference", one could achieve this with C-style C++ code along with "constexpr" and "auto"
>making something useful is being a code monkey
>learning algorithms that may or may not ever apply to a practical solution you're designing is not
?
>ref counting
Small overhead (incrementing/decrementing a counter and a zero check is not that expensive), allows easy management of quite complex data structures, where every object may be referenced by several others. The deficiency is that reference counting requires references not to be circular. Once you get reference circles, you leak memory.
Weak references may be used to break some reference cycles, however, they come with quite a bit of additional costs:
Weak references require a second reference count to manage the weak reference itself. Likely, the weak reference is another object that needs to be allocated independently, incurring a significant overhead in memory consumption.
Destroying an object in the presence of weak references requires atomically resetting the weak reference that belongs to the object and decrementing the reference count. Otherwise you get erratic behavior of the weak references. I'm not into the details, but I believe this can be hard to achieve in a lock-free fashion.
>pulling random numbers out of your ass
>smart pointers
Reference counting alone leaks cycles so reference counted smart pointers will leak memory in general unless other techniques are added to catch cycles. Once those techniques are added, reference counting's benefit of simplicity has vanished. Also, note that scope-based reference counting and tracing GCs collect values at different times, sometimes reference counting collects earlier and sometimes tracing GCs collect earlier.
Smart pointers are one of the least efficient forms of garbage collection, particularly in the context of multi-threaded applications when reference counts are bumped atomically. There are advanced reference counting techniques designed to alleviate this but tracing GCs are still the algorithm of choice in production environments.
Typical smart pointer implementations allow destructors to avalanche, resulting in unbounded pause times. Other forms of garbage collection are much more incremental and can even be real time, e.g. Baker's treadmill.
Friendly reminder that the Linux kernel object model uses reference counting a lot of places (see every single get and put function, for example get_user_pages and get_page/put_page).
>I'm not into the details, but I believe this can be hard to achieve in a lock-free fashion.
It can. GCC's shared_ptr implementation uses atomic instructions to increase/decrease the counter, and freeing the object in a concurrent runtime is therefore trivial.
>linux
>pinnacle of anything good
>particularly in the context of multi-threaded applications when reference counts are bumped atomically.
You literally know nothing about CAS, RCU and other mechanisms used in lock-free atomicity.
Making a website is useful, but that doesn't mean it's great or interesting work, and besides I don't see what you're basing yourself on. I know for a fact the guys in charge of algorithms contribute a lot more than I do as I redesign the UI again or add some neat features.
Regardless, this is all irrelevant to my question. Do you think a programmer's thinking and problem-solving abilities can be improved through practice or is it mostly IQ?