• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

So I shouldn't waste time learning SAS in a week? :p Any tips on what I should do to prepare?

if this is an entry level position, they're likely not expecting anyone intimately familiar with SAS. Learning as much as you can is never a bad thing though. If you can pick things up quickly, that'll bolster your chances further.
 

balgajo

Member
Is your singleton defined in a static library that is linked into multiple different shared libraries?

It is defined in one shared libraries and used by other two libs and the main application. Though 3 instances are generated in this process. I can see why I'm having this problem but I don't know if there's some workaround on linux.
:(
 
It is defined in one shared libraries and used by other two libs and the main application. Though 3 instances are generated in this process. I can see why I'm having this problem but I don't know if there's some workaround on linux.
:(

I have a couple of theories, but rather than throw darts and hope I hit something, can you post the code for the singleton?
 

balgajo

Member
I have a couple of theories, but rather than throw darts and hope I hit something, can you post the code for the singleton?

Here it is!


template <class T>
class Singleton
{
public:
static T& instance()
{
static T instance;
return instance;
}

private:
Singleton();
~Singleton();
Singleton(Singleton const&);
Singleton& operator=(Singleton const&);

};
 
Here it is!
Code:
template <class T>
class Singleton
{
public:
    static T& instance()
    {
        static T instance;
        return instance;
    }

private:
    Singleton();
    ~Singleton();
    Singleton(Singleton const&);
    Singleton& operator=(Singleton const&);

};

Alright this is one of the cases that I suspected. In theory this is supposed to work (on Linux anyway, but not necessarily on Windows), but declaring function local statics inside of a header file is a really bad idea because there are some *really* subtle rules about when it's supposed to work and when it's not. In this case I'm pretty sure it's supposed to work, but given how ugly this part of the language is, I would advise using a different approach.

What's *supposed* to happen is that the function local static is supposed to get a unique mangling, COMDATted, and then when these shared libraries load it's supposed to resolve the symbol based on the mangling so that only a single copy of it is being used. Note that on Windows this isn't the case, multiple DLLs (i.e. shared libraries) that included this header would be guaranteed to get a separate instance of the static.

If you're using an old compiler, it's possible this isn't working. Or there could be something else going on.

If you want to delve into this deeper, you could use a tool like nm to display the symbols in each .so file and verify that they have unique names.

On the other hand, I would probably just implement singleton-ness at the class level. Do you really need it to be this generic? You could make a Singleton<int> using this class, which is kind of non-sensical if you think about it. If Foo needs to be a singleton, just put the logic directly into Foo, and put the implementation into the cpp file.

As an aside, I find that singletons are almost never a good idea. They kill testability for starters.
 
As an aside, I find that singletons are almost never a good idea. They kill testability for starters.

They're good for quick and dirty global state management, but, past the rapid prototyping stage, you should be either passing a global state context as a parameter if your leaning more towards C-style coding or wrap your application in an object if your programming in C++ or really any object oriented language.

They're also good for enhancing performance in situations where a lot of a similar object are being created by separate actors (things like formatter objects ).
 
They're good for quick and dirty global state management, but, past the rapid prototyping stage, you should be either passing a global state context as a parameter if your leaning more towards C-style coding or wrap your application in an object if your programming in C++ or really any object oriented language.

They're also good for enhancing performance in situations where a lot of a similar object are being created by separate actors (things like formatter objects ).

Can you elaborate on the performance thing? Maybe a code sample illustrating how they increase performance?
 

Makai

Member
Rust is awesome. I've been doing engine programming in it for a few weeks and now it feels like the One True Language. Encouraging my job to switch from C#/Unity to Rust/OpenGL. :D
 

hateradio

The Most Dangerous Yes Man
Probably a tiny bit OT, but probably not as this this is probably common here.


I may be going to San Jose, anyone who lives there or nearby interested in PMing me or just posting your opinions about the place and what to expect?

I live in LA. :/
 
Probably a tiny bit OT, but probably not as this this is probably common here.


I may be going to San Jose, anyone who lives there or nearby interested in PMing me or just posting your opinions about the place and what to expect?

I live in LA. :/

What kind of opinions? Having to do with programming somehow? Job market related? I live in SJ but not sure what you're looking for
 

vypek

Member
I want to become a talented software developer/engineer and while I feel I am learning a lot at my job I also feel like I'm still an awful programmer. What are ways to really improve a lot? Just keep doing some random practice problems? I feel like I don't really know anything and at this point I'm not even sure how I got my Bachelor's
 

Somnid

Member
Being fluent in haskell must be rad. Like, get a interview question, write 3 lines and drop the mic. At least that's how I imagine it.
 

Makai

Member
Being fluent in haskell must be rad. Like, get a interview question, write 3 lines and drop the mic. At least that's how I imagine it.
More like the junior programmer that interviews you and has no ifea what that is. Assumes it's not rock solid because there's no ISortable interface
 

JesseZao

Member
I want to become a talented software developer/engineer and while I feel I am learning a lot at my job I also feel like I'm still an awful programmer. What are ways to really improve a lot? Just keep doing some random practice problems? I feel like I don't really know anything and at this point I'm not even sure how I got my Bachelor's

Practice on your own time. Seek out books and/or tutorials. Go to local meetups. Don't be afraid of failure, keep pushing yourself to try new things. Etc, etc.
 

Makai

Member
I want to become a talented software developer/engineer and while I feel I am learning a lot at my job I also feel like I'm still an awful programmer. What are ways to really improve a lot? Just keep doing some random practice problems? I feel like I don't really know anything and at this point I'm not even sure how I got my Bachelor's
Learn something nobody else knows. My recomendation: www.learnyouahaskell.com
 

Kalnos

Banned
Rust is awesome. I've been doing engine programming in it for a few weeks and now it feels like the One True Language. Encouraging my job to switch from C#/Unity to Rust/OpenGL. :D

Why Rust vs C++ (or even just C#) just out of curiosity? I'm guessing it comes down to ease of use but I'm curious as to what features make Rust more appealing than years of C++ examples, materials, libraries, etc.

I do love the small size of the language and Cargo from what I have seen.
 

Somnid

Member
Why Rust vs C++ just out of curiosity? I'm guessing it comes down to ease of use but I'm curious as to what features make Rust more appealing than years of C++ examples, materials, libraries, etc.

I do love the small size of the language and Cargo from what I have seen.

Rust is just as fast, but it's more modern, and has complete memory safety. Basically if it compiles it's practically bulletproof. Cargo and crates.io are awesome and the community is pretty awesome too.
 

Rear Window

Neo Member
Thanks Slo, great advice and you're right that I shouldn't rush into a decision. I'm lucky in the sense that for a long while now (since the start of the decline) I've been following FI blogs like MMM and have managed to build up a bit of a buffer.

This has been a long time coming for me tbh, but going back to the language I used to love and still hating it has made me realise I'm just not cut out for it any more :(

I'm still hoping to do a little bit of work and programming from home, maybe even enough to maintain our pretty modest lifestyle - though the way I feel right now I never want to see another line of code again x_x

I've been feeling the same way for a few years now. Been doing it professionally since shortly after the tech bubble burst. For me at least, I think it came down to what I was developing. I simply cannot stand doing anything web related anymore. Front-end or back-end, it is all stupid and I hate it. All the same crap over and over again with a "new" coat of paint which ends up just being an abstraction over what you were doing before. More pain when your site has to be IE compatible. Not just one browser but you have to test with 8, 9, 10, 11. Jeez. Sucks that that's where 90% of the jobs are.

I've turned to Unity development recently and am a lot happier. Things that are actually new to me. It may not be programming you are tired of but what you are programming.

Going into management is another option for you.
 

Makai

Member
Why Rust vs C++ (or even just C#) just out of curiosity? I'm guessing it comes down to ease of use but I'm curious as to what features make Rust more appealing than years of C++ examples, materials, libraries, etc.

I do love the small size of the language and Cargo from what I have seen.
Rust has most of my favorite features including tuples, options, unions, and pattern matching. But it also has a unique memory model that guarantees several classes of bugs won't happen. No explicit memory management - malloc and free are inserted by the compiler without the hit of a garbage collector or reference counter.

https://doc.rust-lang.org/book/ownership.html

Unity is good for hobbyists/prototyping but leads to atrocities of software engineering when used for "serious" development. And it uses the almost decade outdated C# 3 - but even the upcoming C# 7 release would feel outdated. At my work we have handspun native plugins embedded in our Unity project, which itself is embedded in "native" Android/iOS projects. And then I hit build and it spits out 80mb of source (millions of lines of C++). Convinced now that just doing everything natively is easier/safer.
 

hateradio

The Most Dangerous Yes Man
What kind of opinions? Having to do with programming somehow? Job market related? I live in SJ but not sure what you're looking for
Like is it a fun place to live. What's cool about it, what sucks about it. I mean I'm coming from LA where everything is, so I just want to know what to expect.

I know SF is like an hour north, and I'll probably check it out once in a while.
 
Man I am about to graduate in couple of semester and most intern jobs I see are for JavaScript. Is there really a high demand for it? So far I mostly know c++ and java.
 

Slo

Member
Man I am about to graduate in couple of semester and most intern jobs I see are for JavaScript. Is there really a high demand for it? So far I mostly know c++ and java.

Yes it's in high demand, and it's a nice compliment to have for a Java/C++ guy. Take a class on Udemy. Look for one that'll focus on Node.js and/or some jQuery.

Yeah I am gonna start learning JavaScript this winter break. Since I am already proficient with c++ and java i can pick up the basics fast I hope.

You should pick it up fairly quickly. The biggest difference is that it's a weakly typed language, unlike Java/C++. Google "dependency injection" to give you some idea of how the whole system comes together.
 

Gaaraz

Member
I've been feeling the same way for a few years now. Been doing it professionally since shortly after the tech bubble burst. For me at least, I think it came down to what I was developing. I simply cannot stand doing anything web related anymore. Front-end or back-end, it is all stupid and I hate it. All the same crap over and over again with a "new" coat of paint which ends up just being an abstraction over what you were doing before. More pain when your site has to be IE compatible. Not just one browser but you have to test with 8, 9, 10, 11. Jeez. Sucks that that's where 90% of the jobs are.

I've turned to Unity development recently and am a lot happier. Things that are actually new to me. It may not be programming you are tired of but what you are programming.

Going into management is another option for you.
Ah, I'm really glad you're enjoying Unity a bit more than what you were working on previously :)

You're right that different things may appeal to different people, I think I've pretty much settled on the idea that I like working within my comfort zone, but I only enjoy writing and working on my own code, I find having to deal with other people's code frustrating rather than rewarding. I know that makes me pretty much unemployable, but eh, I'm happy that I've finally figured out what makes me really enjoy some projects I've worked on, and hate others.
 
Thanks for the advice, both of you :)

I definitely recommend learning Haskell. Even if you don't use it at your job or in side projects it will make you think differently and write safer code.

Learn You A Haskell though may not be the best resource though.

Here's an analysis of a couple different resource you could use if you wanted to learn Haskell.
With pros and cons listed.
http://bitemyapp.com/posts/2014-12-31-functional-education.html
 

Koren

Member
Anyone ever taken a stab at creating their own language?
Well, a couple, if only to train with L&Y (several stupid/toy ones, too).

Though beside learning/teaching, there's no real point behind this (although I'd be interested in a D/Python mix), and it's awfully difficult to do it right.
 
Guys I have to learn ruby on rails for work. So I bought a course from udemy and they recommend cloud 9 for IDE, but it seems to me that they ask for a credit card info even for the free version. Don't feel comfortable giving my credit info for a free version. Is it ok to give cloud 9 my credit info? I just hope i don't get unwanted charges on my card lol.
 
Guys I have to learn ruby on rails for work. So I bought a course from udemy and they recommend cloud 9 for IDE, but it seems to me that they ask for a credit card info even for the free version. Don't feel comfortable giving my credit info for a free version. Is it ok to give cloud 9 my credit info? I just hope i don't get unwanted charges on my card lol.

Using Cloud 9 is not necessary, most tutorials use it because it lets the teacher skip the install process and get straight to the code. If your using this for work it might behoove you to know how to set up your own environment. Either on Linux or a mac (most go with a mac).

As far as features provided by Cloud 9, they are pretty bare bones. Not worth it when you compare the features provided by Rubymine. Cloud 9 doesn't really go beyond a simple text editor with a Ubuntu environment set up behind it.

If you just want to know whether Cloud 9 is safe and they won't sell your credit card to the black market, then the answer is yes, they are safe.
 

balgajo

Member
Alright this is one of the cases that I suspected. In theory this is supposed to work (on Linux anyway, but not necessarily on Windows), but declaring function local statics inside of a header file is a really bad idea because there are some *really* subtle rules about when it's supposed to work and when it's not. In this case I'm pretty sure it's supposed to work, but given how ugly this part of the language is, I would advise using a different approach.

What's *supposed* to happen is that the function local static is supposed to get a unique mangling, COMDATted, and then when these shared libraries load it's supposed to resolve the symbol based on the mangling so that only a single copy of it is being used. Note that on Windows this isn't the case, multiple DLLs (i.e. shared libraries) that included this header would be guaranteed to get a separate instance of the static.

If you're using an old compiler, it's possible this isn't working. Or there could be something else going on.

If you want to delve into this deeper, you could use a tool like nm to display the symbols in each .so file and verify that they have unique names.

On the other hand, I would probably just implement singleton-ness at the class level. Do you really need it to be this generic? You could make a Singleton<int> using this class, which is kind of non-sensical if you think about it. If Foo needs to be a singleton, just put the logic directly into Foo, and put the implementation into the cpp file.

As an aside, I find that singletons are almost never a good idea. They kill testability for starters.

I wanted a way to create a singleton without needing to declare an instance method in each class. But in the end I came back to the old manner. Also, from nm, I was getting different symbols in each shared object. I think that makes sense because it generated a template instance for each shared obj compilation. Thanks!

About Rust, how is the community? I was interested on it sometime ago.
 
I wanted a way to create a singleton without needing to declare an instance method in each class. But in the end I came back to the old manner. Also, from nm, I was getting different symbols in each shared object. I think that makes sense because it generated a template instance for each shared obj compilation. Thanks!

Still, the loader is supposed to figure this out at runtime. It looks at the mangled name of the symbols in each shared library, figures out they're the same, then merges all of them into one.

So either the symbols in each shared library had *different* mangled names in which case you'd want to figure out why that is the case, or they had the same name, in which case the loader isn't doing what it's supposed to do (perhaps a bug with how the linker is COMDATing the symbols?)

In any case, sounds like you worked around this problem anyway
 

Kansoku

Member
About Rust, how is the community? I was interested on it sometime ago.

From what I've seen, the community is great. Started learning a couple of days ago, and it has been great following /r/Rust, and all the stuff people are doing (like 24 days of Rust).
 

Mr.Mike

Member
Pretty much everything about Rust seems way better than C++ except the availability of libraries. The language itself is really nice, but the main thing that appeals to me actually is Cargo, and that's definitely way better than what's going on with C/C++. It's actually kinda crazy how terrible the package management situation around one of the dominant programming languages is.

Rust can do C FFI, but it seems like you'd quickly start to lose a lot of what's great about Rust having to work with C libraries.
 

Somnid

Member
Rust community is great. They actually have people designated for community outreach, trying to figure out how people use rust, who uses rust, what the pain points are. One of their goals is trying to build a non-elitist community that's very friendly to newcomers and first-time contributors.
 

Koren

Member
Pretty much everything about Rust seems way better than C++ except the availability of libraries.
That's waht I thought about D a LOOOONG time ago.

Unfortunately, that's often the main issue with C++ replacements. Rust may have a higher chance than D, though.

I still really like D :/

It's actually kinda crazy how terrible the package management situation around one of the dominant programming languages is.
Indeed.

At least, when we get modules, that'll help a bit, I hope.


At the same time, I went from "hey, it's nice" to "what is this pile of shit" for Python modules ;)

From the version conflicts to the wheels that avoid things that don't compile, and across X server rebooting when you type "help()" in python because a module doesn't follow the rules, and not taking into account all the security concerns with pip...
 

Mr.Mike

Member
Also maybe when a bunch of libraries are prefixing every single function with some sort of initial it's time to consider implementing some sort of namespace (other than prefixing every name). Though I do appreciate how little there is to C compared to what C++ has become.
 

Kansoku

Member
The problem with Rust packages right now is that some (big) packages require the nightly version, but that should be mostly solved when 1.15 lands with macros "1.1".

There is also some discoverability issues with Cargo, in that there are a bunch of abandoned crates up top.

But yeah, the language is pretty new, and it had some major changes with 1.0, so I expect the library situation to get better the following years. The community is pretty active, almost everyday there's a new lib popping up.
 

Makai

Member
I know this is crazy but my money's on Jon Blow's Jai to replace C++. It can beat C for performance if it's easy to make cache-friendly code. He already got it to compile instantly.
 
I know this is crazy but my money's on Jon Blow's Jai to replace C++. It can beat C for performance if it's easy to make cache-friendly code. He already got it to compile instantly.

As with every other language that's ever been touted as being a C++ killer, it doesn't matter how good the language is on its own merits, it could be better than C++ in every possible way. It could be easier to write, produce safer code, produce faster code, have more features, interoperate with more languages, and it still wouldn't replace C++.

All of these languages coming out now are great, but they're coming out at the wrong time. The only thing that's going to replace C++ is time. 20 years from now someone will come along and develop a new language that might not even be better than the languages of today, but the important thing is that it will hit at a time when C++ usage has been on a slow decline for years, and possibly even decades, making the market ripe for a replacement.

The world isn't ready for a C++ replacement yet. There is too much mission critical software dependent on it, too much library code written in it, and too much industry weight behind it.

If a new language comes along and does X, Y, and Z better than C++, then the standards committee will adopt X, Y, and Z for inclusion in C++ 10 years from now, which is not long enough for the new language to make a significant dent in C++'s market share, and even if it does X, Y, and Z worse than those languages, it'll be good enough for the maintainers of the trillions of lines of existing C++ code to not put significant effort towards switching.
 

Koren

Member
The world isn't ready for a C++ replacement yet. There is too much mission critical software dependent on it, too much library code written in it, and too much industry weight behind it.
I'm thinking the same, too. C++ will be replaced when we'll look for an alternative, not when an alternative is available. Better languages (keeping the same advantages) are already available, even if they don't have the manpower behind them..

If a new language comes along and does X, Y, and Z better than C++, then the standards committee will adopt X, Y, and Z for inclusion in C++ 10 years from now, which is not long enough for the new language to make a significant dent in C++'s market share, and even if it does X, Y, and Z worse than those languages, it'll be good enough for the maintainers of the trillions of lines of existing C++ code to not put significant effort towards switching.
Probably, although each time C++ "eats" such a new feature, its syntax becomes uglier. When you add grammar special rules to deal with grammar conflicts, you know it's getting bad.

That being said, I think that, when C++ will be replaced, in 15, 30 years, it still may be by a language appearing now. The moment languages gain momentum doesn't have much in common with the moment it's created. And in any case, each time people create C++ replacement, they come with interesting ideas that could (will) be a basis for the replacement.
 

Mr.Mike

Member
https://rocket.rs/

There's also a non-zero chance that Rust finds a niche as a language for web development. Probably not usually as the main language of a backend, but we are seeing it be used to replace C where C is used to make performance bound parts of software faster, while the rest is still Python/Ruby/JavaScript. And using Rust from Python/Ruby/JavaScript is actually really easy.
 

Makai

Member
https://rocket.rs/

There's also a non-zero chance that Rust finds a niche as a language for web development. Probably not usually as the main language of a backend, but we are seeing it be used to replace C where C is used to make performance bound parts of software faster, while the rest is still Python/Ruby/JavaScript. And using Rust from Python/Ruby/JavaScript is actually really easy.
I think that's Go's niche. Enormous growth in Go this year while C is in large decline - at least according to Tiobe.
 

Somnid

Member
The replacement phase is now, I think. Systems are so massive that large C++ codebases are just leaking ships, they'll never be able to seal all of the memory leaks, buffer overflows and threading issues. Basically when you hit a certain scale, you can't just trust tooling and code reviews to save you because those 1 in a billion edge cases happen too frequently, you need mathematically provable models. cpp_is_king is right that those codebases are just too big to throw out but now that we are seeing viable replacements in the system-programming space, new projects are going to reach for C++ less frequently and new devs are less likely to learn it as a primary language.
 
Top Bottom