• 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

Koren

Member
So as compile time, you could simply have whatever you want and the compiler would auto-decrement the constant in your array accesses anyway.
I agree, but since there's no many definitive reasons to start at 1 instead of 0, I'd say... Why bother?

As I am a local ML proponent, here is the same code in f#.

Code:
let rec someRecursiveHelper n acc =
    if n > 0 then acc
    else someRecursiveHelper (n-1) (acc+1)

let someRecursiveFunction n =
    someRecursiveHelper n 0
Out of curiosity (I need to dive more into F#), would this also be correct?

(Edit: I just noticed the > 0 instead of = 0, read too quickly, but I'm not sure I understand why it's > 0)
Code:
let rec someRecursiveHelper acc = function
  | 0 -> acc 
  | n -> someRecursiveHelper (acc+1) (n-1)

let someRecursiveFunction = someRecursiveHelper 0
 
I agree, but since there's no many definitive reasons to start at 1 instead of 0, I'd say... Why bother?
I actually prefer 1-indexed sequences and closed intervals. The reason is that I just think the nth element in a sequence should be indexed as n, not n-1. It's just... more... intuitive! And I also don't believe in array iteration by number, anyway. BCPL actually had a for-each construct and Ken Thompson removed it for simplicity in B. What a bad move! Arrays should have always been two words. Etc. As for the intervals, we clearly just need to range constructs. One which has a start and an end (closed interval). And another which has a closed start and how many elements you want in the sequence.

upfrom(3, 10) would range from 3 to 12. There are 10 elements in the sequence. My reasoning for this is that you always want either to know the start and end points, or you want to know how many elements are in the sequence. So have one for each!


Out of curiosity (I need to dive more into F#), would this also be correct?

(Edit: I just noticed the > 0 instead of = 0, read too quickly, but I'm not sure I understand why it's > 0)
Code:
let rec someRecursiveHelper acc = function
  | 0 -> acc 
  | n -> someRecursiveHelper (acc+1) (n-1)

let someRecursiveFunction = someRecursiveHelper 0
Yeah, that works, and the function keyword is handy. But nowadays I wish for SML's/Haskell's version of the same thing, which lets you match multiple arguments at once. Yes, I wrote it too fast and flipped my arms, btw. What I meant was

Code:
let rec f n acc =
    if n > 0 then f (n-1) (acc+1)
    else acc

The reason for the inequality is that it covers the negative case more gracefully and guards against nontermination. Yours will choke on negative numbers.

But maybe the right thing to do was to throw an exception, anyway.

By the way: do you actually teach exceptions in your class? Or do you prefer to emphasize algebraic datatypes?

Also, I agree. You need to dive more into F#! After learning more and more about the explicit details in the engineering of the .NET GC, and comparing it to other garbage collectors, I am convinced that people should let millions of dollars and decades of engineering handle the runtime; there's really no need to duplicate the work. I learned that GHC's garbage collector is not even incremental! Meaning collection of large working sets is always proportional to the size of the working set. Nuts if you have any kind of latency constraint. Anyway my point is that F# is a first class citizen ML (minus a module system) on one of the most well designed runtimes ever. And with .NET core, it's becoming less and less tied to Windows.
 

Koren

Member
I actually prefer 1-indexed sequences and closed intervals. The reason is that I just think the nth element in a sequence should be indexed as n, not n-1. It's just... more... intuitive!
Seems logical, but I must be too used to 0-indexed, because I'm having troubles with 1-indexed. I believe I associate now the index with an offset.

It's a mess with students each time I use arrays to describe mathematics objects, especially 2D arrays for matrices, though. "Normal" language is definitively 1-indexed.

What about changing normal language instead? ^_^

And I also don't believe in array iteration by number, anyway.
I also don't, but there's plently of cases where iterators don't work. Each case you couldn't use a list, in fact. For example, most divide-and-conquer algorithms. Also, when you have several tables where A and B are related, having a common index is really handy.

BCPL actually had a for-each construct and Ken Thompson removed it for simplicity in B. What a bad move!
At least, it's coming back on C++X11 ;)

we clearly just need to range constructs. One which has a start and an end (closed interval). And another which has a closed start and how many elements you want in the sequence.
I agree. In fact, I would even think we may do with a math-like notation. [0..2] and [0..2[ or [0..2) are not the same. Not sure how you could introduce it in a language without adding too much clutter/difficulties in the syntax, though.

I'm all for your upfrom (although in most languages it's an easy enough macro that can be added at the start of any program...)

I actually like what itertools provides in Python. Plently of interesting solutions to iterables. For example, you can do "upfrom(3,10)" by islice(count(3), 10)

But nowadays I wish for SML's/Haskell's version of the same thing, which lets you match multiple arguments at once.
Interesting... I'm also using fun in Caml a lot, and if it's not available alongside function, I guess I'll miss it. I guess you could always use uncurrified expressions, but that's less interesting.

The reason for the inequality is that it covers the negative case more gracefully and guards against nontermination. Yours will choke on negative numbers.
I'd probably write a
Code:
  | n when n>0 ->
  | _ ->
in Caml, anyway, but I need to look more into F# syntax...

But maybe the right thing to do was to throw an exception, anyway.
For 0 or for negatives?

By the way: do you actually teach exceptions in your class? Or do you prefer to emphasize algebraic datatypes?
That's... actually a hot question.

Short answer: I do...

It's not required as I understand it (I train students for recruitments in top engineering schools, so there's a national "list" of expected knowledge I have to stick to), but I think it's really useful, so I do it in ML classes (where I have students more interested in CS)

I usually don't in Python classes (which everyone attend in science). But at the same time, some people argue that we should only teach algorithmics, and we shouldn't even use slices or list comprehensions in Python (I disagree on this one), so I have to make some choices, and exceptions catching in Python aren't that important for beginners, I'd say.

(Not) cmpletely unrelated, I still find fun that several people think rising an exception in a loop you catch in a try outside of the loop is a pass to exit the loop, but break is a definitive no-no ^_^

Also, I agree. You need to dive more into F#!
Will definitively do, soon.

Anyway my point is that F# is a first class citizen ML (minus a module system) on one of the most well designed runtimes ever. And with .NET core, it's becoming less and less tied to Windows.
You're pointing maybe the first reason why I've been reluctant to do too much C# (and F#), even with Mono and other tricks.

But Scala (and to a lesser extend a couple others like Clojure) made me overcome my JVM allergy, so maybe (probably) F# will do the job.

That being said, I know the guys behind Caml and used to work in the (large) "organization" that develop it, so I can't jump on a Microsoft variation of it too quickly, I need to show some support ^_^ (and overall, they've done great work to develop functional programming)
 
The best implementation of counting the 1s in a single binary word:

Code:
int count(uint64_t x) {
  int v = 0;
  while(x != 0) {
    x &= x - 1;
    v++;
  }
  return v;
}

It's a mess with students each time I use arrays to describe mathematics objects, especially 2D arrays for matrices, though. "Normal" language is definitively 1-indexed.

What about changing normal language instead? ^_^
No way! Reusing intuition saves us from having to teach more. In math, 0 indexing if sequences corresponds to the number of times a transformation is applied to the initial value. The first is 0 because it has not yet been transformed. Since most programming sequences are not like mathematical sequences it seems far more appropriate to just requisition natural language and the most intuitive definitions: the number of elements up to and including the ith element in a sequence should be i.


I also don't, but there's plently of cases where iterators don't work.
Touche. I was only stating my preference because one of the arguments for 0 indexing is that if you are using it frequently, you should be able to easily calculate the length of the interval. But I don't think you should be using it frequently!

I agree. In fact, I would even think we may do with a math-like notation. [0..2] and [0..2[ or [0..2) are not the same. Not sure how you could introduce it in a language without adding too much clutter/difficulties in the syntax, though.
Oh, no way. That would make the grammar highly context sensitive!

Interesting... I'm also using fun in Caml a lot, and if it's not available alongside function, I guess I'll miss it. I guess you could always use uncurrified expressions, but that's less interesting.

I'd probably write a
Code:
  | n when n>0 ->
  | _ ->
in Caml, anyway, but I need to look more into F# syntax...
Practically 100% of the functional syntax of OCaml is available in F# because it was designed that way! You get fun.


For 0 or for negatives?
Negatives. The function is defined inductively with 0 as the base case so supplying a negative number would cause it to not terminate.

That's... actually a hot question.
Uh oh!

Short answer: I do...
Sounds like you do the right thing. I would expect engineers to make use of exceptions (although error codes are preferable) and I would expect a science program to occasionally use list comprehensions just because they're so succinct.

(Not) cmpletely unrelated, I still find fun that several people think rising an exception in a loop you catch in a try outside of the loop is a pass to exit the loop, but break is a definitive no-no ^_^
Using exceptions as non-lexical control flow is terrifying.

You're pointing maybe the first reason why I've been reluctant to do too much C# (and F#), even with Mono and other tricks.

But Scala (and to a lesser extend a couple others like Clojure) made me overcome my JVM allergy, so maybe (probably) F# will do the job.
Mono has gotten fantastically better ever since .NET open sourced and .NET core became a thing. You will probably like the language, as long as you are not attached to your functors.

That being said, I know the guys behind Caml and used to work in the (large) "organization" that develop it, so I can't jump on a Microsoft variation of it too quickly, I need to show some support ^_^ (and overall, they've done great work to develop functional programming)
You used to work at INRIA? Wow.

It still surprises me that OCaml gets new and exciting improvements every year. GADTs! Implicit modules! Who knew it was still relevant?
 
No way! Reusing intuition saves us from having to teach more. In math, 0 indexing if sequences corresponds to the number of times a transformation is applied to the initial value. The first is 0 because it has not yet been transformed. Since most programming sequences are not like mathematical sequences it seems far more appropriate to just requisition natural language and the most intuitive definitions: the number of elements up to and including the ith element in a sequence should be i.

That's not really different from the fact that the array index is the memory offset, and since the first index isn't offset it should be 0. Thinking about arrays in terms of memory usage is still a good habit to be in. It also opens up a lot of good logical reasoning about array manipulations.
 

M.D

Member
I'm doing a course on Udemy and this is early on

It's in the process of building a simple guess the number game, and there's one thing I don't quite understand and that is why is this thing actually working? What actually causes the code to produce another number after I initially set it to ask if it's 750?


using UnityEngine;
using System.Collections;

public class NumberWizards : MonoBehaviour {
int max = 1000;
int min = 1;
int guess = 500;
// Use this for initialization
void Start () {
print ("Welcome To Number Wizard");
print ("Pick a number in your head, but don't tell me!");

print ("The highest number you can pick is " + max);
print ("The lowest number you can pick is " + min);

print ("Is the number higher or lower than " + guess);
print ("Up = higher, down = lower, return = equal");

}

// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.UpArrow)){
// print("Up arrow pressed");
min = guess;
guess = (max + min) / 2;
print ("Higher or lower than " + guess);
} else if (Input.GetKeyDown(KeyCode.DownArrow)){
print("Down arrow pressed");
} else if (Input.GetKeyDown(KeyCode.Return)){
print("I won!");
}
}
}
}

Edit: This is probably easier to understand

http://paste.ofcode.org/FcADbXCGcNtiYv3EgVvetx
 

poweld

Member
I'm doing a course on Udemy and this is early on

It's in the process of building a simple guess the number game, and there's one thing I don't quite understand and that is why is this thing actually working? What actually causes the code to produce another number after I initially set it to ask if it's 750?




Edit: This is probably easier to understand

http://paste.ofcode.org/FcADbXCGcNtiYv3EgVvetx

I'm not sure what you're asking, and I also don't believe this does work. If you're asking when the Update function is being called, it's once per frame, if the comment can be believed. The scheduled calls are probably set up in the parent class, MonoBehavior.
 

diaspora

Member
I'm querying a db and the date returned looks like YY-MM-DD, how can I query it so that the query result is YYYY-MON-DD? It's really to make it more comprehensible for me, I've tried googling it but everything is showing me results for date ranges which isn't what I need.
 

Kalnos

Banned
I'm querying a db and the date returned looks like YY-MM-DD, how can I query it so that the query result is YYYY-MON-DD? It's really to make it more comprehensible for me, I've tried googling it but everything is showing me results for date ranges which isn't what I need.

What kind of database, what type of field? What language?
 
Hey programming gaf, anyone else here trying out Rust?
Just started reading the docs and typing over the example a hour ago to get a feel of it.
 
Hey programming gaf, anyone else here trying out Rust?
Just started reading the docs and typing over the example a hour ago to get a feel of it.
I've been using it for a year (1.0). One of my favorite programming languages. Definitely an improvement over C++ and probably most other languages you can think of. Its primary abstraction mechanism (traits) is very well designed and comes from Haskell and Scala. My favorite part is that it proves that a high level program doesn't need to be slow at all.

Some general warnings: there's a steep barrier to entry due to the borrow system. Many of your programs will not compile and you'll be wondering why. But once you get over the initial difficulty with it, it comes quite naturally. If you're already familiar with C, it'll be easier.
 
I've been using it for a year (1.0). One of my favorite programming languages. Definitely an improvement over C++ and probably most other languages you can think of. Its primary abstraction mechanism (traits) is very well designed and comes from Haskell and Scala. My favorite part is that it proves that a high level program doesn't need to be slow at all.

Some general warnings: there's a steep barrier to entry due to the borrow system. Many of your programs will not compile and you'll be wondering why. But once you get over the initial difficulty with it, it comes quite naturally. If you're already familiar with C, it'll be easier.

Have been trying to get into C programming again getting away from OOP madness
called legacy enterprise programming. Yesterday my eyes rolled onto Rust while i was
derping at work xD

I like the fact Rust does things differently using different programming concepts then
Java or C#. Hopefully i will learn a lot of new concepts in my Rust adventures.
 

Kieli

Member
I'm running into two problems that are confusing me.

Suppose you the following data structure:
Code:
template <typename T>
class SomeRandomClass
{
public:
  T storeSomeStuffMate;
  SomeRandomClass<T>* awYiss;

  SomeClass(T feedMe)
  {
    storeSomeStuffMate = feedMe;
    awYiss = NULL;
  }
};
In some other class, I try invoking SomeRandomClass<T> disruptive = new SomeRandomClass<T>(). However, I get "no default constructor available" error message.

Likewise, suppose I instantiate an object of type SomeRandomClass. I declare the following function which operates on said object.
Code:
template <typename T>
void SomeRandomClass<T>::someRandomFunction() {
this.doSomethingCool();
}
Except, I get an error "left of .doSomethingCool must have class/struct/union".

Help a brotha out?
 
I'm running into two problems that are confusing me.

Suppose you the following data structure:
Code:
template <typename T>
class SomeRandomClass
{
public:
  T storeSomeStuffMate;
  SomeRandomClass<T>* awYiss;

  SomeClass(T feedMe)
  {
    storeSomeStuffMate = feedMe;
    awYiss = NULL;
  }
};
In some other class, I try invoking SomeRandomClass<T> disruptive = new SomeRandomClass<T>(). However, I get "no default constructor available" error message.

Likewise, suppose I instantiate an object of type SomeRandomClass. I declare the following function which operates on said object.
Code:
template <typename T>
void SomeRandomClass<T>::someRandomFunction() {
this.doSomethingCool();
}
Except, I get an error "left of .doSomethingCool must have class/struct/union".

Help a brotha out?

If you define no constructors, a default constructor is automatically generated. If you define at least one non default constructor, no default constructor is generated. In the first example you defined a non default constructor (although I assume you misspelled that), but you tried to new it using the default constructor.

In the second example, this is a pointer, you need to use -> instead of .

As an aside, please immediately stop using NULL and use nullptr instead. Get in the habit of doing this early
 

Kieli

Member
Man, coming from Java to C++ has been brutal for me. So many quality of life features I take for granted that C++ just doesn't have.

Can't even reason about the code because the code I write isn't doing what I want it to do. Debugger ain't helping too. It just says things are NULL when I know they shouldn't be.

UGH. CODE IS LIFE.
 

Two Words

Member
Man, coming from Java to C++ has been brutal for me. So many quality of life features I take for granted that C++ just doesn't have.

Can't even reason about the code because the code I write isn't doing what I want it to do. Debugger ain't helping too. It just says things are NULL when I know they shouldn't be.

UGH. CODE IS LIFE.
This is why I think it's better to go from C/C++ to Java instead of the reverse order.
 

upandaway

Member
Man, coming from Java to C++ has been brutal for me. So many quality of life features I take for granted that C++ just doesn't have.

Can't even reason about the code because the code I write isn't doing what I want it to do. Debugger ain't helping too. It just says things are NULL when I know they shouldn't be.

UGH. CODE IS LIFE.
Yeah I had a hard time too last semester, it felt so fragile. Even when some miracle happened and it finally compiled, I either got some memory problem or something literally no one in history has ever gotten according to google. If you have the time you should write some unit tests for even the most basic things, they really helped me
 

GSR

Member
My first coding internship I went from a curriculum that was almost entirely taught in Java to writing kernel-level C code. That was a fun transition.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
My first coding internship I went from a curriculum that was almost entirely taught in Java to writing kernel-level C code. That was a fun transition.

ZEJSW.gif

I still have nightmares from my computer architecture classes.
 

Koren

Member
This is why I think it's better to go from C/C++ to Java instead of the reverse order.
I can understand why it would be better, but I followed this path, and I'm totally allergic to Java. In fact, it's at the very bottom of the list of languages I'd like to use.

I'm pretty sure I would prefer writing a project in Shakespeare, Whitespace, LT, LOLCode, Piet, Befunge, or anything like that than Java. At least, it would be a fun little challenge.

The fact that Java is the base of Android development is killing me.
 
Hey programming gaf, anyone else here trying out Rust?
Just started reading the docs and typing over the example a hour ago to get a feel of it.

I really, really like Rust. Apart from all the fancy compiler things it does (guaranteed memory safety at compile time with no GC), it's just a good language to program in. It's super fast, very well designed and feels modern. There are a couple of things that can be annoying like forced up/down-casting of numeric types (e.g. when a function takes u16 and you supply a u8, you have to explicitly upcast it as "example_function(x as u16)") but you get used to those.
 

Koren

Member
There are a couple of things that can be annoying like forced up/down-casting of numeric types (e.g. when a function takes u16 and you supply a u8, you have to explicitly upcast it as "example_function(x as u16)") but you get used to those.
After having been burned last summer by numpy implicit casts*, I'm even more fine with explicit casts than before. And yes, Rust a nice language.


* when Tab is declared as a uint64 numpy.array, I wouldn't expect Tab[0] = Tab[0]+1 to do nothing... Or even result with Tab[0] decreased!

But numpy developpers decided that uint64 + int should be double (because, you see, your 1 could be negative, and there's no sint128 type available)... The double obviously absorbs the +1 for large values of Tab[0], and the result is recasted into uint64.

Code:
>>> T = np.array([9876543210123456789], dtype='uint64')
>>> T[0]
9876543210123456789
>>> T[0]=T[0]+1
>>> T[0]
9876543210123456512

(naturally, it works with T[0]=T[0]+np.uint64(1), but you have to expect the cast to double to think there could be a need for a cast here, which doesn't seem obvious to me)
 
I really, really like Rust. Apart from all the fancy compiler things it does (guaranteed memory safety at compile time with no GC), it's just a good language to program in. It's super fast, very well designed and feels modern. There are a couple of things that can be annoying like forced up/down-casting of numeric types (e.g. when a function takes u16 and you supply a u8, you have to explicitly upcast it as "example_function(x as u16)") but you get used to those.

Put some more hours into reading documentation and typing over examples this morning. I really like the pattern matching stuff its like a supped up switch statement.
Makes the code also look cleaner then having a switch statement with fall through
or a if else trees.

Another small thing is the enumerator with the for in loop(foreach in other languages)
Its such a small thing that helps with visualizing the data in a print statement.
Saw that Rust has loop labels they look a lot like more scope bound GOTO labels
haven't had to use any of that in Java or C# i know about GOTO labels from CS classes.

Hope to finish up reading up on Rust soon, so i can start building a simple Raytracer or try some DirectX12 and Vulkan coding if there are Rust bindings for those two.
 
Yeah I had a hard time too last semester, it felt so fragile. Even when some miracle happened and it finally compiled, I either got some memory problem or something literally no one in history has ever gotten according to google. If you have the time you should write some unit tests for even the most basic things, they really helped me

The problem is really the way it's taught. I almost never even use the new keyword anymore, memory errors are almost a thing of the past if you're using modern techniques.

I can understand why it would be better, but I followed this path, and I'm totally allergic to Java. In fact, it's at the very bottom of the list of languages I'd like to use.

I'm pretty sure I would prefer writing a project in Shakespeare, Whitespace, LT, LOLCode, Piet, Befunge, or anything like that than Java. At least, it would be a fun little challenge.

The fact that Java is the base of Android development is killing me.
It's not just you. I've talked to people who work on Java (note that's ON java, not IN. As in, the language itself) who hate it
 

Koren

Member
The problem is really the way it's taught. I almost never even use the new keyword anymore, memory errors are almost a thing of the past if you're using modern techniques.
It's nice that you can avoid a lot of the memory management, but that require a lot of care (and understanding) when you write constructors (such as copy constructors), if you don't want the program to spend a lot of time copying the same data. I can understand how it's hard for newcomers.

It's not just you. I've talked to people who work on Java (note that's ON java, not IN. As in, the language itself) who hate it
Aww... I feel their pain...
 

Two Words

Member
I can understand why it would be better, but I followed this path, and I'm totally allergic to Java. In fact, it's at the very bottom of the list of languages I'd like to use.

I'm pretty sure I would prefer writing a project in Shakespeare, Whitespace, LT, LOLCode, Piet, Befunge, or anything like that than Java. At least, it would be a fun little challenge.

The fact that Java is the base of Android development is killing me.
Heh, but imagine if you learned it the other way and the way you feel about Java was the way you felt about C/C++ or any other high level language that allows you to have a similar amount of direct control on memory management.


ZEJSW.gif

I still have nightmares from my computer architecture classes.

I thought my comp arch class was fun. Assembly programming feels more rewarding to me once you get it. We had to make the game called Lexathon as a MIPS assembly project. I work in the tutor center for my university's CS program, so we help comp arch students. I was jealous of them this Spring semester. They had the same teacher and they had to make a MIPS assembler in MIPS. That was definitely a much more challenging project and I'm sure it looks a lot better on a resume of student projects than a word puzzle game.
 

Slo

Member
Heh, but imagine if you learned it the other way and the way you feel about Java was the way you felt about C/C++ or any other high level language that allows you to have a similar amount of direct control on memory management.

When I was in college our first 2 years were C++ and then the college switched to teaching Java in the final two years. After struggling with pointers and memory allocation while learning to program for the first time, having that all just handled for you by Java was a god send.

After 15 years as a Java/Javascript developer, going back to managing memory myself seems as daunting as going back to horse and buggy.

Shame.
 

Koren

Member
Heh, but imagine if you learned it the other way and the way you feel about Java was the way you felt about C/C++ or any other high level language that allows you to have a similar amount of direct control on memory management.
The way memory is handled isn't really the thing I dislike in Java. I've used several languages with different philosophies about this. It's a matter of design choices, design patters, verbosity, problems I've had with it (for example, when you want to include a look-up table in the code and the compiler refuse because your function is "too big to compile"), etc.

Besides, since I believe you should have some understanding with low-level memory management, C will not stay "strange" anyway.

I admit language preferences have a lot to do with your own history, though (I learned assembly just after BASIC 1.0, so I guess I like low-level, even if I'm fine with Haskell and the likes...)
 

Two Words

Member
The way memory is handled isn't really the thing I dislike in Java. I've used several languages with different philosophies about this. It's a matter of design choices, design patters, verbosity, problems I've had with it (for example, when you want to include a look-up table in the code and the compiler refuse because your function is "too big to compile"), etc.

Besides, since I believe you should have some understanding with low-level memory management, C will not stay "strange" anyway.

I admit language preferences have a lot to do with your own history, though (I learned assembly just after BASIC 1.0, so I guess I like low-level, even if I'm fine with Haskell and the likes...)

I brought up memory management because a lot of the students I tutor transitioning from Java to C/C++ have an incredibly hard time dealing with memory management. Many don't truly understand the underlying concepts of memory and how it relates to programming.
 

Makai

Member
Heh, but imagine if you learned it the other way and the way you feel about Java was the way you felt about C/C++ or any other high level language that allows you to have a similar amount of direct control on memory management.
I think Java gives you too much control over memory.
 
Do you know of a book or series that teaches it in a solid way for a non-beginner? I haven't used C++ since I graduated but it would be fun to fuck around in it again.

I don't really follow the C++ book scene anymore, but it looks like there's not much. Back in the day Stroustrup and Lippman's books were the two go-to's, and it looks like both are updated for C++11 but neither are updated for C++14.

http://www.amazon.com/dp/0321714113/?tag=neogaf0e-20

http://www.amazon.com/dp/0321563840/?tag=neogaf0e-20

There really isn't much else that looks appropriate for learning C++11.

While browsing Amazon, I just found out that Large Scale C++ by Jon Lakos is getting an update this year. That was an amazing book back in the day, so I'm surprised and happy to see it finally getting updated. No idea how it will treat C++11 and C++14 though, but I'd keep an eye on it.
 
It's nice that you can avoid a lot of the memory management, but that require a lot of care (and understanding) when you write constructors (such as copy constructors), if you don't want the program to spend a lot of time copying the same data. I can understand how it's hard for newcomers.

Sure, but getting high performance out of C++ isn't really the problem most people have with it, so I assume that's not what the poster was referring to. More likely it was about memory leaks, memory corruption, managing memory so it's deleted at the right time, that kind of thing.

Those kinds of issues are almost non-existant in modern C++.

You can start by just making the following trivial change
Code:
// old way
Foo *f = new Foo(1, 2, 3);

// new way
auto f = std::make_unique<Foo>(1, 2, 3);

everywhere in your code, and fixing compiler errors that result to make it work. In the process you'll learn about move semantics as well.

From there you can audit your codebase for uses of new, and think "how can I eliminate this new?" You will almost always find a way, and probably learn a bunch of stuff along the way
 

upandaway

Member
They only told us about smart pointers in the last lecture or the one before last, it would have saved us so much headache (even if we can't use the libraries, it's easy to implement yourself). But I guess memory management is part of the syllabus.
 
Memory errors don't really happen in modern C++ for single threaded applications. The point of Rust was to make the same ease feasible in concurrent applications. For instance, data races and proper locking are guaranteed impossible by the compiler.
 
Memory errors don't really happen in modern C++ for single threaded applications. The point of Rust was to make the same ease feasible in concurrent applications. For instance, data races and proper locking are guaranteed impossible by the compiler.

I don't know Rust, but I'm skeptical about this claim. Are you saying every memory access is guarded by a lock? Even if that's true (which is very unlikely) It's still possible to have a race. Detecting race conditions is equivalent to the halting problem, so how can it provably prevent them?
 
Top Bottom