[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
It's been a while since I've posted here. Ask a C++
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 59
Thread images: 2
File: cpp-logo-dribbble_1x.png (18 KB, 400x300) Image search: [Google]
cpp-logo-dribbble_1x.png
18 KB, 400x300
It's been a while since I've posted here.

Ask a C++ developer anything. Just farting around before work tomorrow.
>>
>>55628011
Why haven't you killed yourself yet?
>>
What's the biggest program you made or contributed to?

Do you like templates? If yes why?
>>
>>55628018
Life's alright. Not great, but good enough to keep on keepin on.
>>
>>55628011
What are some languages I should learn so I have a chance at getting a job in the future?
>>
>>55628030
>What's the biggest program you made or contributed to?

Nothing OSS. PRoject at work

>Do you like templates? If yes why?

Situational. They can be very powerful and very useful sometimes.

>>55628047

Don't focus on the language, focus on understanding how to program... If you do want to focus on the language, then it depends on what kind of job you want.
>>
>>55628011

I havent written any c++ in the past 10 years, so my question is... are exceptions in c++ still the complete abortion they always were?
>>
Is it true that node.js is the best thing ever ?
>>
>>55628071
Can you give the magnitude of your project. Because where I work they have this huge C++ codebase which is unmaintanable (we are only 3 guys)...

You have any idea how to convince the managment we need more people?

>Situational. They can be very powerful and very useful sometimes.
I hate them. There is nothing worse then a badly written template by someone else that triples the compile time.
>>
>>55628071
I'm not really interested in any job in particular as long as I'm not a games company code monkey. Maybe something I can take overseas to Japan or whatever. and yes, I know I'm not going to make it in Japan, but it doesn't hurt to dream.
>>
>>55628121
>You have any idea how to convince the managment we need more people?

Depends on the context. Do you have a project mgmt schedule? or are you using a process like scrum?

How you answer that determines how I would answer your question.

>badly written template

Well yeah, badly written anything sucks, doesnt mean you should toss that bit of the language otherwise you'd be left with nothing, people can write shit in anything.
>>
>>55628091
Yes.

>>55628121
Humongous - ~400 people work on it.

>You have any idea how to convince the managment we need more people?

It's not necessarily in their best interest. Until shit starts being entirely broken in production, it's not that importnat.
>>
>>55628160
>>55628172
We have a project schedule yeah.

Well it is in their best interest, they dont realize that everything just barely works and if anything goes wrong the company will not be able to do anything during atleast a couple of days.
The standard answer of the management is: "That's why we have hired you".
>>
>>55628172
>broken in production, it's not that importnat.

Interesting, so the way to get more people is to let it break in production?
>>
do you think the 2003 invasion of iraq was a mistake?
>>
>>55628214
>We have a project schedule yeah.

Ok then, well in that case show them how much the schedule will slip by if they dont hire more people.
>>
Thanks for doing this. I am very interested in focusing on c++. I have many questions so I'll might samefag in this thread.

How should one best learn things like using overloaded and bitwise operators?

Since vectors are a thing, should they always be used instead of arrays because of the member functions within vector library?

Sometimes when I seek online help, the code I encounter smacks me in the face with how little I know and retain about how to properly use libraries and templates.

Thanks again for taking your time in this thread
>>
>>55628011

In case you thought I was trolling about c++ exceptions, I was referring to this stuff...

www.octopull.co.uk/c++/dragons.html

is that sort of thing still required?
>>
>>55628258
>How should one best learn things like using overloaded and bitwise operators?

By implementing and using them.

>Since vectors are a thing, should they always be used instead of arrays because of the member functions within vector library?

Nope, use the right tools for the job.
>>
>>55628011
Do you use std::string ?
>>
>>55628278
Thanks.

Would you remember anything that you've learned during your more recent experiences that made you wish that you had known about such things before?
>>
>>55628214
>>55628218

In my experience, yeah. Break in prod or fall behind schedule.

>>55628221
I'm no politician.

>>55628258
Bitwise - intuition will really get you far. I mean, you shouldn't be doing hacky shit, you really don't need to use bitwise operators, but they're there if you need them.

Pretty much always use vectors until you know better.

It's a lot to learn. It'll be tough.

>>55628263
My company doesn't use exceptions - they are USUALLY relatively cheap with modern compilers.

>>55628281
No.
>>
>>55628298

wish i'd read this sooner...

Refactoring: Improving the Design of Existing Code by Martin Fowler
>>
>>55628310
>relatively cheap

Its not the cheapness that concerns me, its the amount of grief and pain you have to go thru to use them safely.
>>
How do you properly integrate errno with exceptions?

How often and when do you use exceptions?

Should I be making my own exception objects inheriting from std::except for every type of exception that can happen in my project, or should I just use std::runtime_error for everything?

Why don't you use std::string?
>>
How many years have you worked with C++?

What experience do you have with languages that are not C++?

What experience did you have prior to getting this job?

If this is not your first "coding" job, what experience did you have prior to getting your first job? (e.g. school, personal projects, past non-"coding"-related jobs)
>>
>>55628393
>its the amount of grief and pain you have to go thru to use them safely.
Elaborate please.
>>
>>55628424
>How do you properly integrate errno with exceptions?

Take a copy of it, store it in the exception.

>How often

Odd question, you use them when you need to.

>and when do you use exceptions?

When? Depends on the context. They introduce a lot of complexity in terms of coding and design so the pay off has to be worth it. But consider that unix itself was written without them.

>use std::runtime_error for everything

Everything? no. As appropriate? yes.
>>
>>55628442

Do you still need to do this stuff...

www.octopull.co.uk/c++/dragons.html
>>
>>55628481
I'm not OP, I was just asking why you think exceptions are painful, since I'm pretty new to them.
I'll read the link.
>>
I don't find pseudocode useful but my professor keeps pushing it. Is it a worthwhile skill to learn?
>>
>>55628495

>Not OP

No worries friendo. Its a scary link but thats why i'm trying to find out if you still need to do that stuff.
>>
>>55628011
What's the best way to learn C++?
>>
>>55628502

Sure, why not? Just think of it as another programming language.

Personally when I'm talking code with other programmers at the whiteboard we tend to use a mash of pseudocode, real code, booch clouds and uml fragments, its all good.
>>
>>55628393
I've avoided them in both personal and professional coding -- don't know the pain required to use them safely.

>>55628424
>How do you properly integrate errno with exceptions?
I don't use exceptions.

>How often and when do you use exceptions?
Sparingly, when traditional control flow doesn't make sense given the problem.

(Alternatively, use a monad-like class, and don't touch exceptions. See: https://github.com/google/lmctfy/blob/master/util/task/statusor.h )

>Should I be making my own exception objects inheriting from std::except for every type of exception that can happen in my project, or should I just use std::runtime_error for everything?
Honestly, not too sure. I don't use them, I know how to write them, but I don't know best practices.

>Why don't you use std::string?
Lots of missing optimizations, and many libraries have a ref-counted COW implementation of std::string, which is bad when dealing with code that needs to be deterministic in runtime, as there can be wonky performance hits in unexpected places.

>>55628502
Pseudocode is just writing down your thoughts. You can write pseudocode quicker than you can write perfect, ideal code. It's definitely got its uses.

>>55628510
Sorry man, I just don't know.

>>55628521
Time, personal projects, etc.

Take a class taught in C++ if you can.
>>
>>55628521

Learn c first, learn an oo language (eg, python, java, c#, swift) then after about 5 years or so take a look at c++
>>
>>55628531
>many libraries
Ugh. I meant to write "many compilers."
>>
>>55628531
>I've avoided them in both personal and professional coding -- don't know the pain required to use them safely.

Ok no worries. My apologies for hijacking your thread, i've answered a few questions too.

As to yourself, it seems like you're well on your way programming wise. If you havent already I'd recommend you start looking at software processes, like scrum,xp, crystal, kanban etc As you go up the tree you'll need them.
>>
>>55628564
>As to yourself, it seems like you're well on your way programming wise. If you havent already I'd recommend you start looking at software processes, like scrum,xp, crystal, kanban etc As you go up the tree you'll need them.

Not to date myself, but I'm pretty far developed in my career =).
>>
>>55628532
first I was told C++ is a language you should learn first. Now I'm told otherwise. What's the truth anon?
>>
>>55628608

c is a subset of c++, so in a sense you will be learning c++ too, just a bit of it.
>>
>>55628608
I'm not the guy in >>55628532 , I'm OP.

C++ isn't the right language to start out with for many people. It's one of the few languages where you need to manage your memory yourself. It's hard, and might distract from other things you might want to learn.

On the other hand, it's a great language (with a handful of warts from past-times). What do you want to do with programming? That best determines what language you should start with. For most, C++ isn't the best starter.

>>55628641
C is not a subset of C++. Off the top of my head, type punning and VLAs are valid in C, but either undefined behavior (type punning) or compilation errors (VLAs) in C++. C uses malloc / free, C++89 uses new / delete, C++11 and beyond avoid new / delete wherever permissible.
>>
>>55628655
>C++11 and beyond avoid new / delete wherever permissible.
Wait, so what do I use to get dynamic memory in C++11/14?
>>
>>55628011
What compiler/toolchain and OS do you use? Would you consider C++ to be the "best" language there is, or just the one you're stuck with?
>>
>>55628689
http://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique

It makes ownership very nice to understand and manage, and lifetimes easy to understand.

>>55628705
GCC and Clang. I work on an in-house version of Linux.

It's situational. For back-end / server development, I think C++ is the best. OS / drivers? C++ is great, but I understand motivations and reasons to use C. Quick scripts? Bash / python are going to get you far. High-level? I like Haskell, but I haven't written anything production ready yet. It's just fun to learn something drastically different.
>>
>>55628735
>http://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique
I'm having a hard time understanding where the object is actually stored.
Isn't it just calling new under the hood? what's the point them? why use this over new? what's it's advantages over new?
This is stupid.
>>
>>55628655

>C is not a subset of C++

sure, there are edge cases but from the point of view of a n00b, if the n00b writes some basic c he'll find that it compiles with a c++ compiler too. thats what i meant by subset.
>>
>>55628802
std::make_unique<T>(...) returns a std::unique_ptr<T>. The destructor of an std::unique_ptr<T> will deallocate memory automatically, call the appropriate destructor, etc.

It is far less error prone, you can't forget to deallocate. and it signifies ownership. What's also nice, is that you can still return std::unique_ptr<T> from a function, via std::move(...).
>>
>>55628835
I'm off to shower, I'll be back in a bit to answer some more questions before sleeping.
>>
What kind of overhead do smart pointers introduce?
>>
>>55628910

Not enuf for you to care about unless you're doing some seriously resource intensive stuff.

They just increment/decrement a count and then deallocate the memory for you when appropriate which you'd have to do anyway so really its just the increment/decrement.
>>
>>55628967
What about dereferencing?
Will most compilers inline the operator overload making the overhead almost zero?
>>
Back from my shower.

>>55628910 and >>55628980
Near nothing. When unique_ptr was introduced, it would often have the overhead of an additional pointer dereference. Nowadays, this isn't the case, and they are often a zero-cost abstraction.

N.B.: I've worked with code that (for some reason) the optimizer couldn't optimize away the additional pointer dereference, and since this was causing issues with data locality and associated cache misses, I elected to remove the unique_ptr. But that's really, really, really, really, really, rare.

>>55628967
>They just increment/decrement a count
shared_ptr (typically) has a refcount implementation. unique_ptr does not. I'm personally not a fan of shared_ptr, and it's avoided like the plague at my work. So I don't know what "count" you're referring to.
>>
>>55629138
And with that, it looks like I've killed the thread. I might visit it tomorrow morning if there are any more questions and the thread hasn't died, but if not, goodnight /g/. Have fun!
>>
>>55629138
>I don't know what "count" you're referring to.

the shared_ptr refcount. when someone says smart_ptr i assume they mean a reference counting one, that being the "smart" bit of it.
>>
What is your opinion of Unity?
>>
>>55628121
>Because where I work they have this huge C++ codebase which is unmaintanable (we are only 3 guys)...

are you me? fml.
>>
>>55628369
Thanks for the reference. Been reading this since you recommended it and I am finding it very useful to develop these habits as I learn.

for example:
>>Don't understand what someone else's code means? Refactor it!
Seems like a nice strategy
>>
>>55628011
Is having a c++ job worth pursuing if you like it?
Thread replies: 59
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.