[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 69 KB, 1200x1349, 1200px-ISO_C++_Logo.svg.png [View same] [iqdb] [saucenao] [google]
9766783 No.9766783 [Reply] [Original]

What's the best book to get a basic understanding of C++ for f.i. scientific computing? I'm asking here cause programming books are fucking memes most of the time. I'm not looking for a book that has "funny" illustrations or quips.

>> No.9766828
File: 437 KB, 512x683, 1527101402086.png [View same] [iqdb] [saucenao] [google]
9766828

im about halfway through sams teach yourself c++ in one hour a day. its pretty good. no funny bullshit

>> No.9766836

Stroustrup - Programming: Principles and Practice Using C++

>> No.9766840

>>9766783
No one uses C++ for scientific computing, don't bother.

>> No.9766848

Numerical Recipes in C++: The Art of Scientific Computing

>> No.9767151

>>9766840
C is master race

>> No.9767190

>>9767151
No one uses C for scientific computing either

>> No.9767191

>>9767151
When I was younger I used to shit C,thinking it was retarded for not being able to use OOP like C++. As I got older I realized if you want to do anything regarding microcontrollers, C is the only way to go.

>> No.9767200

>>9767191
You can practice OOP with C if you kno OOP and C well enough. C is master race. Besides, most Algol-based popular languages are derived from C.

Pretty much anything mission critical is written in C. The Mars Rover operates because millions of lines of C.

C master race.

>> No.9767207

>>9767190
They use slower meme languages like Python because it’s easy for researchers to learn. You could scientific compute with C if you wanted but it’d be more involved and would require a lot of time.

>> No.9767215

>>9766840
>>9767190
Not sure if troll or serious. Both C and C++ are widely used in scientific computing.

>> No.9767223

>>9767191
microcontrollers will be dead soon, everyone is switching to 32 processors or higher

>> No.9767228

>>9767223
And tell me sir, what language is used to write firmware? C, master race.

>> No.9767247

>>9767215
Maybe in 1995, not now.

>> No.9767259

>>9767247
Wrong. They are still used.

>> No.9767267

>>9767259
No they aren't

>> No.9767268

honest answer: youtube tutorials ... thats how i did it

>> No.9767300

>>9767267
Yes, they are. Fuckin christ

>> No.9767309

>>9767300
Repeating it won't make it true

>> No.9767323

>>9767309
Repeating it won’t make you right

>> No.9767353

>>9767267
even fortran is still used, some research groups simply refuse to rewrite thousands of lines of proved programs into other languages.

python is used to do quicker calculations and graphing etc when mathematica isn't enough.
for high level, i've seen C and C++ being used, C++ being preferred heavily.

t. particle physicist phd.
oh, we also used ROOT from cern, but that's specific to this area.

>> No.9767381

>>9767309
SEE. Told you. Dumbfuck

>> No.9767386

>>9767353
Legacy code doesn't count

>> No.9767387

>>9767353
>even fortran is still used
yup. CFD is all fortran shit.

>> No.9767403

>>9766783
This >>9766848

But also the only way to learn is to write code yourself. Start a project or find something to contribute to on Github.

>>9766840
Tons of HPC libraries are in C++

>> No.9767434
File: 42 KB, 600x600, 1509776446788.jpg [View same] [iqdb] [saucenao] [google]
9767434

>>9767247
>>9767267
>>9767309
>>9766840

>My prof only uses Python and R, so that must be what people use in industry! Obviously not C or C++!

Brainlets are getting more and more sure of themselves these days.

>> No.9767437

>>9767434
I'm in the industry though and it's 99% Python

>> No.9767453

>>9767437
>and it's 99% Python
waiting on a source for that.

>> No.9767455

>>9767453
My employer's codebase

>> No.9767461

>>9767455
>my employer's codebase is the whole industry!
sure, even if that was true, how's that relevant to science research?

>> No.9767478

>>9767455
sorry man but you're actually a retard. tons of R&D sectors utilize C++. The F22 raptor and F35 were programmed in C++. Would the military be a more reliable source than your employer? what do you think?

>> No.9767687

>>9767478
C/C++ is used heavily in industry. Not even arguable.

>> No.9768148
File: 2.71 MB, 1861x1760, c++ programming starter pack.png [View same] [iqdb] [saucenao] [google]
9768148

>>9766783

>> No.9768304

>>9767191
Noob question, but why wouldn't you use C++ instead of C in general, but also for microcontrollers? The way I see it, C++ is just C with OOP support, but then again I'm just a noob.

>> No.9768324

>>9768304
because cargo cult programming.

>> No.9768964

>>9768304

Here's an analogy.

It's like a woman that has a very tight shallow vagina.

Using C++ instead of C is like the woman having sex with a black man instead of a white man. The penis is just too big and overwhelming for her.

>> No.9768970

>>9768148
Why such a focus on MPI? Sure, it's the go-to for any sort of scientific/engineering parallel computing but it's useless for your average dev job/hobby programmer.

>> No.9768974

programming is a meme.

>> No.9769322

>>9767461

Why are you so defensive of C++?

Industry is python and R, mock it all you will but you're in for a shock if you actually believe that

>> No.9769325

>>9768970
Do you know where you are?

>> No.9769328

>>9769322

It depends on the region. In northeastern US, most employers want Java programmers.

>> No.9770164

Got some catching up to do here, thanks for the replies.

>> No.9770467

>>9766783
In regards to all the silly replies in here, I can shed some light on C++ in industry
C++ is used widely in industry for high performance scientific computing. Anytime that speed matters C++ will be used.
Typically, I prototype something in python on smaller datasets and make sure its working properly. Once I'm sure my algorithms are correct I write them in C++ and deploy that.
If you're only using python, you're most likely working on meme problems in industry, all your applications will be written in C++.

>> No.9770859

>>9770467
I'm very comfortable with both Python and R. Just looking to pick up some C++ just in case, what are the main things you're using C++ for?

>> No.9770967 [DELETED] 

>>9767247
Wtf are you on about faggot, C++ is used all the time in scientific computing and engineering. Python and R are getting pretty big but that doesn't discount C++.

>> No.9771316

>>9770467

Employers seem to expect knowledge of C++ but I don't think it actually gets used on a daily basis

What exactly are you using C++ for?

>> No.9771617

>>9770467
>>9771316
Python and R are used to dick around and look for patterns in datasets. Once it's been established that we can in-fact generate patterns, the next step is deploying an app or something on a server that people can access or use.
This part is written in C++ because its faster and allows much more control of memory etc.

Say I am Netflix and I've got a massive dataset of movies and users and I want to build a recommender system to recommend people movies they are likely to watch. First I take 0.001% of that dataset, and use python to build some machine learning models I think will work. After a while I discover that using matrix factorization works really well.
Now I want to actually recommend people movies, but python is slow and nobody wants to wait an hour to get their recommendations.
So we build a large decentralized system, and I write C++ code that executes a ton of operations in parallel and optimizes my matrix factorization to run on many machines quickly, I also write it so thousands of people can use my algorithm at once.
You cannot do that in python.
Essentially: Python to prototype and quickly solve problems, C++ to deploy solution and make it actually useful to others.
This is sci though, so most people here don't go past the 'solve problems' phase :)

>> No.9771625

LEARN RUST YOU STUPID FUCKING NIGGER.

>> No.9771630

>>9770859
>>9771316
Just saw you ask what exactly I use C++ for
A recent problem that was solved

Say you have several ioT devices sending you data about some state you're monitoring. The data is high dimensional and comes in every few milliseconds. The devices are shit quality and are guaranteed to produce outliers.
Thing is that the data is high dimensional and comes fast, so you don't have time to compare all the new data to see if its an outlier, also the state you're measuring changes so you're not sure if its outliers or just a state change.
This problem took a while and I solved it using some neat hashing algorithms, I did this part in python on simulated data.
Once it worked, only C++ could handle taking in data from multiple sources at once and reporting outliers quick enough to where the incoming data wouldn't build up and overfill memory.

>> No.9771642

>>9767247
even if you do simple prototyping in Python (the big fad now in industry) if you have any use case beyond the most basic boilerplate of library functions you will have to write some C (or something similarly "lower") and then bring it into your python code.

>> No.9771649

>>9771625
>>>/g/tfo

>> No.9771691

>>9771649
I'm a Mathematician though, just do software development on the side for money.
Why would I go to that shithole?

>> No.9772335 [DELETED] 

>>9766783
Bjarne Stroustrup's books are the best. /end thread.

>> No.9772339 [DELETED] 

>>9767200
The only thing you have that is similar to OOP are structs, so no not really.

>> No.9772342

>>9771625

Easy with those racial slurs internet warrior.

>> No.9772343 [DELETED] 

>>9767207
>Cython is not a thing.
brainlet.

>> No.9772344

>>9767200
t. pajeet

>> No.9772348 [DELETED] 

>>9768964
>C++ being versatile is a bad thing
have fun segfaulting schlomo.

>> No.9772354 [DELETED] 
File: 29 KB, 502x442, 15977595_120599858447390_6032570884158446514_n (2).jpg [View same] [iqdb] [saucenao] [google]
9772354

>>9771625
>falling for the rust is better than C++ meme

whose the nigger again? (you).

>> No.9772357

>>9772342
is this the new "why the homophobia"? or are you just a facebook tourist?

>> No.9772551

>>9766783
Stroustup. C++ isn't something you just pick up. If you want to do something non-trivial with it, you need to go balls deep.

Stroustup's text has no peers. Literally everything you need to know about the language.

>> No.9772562

>>9772343
Not person you're replying to but I don't think you understand what Cpython is.
CPython does not translate your Python code to C by itself. It instead runs a interpreter loop, which is orders of magnitude slower.
C++ is faster because you have control over memory layout, allocation, and of course because it compiles to native code.

>> No.9772576

>>9767207
There are quite a few robust Scientific and Numerical packages for C, but okay bud.

So sick of the Python meme. Under the hood, Numpy and it's relatives are straight up C. If you know what you're doing and what tools to use, Python is fine.

You should spend less time parroting HackerNews comments and more time doing literally anything else.

>> No.9772586

>>9772576
Python isn't a meme, it's just too slow for deploying tools. It's great for research.
No language is superior to the other, they just all have different flaws.

>> No.9772882

>>9772562
Exceptionally brainlet post

>> No.9772918
File: 32 KB, 336x420, Ivor-Horton’s-Beginning-Visual-C-2013-336x420[1].jpg [View same] [iqdb] [saucenao] [google]
9772918

>>9766783

>> No.9772924

>>9766783
>C++
Learn C

>> No.9773002

>>9772918
>Visual C++
Turbo C++ (and Turbo Pascal, for that matter) were much better. Such a comfy interface.

>> No.9773020

>>9766840
Kek.
Scientific programming involves usually the following: C/C++, FORTRAN, Python, R, IDL and the occasional dab in Matlab.

Also, it's not like you have a choice.

>Hey dude, welcome to our research group. You'll be working on this earth system model that we've been developing for the last 25 years. Most of the 120k lines of code is in F77, but some postdoc started writing modules in F90. Also, there's a couple of extensions some summer student once wrote in C, but we don't know how that works. Also, Jeff spent his PhD refining the soil chemistry, but he did it in Ruby, and he used Portuguese cartoon characters as inspiration for variable names. But that's OK since Mary wrote some wrapper in C++ to deal with that. But they're both gone and none of that is documented. We expect a paper from you in 8 months. Enjoy!

Just kill me.

>> No.9773021

>>9767191
I work on micro controllers and use cpp extensively. You have to be a fool to under value the years of software development and the efficiencies that higher level languages bring.


The entire application layer of the microcontroller can be simulated on a pc, allowing me to run about 1000 tests cases I've written for it, covering almost every weird situation the device could ever face.

The hardware code is then also tested the same way, in isolation, with hundreds of tests, taking about an hour to run.

And because of oop and the ability to separate code into useful blocks, I've had the quickest development time and most stable product my work has ever done.

Only a fool would think cpp has nothing to offer embedded systems, and to ignore 20+ years of software best practices.

>> No.9773084

>>9771617
>>9771630
Thanks!

>> No.9773933

>>9772357

This is /sci/, not /pol/. Fuck off if you have a problem with our no racism policy.

>> No.9773943

>Amerifats still have to use C/C++
top fucking kek, in Europe we have good enough computers that the computation time difference between C/C++ and Python is negligible

>> No.9773951

>>9773021
>And because of oop and the ability to separate code into useful blocks
Seeing how all of your other points have nothing to do with oop, What makes you think you can't do this in C?

>> No.9773959

>>9772339
Tell me, anon, what do you think the difference is between a class and a struct?

>> No.9773969

>>9768304
C++ compiles slower (issue if you're compiling in-place, like a Raspberry Pi), and yields larger binaries (bad, because embedded systems usually have smaller caches).

>> No.9773976

>>9771630
Wouldn't it have been easier to just develop straight in C++ and skip Python?

>> No.9773991

>>9773943
We live in defferent Europes, then. You stay where you are for the time being, alright?

>> No.9773992 [DELETED] 

>>9772562
>Not person you're replying to but I don't think you understand what Cpython is.
CPython does not translate your Python code to C by itself.

I never said this.

>It instead runs a interpreter loop, which is orders of magnitude slower.
C++ is faster because you have control over memory layout, allocation, and of course because it compiles to native code.

Lol, citation needed.

>> No.9773997

>>9773976
Nah.

Let me tell you why. Let's say someone gives you big fat dataset and tasks you with developing whatever scheme to do some real-time classification for whatever is in there. With Python, I can fire up an interactive shell, query and read some HDF/netCDF/whatever structured binary file in a single line. Doing that alone in C++ would take dozens of lines at least and a compilation process. Now reading the data in is as quick as mydata = h5py.File('dildo_sales.hdf', 'r')['consumers'][:]. Then, you start looking at the data, plot some graphs, histograms whatever (quickly done with something like seaborn, matplotlib, etc.). Load up the packages to do your statistical analysis, like pandas, statsmodels, scipy, .., and go to town.

With Python, you'll be able to go at it within minutes of receiving the data, while with C++ you probably would not have managed to read the data out.

Once you're satisfied with your classification scheme, just write it up in C++ for performance, badabing-badadoom, next job please. Python drastically reduces development time at the cost of execution performance.

>> No.9773999 [DELETED] 

>>9773959
With classes I can create subclasses that will inherit its parent's properties and methods, classes are created private by default, structs aren't.

>> No.9774016

>>9773991
I'll stay in Switzerland at the top school in Europe, you can stay in your shithole

>> No.9774028

first look for what job you are trying to do
then pick the right tool for the job
I doubt you need to use C++ for what you're doing
you probably just heard it was heard to learn and fast or something so learning it makes you a badass
it doesn't
it makes you a faggot
someone who isn't a tard will pick the right tool and do the job in a quicker time and finish the job

C++
nigger please

>> No.9774029

>>9774028
>>>/g/tfo

>> No.9774032

>>9773999
>With classes I can create subclasses that will inherit its parent's properties and methods
Can be done by struct containing a struct, or with the -fms-extensions flag.

>classes are created private by default, structs aren't.
This is kind of the right answer. Really the only main difference between class and struct is the privilege system, which AFAIK is not necessary for oop.

>>9773997
>Once you're satisfied with your classification scheme, just write it up in C++ for performance
This is what I don't understand. You need to write the C++ part anyway. What do you mean by classification scheme? What does Python yield to you? The numerical limits along which you classify?

>> No.9774043

>>9774016
>school
So you want a research playbox. Sure, such tools are needed. However, when you want a computation done en masse, you want it do be done as quickly as possible.

>> No.9774044

>>9774029
blow me college boy
wanna be lil bish

>> No.9774047

go to school at a real uni and get some time on the supercomputer and just write the shit in Python

>> No.9774052

>>9774032
>What do you mean by classification scheme?
That was just an example. Replace it by whatever task you see fit.

>What does Python yield to you?
Massively reduced development time, as I can do certain things in a single line which otherwise would take me half a day in C++. But don't take my word for it. See how long it takes you to run k-means clustering on whatever set of data in C++. In Python it's a matter of minutes.

>> No.9774057

lol get ready folks he's gunna learn it all in a weekend and understand templates and iterators and all the rest of the bullshit lickedy split
despite not even understanding the basics of OOP
but never fear everyone here is just a temporarily embarrassed Oppenheimer so it's totally realistic

>> No.9774062

>>9774043
>However, when you want a computation done en masse, you want it do be done as quickly as possible.
The best way to do this is to spend a few thousand dollars on EC2 instead of wasting a week or more of valuable programmer time

>> No.9774064

>>9774052
>That was just an example. Replace it by whatever task you see fit.
I can't replace it because I fundamentally did not understand what you were talking about.

>k-means clustering on whatever set of data in C++
But if you needed to implement k-means clustering in C++ anyway, what's the difference?

>> No.9774065

>>9774052
>Massively reduced development time, as I can do certain things in a single line which otherwise would take me half a day in C++.
The complete opposite statement holds true for me.

>> No.9774072

>>9773943
>time difference between C/C++ and Python is negligible
That's the function of the software, not the hardware.

>> No.9774085

>>9774064
>But if you needed to implement k-means clustering in C++ anyway, what's the difference?

By the time you've managed to write the C++ implementation, I have fully tested the k-means approach, figured out whether it's the right tool, and have tried about 10 other approaches to see if they work better.

>> No.9774088

>>9766783
>I'm a big boy! I only read big boy books! If they have any jokes or humour then they are not for me, because I'm a big boy!!

pseud

>> No.9774095
File: 24 KB, 602x450, 1445101518686.jpg [View same] [iqdb] [saucenao] [google]
9774095

>>9774085
Oh, NOW I see. Thanks.
It's just that I thought of this as "figuring out what needs to be done", and not "rapid prototyping" or whatever. Just semantics, I guess, but it confused me.

>> No.9774189

>>9769322
There's nothing wrong with Python and R, but their utility is in easy of use, not efficiency. It would be very odd for any computationally intensive task to be done entirely in Python. That being said, a lot of programs use python to interface with C, C++ code. Blender is one good example.

>> No.9774194

>>9771625
The problem with RUST is no one uses it, this will never be solved, just learn C++.

>> No.9774203

>>9774057
You can do scientific computing with only a rudimentary understanding of C++. I don't think the OP expects to learn everything in a weekend, they just want to know where to start do that they can get up and running as quickly as possible.

>> No.9774216

>>9766783
>Not using Forth

>> No.9774228 [DELETED] 

>>9774032
>This is kind of the right answer. Really the only main difference between class and struct is the privilege system, which AFAIK is not necessary for oop.

No, that's not everything, you pass by reference with a class, whereas with a struct you are passing by copy. The way they are stored is also entirely different (heap vs stack space).

>> No.9774248 [DELETED] 

>>9774032
>Can be done by struct containing a struct, or with the -fms-extensions flag.

First of all, why would you do that instead of using an OOP language, second of all what if I have multiple methods, instances of different objects ect.. in that class? The fact of the matter is OOP and Functional programming are two different paradigms designed for different problems.

>> No.9775023

>>9773020
I'm sorry.