• 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

poweld

Member
Perhaps. It's not for everyone. Though where impressions of the language are concerned, "C++" is ambiguous... C++11 is a huge improvement in usability from C++03, and 03 is a momentous improvement from the original spec.

I'm sure you're right. I was working with 03, and by the time 11 came out I was just exiting the job where I was using the language, so I haven't really given it a good look.

I think Go gets a lot right...*snip* That said, I have major issues with Go

Wow, great post. I didn't offer much in my original post, but I agree with you on many points. Generics especially. For the last 9 months I've been working in Scala, and boy was I spoiled by that language's generics. Just the other day I reflexively reached into the Go toolbox for a map function, only to come back with some sawdust and mothballs. Even some oddities like the math library not containing a min/max function for any primitive type other than float.

I *sort* of agree with you on compile time and optimization of the binaries, but only in the strictest sense.

I love the quick compile time. It really allows me to get the job done in a reasonable timeframe. When I was a C++ dev, we had something like 3-4M LOC source, and compiled independently on our development machines. From scratch, this took somewhere around 45 minutes. We eventually moved to distributing compilation across all dev boxes, cutting that time down to about 15 minutes, but that still pales in comparison to Go.

It makes perfect sense that this is due to a lack of compile time optimizations, leading to slower runtime. However, I believe that your point about writing code quickly is understated a bit. The balance between performance, time to write, and safety feels about right to me.

I'm currently wrapping up a prototype for a daemon which acts as a sort of syslog-like daemon, staging messages to disk while flushing them out to a streaming service backend for consumption by our other services in parallel. It needed to be up to a certain performance standard, reliable, and portable.

Within about three weeks, I was able to learn the language well enough to implement a highly concurrent solution (well, it's in it's final stages). I imagine the better part of a week was spent fiddling around with the language itself and learning about it. If I had to implement this in C++ using pthreads, even knowing the language, I'm certain I'd still be in the trenches.

Sure, the Go solution might be slower, but the juice was just so easy to squeeze out of it. Even if I'm only getting 80% of the performance I would have out of C++ I'm satisfied.

Of course, as always, it's about the right tool for the job. Go just nestled into that chasm between Python and C++, and I am very happy about that.
 

Slavik81

Member
Hey GAF, concerning issue tracking:

Say I have an app and I don't want reviews/emails from customers going "hey can you add this feature" or "hey when is this going to get fixed". I'm thinking of keeping a github repository purely for tracking issues. Pros: keeping track and categorizing them. Cons: Might be a bit of a threshold for people to overcome to post on Github, and creating an account and such. Also, I'm not sure what kind of permissions I can give to people and if I retain admin rights over the issues.

I really like Github so I prefer testing this approach, but I'd love to hear other suggestions.
Valve does this. e.g. https://github.com/ValveSoftware/steam-for-linux
 

Sharp

Member
eh, then id think youre not really keeping up with things and just blindly bashing java for either its perceived desktop defeciencies or bad experience 15 years ago.

http://www.infoworld.com/article/26...java-is-fastest-for-server-side-web-apps.html
That just isn't true. That survey doesn't include many, many servers (including most C++ servers--have you even heard of any of those frameworks?). Here's what I currently understand to be the record for concurrent connections for an in-software web server, written in Haskell.
 
That just isn't true. That survey doesn't include many, many servers (including most C++ servers--have you even heard of any of those frameworks?). Here's what I currently understand to be the record for concurrent connections for an in-software web server, written in Haskell.

eh, what are the realities once we get a database, object serialization via xml or json, or the other factors which are going to be far more important to a web application.
 

Sharp

Member
eh, what are the realities once we get a database, object serialization via xml or json, or the other factors which are going to be far more important to a web application.
For object serialization, all the fastest solutions I know are in C++ (Protobuf et. al). All the fastest relational databases I know of are written in C or C++ (Oracle, SQL Server, DB2, PostgreSQL). The most scalable databases I know of are written in C or C++ too (Spanner) or use C++ heavily for the I/O (Cassandra--if you don't use JNA it's not particularly fast). All the most efficient messaging solutions I know of are written in C++. For Java solutions to even reach comparable speeds they usually end up eating three times as much RAM or more.

The reality that you speak of is that services that need this sort of efficiency are written in C++, but most services don't. But that has nothing to do with Java being "the fastest." Java has a really great ecosystem full of good libraries that allow people to get stuff done in practice, and for that reason alone it's valuable. But let's not pretend the JVM can perform miracles.

(And really, this goes for anyone who says something like "Java is faster than C/C++ under some circumstances"--by what mechanism? JIT optimizations are nearly always subsumed by runtime-directed optimizations, garbage collection where RAM doesn't matter is nearly always slower than arena allocation. So you're left with stuff like fast singleton access because initialization is offloaded to the runtime and some subtle concurrency problems [and even then, they can always be done as well or better with RCU, as they are in the Linux kernel]. And that stuff has to outweight the cost of GC, heap allocation by default, memory barriers in some cases... seriously, if someone wants to present a mechanism, I'd be happy to hear about it).
 
Are there any certifications out there for programmers that might assist in getting a foot in the door for someone with an AS in Computer Science? Still working towards my bachelors, but getting experience now would be a good step.
 

survivor

Banned
Why does the Javascript community love to have so many packages and libraries and dependencies just to run something. I'm working on a project that requires me to setup a Node.js server to serve a responsive website. Every tutorial I'm looking up has so many perquisites just to start. Install nodejs, get express, get angularjs, get all the dependencies for them, get grunt, bower, yeoman, bootstrap, sass, mocha, and not to mention everything has its own generation tools. I'm starting to feel so lost.
 

Tamanon

Banned
Are there any certifications out there for programmers that might assist in getting a foot in the door for someone with an AS in Computer Science? Still working towards my bachelors, but getting experience now would be a good step.

I don't think a certification(which I'm not aware of any personally) would be as useful in getting in the door as having projects you can point to on a GitHub repository or elsewhere. Just personal projects, like designing a web-app to do something relatively simple.
 

D4Danger

Unconfirmed Member
Why does the Javascript community love to have so many packages and libraries and dependencies just to run something. I'm working on a project that requires me to setup a Node.js server to serve a responsive website. Every tutorial I'm looking up has so many perquisites just to start. Install nodejs, get express, get angularjs, get all the dependencies for them, get grunt, bower, yeoman, bootstrap, sass, mocha, and not to mention everything has its own generation tools. I'm starting to feel so lost.

It's no coincidence this has only happened in the last few years. A lot of people came from other languages where this is the norm so they tried to replicate that crummy experience to make themselves feel like real programmers while using a language they hate.
 
I don't think a certification(which I'm not aware of any personally) would be as useful in getting in the door as having projects you can point to on a GitHub repository or elsewhere. Just personal projects, like designing a web-app to do something relatively simple.

thanks bro
 
I don't think a certification(which I'm not aware of any personally) would be as useful in getting in the door as having projects you can point to on a GitHub repository or elsewhere. Just personal projects, like designing a web-app to do something relatively simple.

This is 100% true, personal projects >>>>>>>>>>> certifications for any company worth a damn. I landed a job at a big 4 recently through personal projects and extra curricular experience (competitions and such). Obviously the degree etc. helps to get to the interview in the first place, certificates would not have helped with the interview process but the projects definitely did.
 

Corgi

Banned
Got relieved from duty after 1.5 year gig as an embedded core java developer after college.

Having issues job hunting atm... I don't have the years of experience for a mid/senior role, and my previous job hasn't given me much opportunity working with the hot stuff of today like webservices, front end, back end, and all that jazz.

Getting a bunch of calls is great, but at the same time combo rejections eats at the soul.


In the mean time, been reading up cracking the coding interview, and thinking of learning more python scripting (seems like a skill people desire).

Any advice on the process, what else to do these days to be 'productive'?


And I need to rant about how dumb those multiple choice 'technical assessments' some hiring firms make you do. Such a waste of time and you don't really learn anything about the person from these!
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
I have a couple of C++ nitpicks that I hope you guys can enlighten me on. There must be a reason for these, but with my thinking it doesn't sit right.

Why make an alias for a type instead of just referring to that type itself?
Code:
// why this
typedef int Item;
Item data;
// instead of this?
int data;

Why overload an operator to do a function instead of making a method?
Code:
// why this
ostream &operator << (ostream &out_s, List l1) { // method contents }
// rather than this?
List::writeList (List l1) { // method contents }

Both of the former options seem like they would cause more code confusion since they are changing the behavior of things that are generally assumed to work in a certain way.

C++ is still quite arcane to me right now, and I'm just attempting to understand it more. I'd honestly like to hear your opinions or reasons so I can learn. This applies to an assignment, but I'm not looking for solutions, just explanations.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
I have a couple of C++ nitpicks that I hope you guys can enlighten me on. There must be a reason for these, but with my thinking it doesn't sit right.

Why make an alias for a type instead of just referring to that type itself?
Code:
// why this
typedef int Item;
Item data;
// instead of this?
int data;
One of the reasons is to make code easier to read in some particular way. List<serials> is more meaningful at a glance than List<int>.

Why overload an operator to do a function instead of making a method?
Code:
// why this
ostream &operator << (ostream &out_s, List l1) { // method contents }
// rather than this?
List::writeList (List l1) { // method contents }

Again, readibility. Pretend you're making a utility class for matrix math and you want to support concatenating multiple matrices. Which do you think looks better?

Code:
Matrix a, b, c, d;
d = a.concat(b.concat(c));
//or
d = a * b * c;
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
One of the reasons is to make code easier to read in some particular way. List<serials> is more meaningful at a glance than List<int>.



Again, readibility. Pretend you're making a utility class for matrix math and you want to support concatenating multiple matrices. Which do you think looks better?

Code:
Matrix a, b, c, d;
d = a.concat(b.concat(c));
//or
d = a * b * c;

Is it just for readability than? If so I can understand that then. I can just think of them as dealing with types and methods in a different syntax.

Thanks for the explanation.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
There might be other more sophisticated reasons for these features but I'm not privy enough to give an adequate explanation!
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
There might be other more sophisticated reasons for these features but I'm not privy enough to give an adequate explanation!

Appreciate it! You helped lift the fog of C++ one bit further away.
 

Water

Member
Is it just for readability than? If so I can understand that then. I can just think of them as dealing with types and methods in a different syntax.
Yes, just for readability. For operators, matrix math is the perfect example of when it would really suck to not have overloading. Also consider
Code:
filestream << 500 << mytype << ...
Typedefing a simple type like int isn't so common, but for low-level stuff you might typedef inside #ifdefs to get a different type for different platforms. And of course this
Code:
void foo(const bar& x, const bar& y)
is a whole lot more readable with "bar" rather than "std::map<std::string, std::vector<std::pair<...".
 

Apoc29

Member
Is it just for readability than? If so I can understand that then. I can just think of them as dealing with types and methods in a different syntax.

Thanks for the explanation.

Using typedef can also help you make changes a lot easier; for example, if you decided that Item (which is an int) takes up too much memory and you wanted them all to be a short instead, you would just have to change the typedef from int to short. Otherwise, you would have to do a manual find and replace on everything of type int and make sure it was a variable describing an Item and that could be error-prone.
 

Randdalf

Member
I have a couple of C++ nitpicks that I hope you guys can enlighten me on. There must be a reason for these, but with my thinking it doesn't sit right.

Why make an alias for a type instead of just referring to that type itself?
Code:
// why this
typedef int Item;
Item data;
// instead of this?
int data;

Why overload an operator to do a function instead of making a method?
Code:
// why this
ostream &operator << (ostream &out_s, List l1) { // method contents }
// rather than this?
List::writeList (List l1) { // method contents }

Both of the former options seem like they would cause more code confusion since they are changing the behavior of things that are generally assumed to work in a certain way.

C++ is still quite arcane to me right now, and I'm just attempting to understand it more. I'd honestly like to hear your opinions or reasons so I can learn. This applies to an assignment, but I'm not looking for solutions, just explanations.

In the case of some sort of List class, I think it would be much clearer to have a push() or append() method rather than using a shift operator.
 

Sharp

Member
Using typedef can also help you make changes a lot easier; for example, if you decided that Item (which is an int) takes up too much memory and you wanted them all to be a short instead, you would just have to change the typedef from int to short. Otherwise, you would have to do a manual find and replace on everything of type int and make sure it was a variable describing an Item and that could be error-prone.
Yeah, that's the real reason for typedef. You can get a similar effect by wrapping your type in a class, but in many cases it's just an alias for one of the integer types and it's not worth the extra effort.

(Historical note: in C, structs lived in a different namespace, and you would define structure types like this:

Code:
struct foo {
  int x;
  int y;
};

struct foo z; /* defines a z of type foo */

So typedefs were largely invented as a way to make this more convenient:

Code:
typedef struct {
  int x;
  int y;
} foo;

foo z;

You can still see this pattern in older C codebases).
 

Ashes

Banned
Depends hugely on what your goals are. What do you mean by useful?

I see. Out of curiosity, how would it differ say between,
A, hobbyist looking for an extra string in their bow
B, somebody not IT inclined seeking employment in that field.


My self. I'm bored and looking for something mentally challenging, but my primary passions lie elsewhere.
 

Sharp

Member
I see. Out of curiosity, how would it differ say between,
A, hobbyist looking for an extra string in their bow
B, employment.


My self. I'm bored and looking for something to mentally challenging.
A. Scheme (along with the book Structure and Interpretation of Computer Programs), C, Haskell, and then if you're still into it you won't need me to tell you where to look :)
B. Python or Ruby, Java or C#, JavaScript, and SQL. Fastest path to employment.

Looking for a mental challenge, but doesn't currently know a programming language: I'd try using Python with the "Project Euler" online problems. They require a combination of mathematics and programming to solve.

All of these are paths to employment, incidentally. It's a question of how long they take and what type of employment you're looking for.
 
My self. I'm bored and looking for something mentally challenging, but my primary passions lie elsewhere.

Sharp knows whats up. Download yourself a copy of Racket (a type of Scheme) and start with Structure and Interpretation of Computer Programs. SICP uses MIT Scheme which has some small differences to Racket but almost everything in the book is 1:1. A quick google or ask here if you get stuck and you should be fine.

This route is less immediately productive from an employment perspective but I believe it is one of the best from a personal improvement perspective. Plus, if you learn Scheme/Racket and get through most of that book you won't have any trouble with other languages/concepts.
 
I have a question for you guys with Software Engineering / Computer Science degrees.

Right now, I am a a sophomore pre-majoring in SE (technically not officially a major until next year). It seems like every couple of months, I always compare my schedule to the CS schedule and I wonder about which major is a better fit for me. The job I would most like to have once I am done with school would either be working on mobile apps or possibly some sort of web development.

Is SE just the way to go now, over CS? Will I be qualified for my goals either way I choose to go? I feel like an SE degree means I'm going to be required to be the lead of projects eventually, but I'm not sure if that is what I want. I know the basic differences of each degree, but I think it'd be valuable for you guys with degrees to give me some input and a little guidance. I should probably talk to my adviser either way though, lol.
 

Varaladis

Member
I have a question for you guys with Software Engineering / Computer Science degrees.

Right now, I am a a sophomore pre-majoring in SE (technically not officially a major until next year). It seems like every couple of months, I always compare my schedule to the CS schedule and I wonder about which major is a better fit for me. The job I would most like to have once I am done with school would either be working on mobile apps or possibly some sort of web development.

Is SE just the way to go now, over CS? Will I be qualified for my goals either way I choose to go? I feel like an SE degree means I'm going to be required to be the lead of projects eventually, but I'm not sure if that is what I want. I know the basic differences of each degree, but I think it'd be valuable for you guys with degrees to give me some input and a little guidance. I should probably talk to my adviser either way though, lol.

Why not just double major? I'm thinking about doing it, or at least minoring in CS. I'm pretty much in the same boat as you right now
 
I have a question for you guys with Software Engineering / Computer Science degrees.

Right now, I am a a sophomore pre-majoring in SE (technically not officially a major until next year). It seems like every couple of months, I always compare my schedule to the CS schedule and I wonder about which major is a better fit for me. The job I would most like to have once I am done with school would either be working on mobile apps or possibly some sort of web development.

Is SE just the way to go now, over CS? Will I be qualified for my goals either way I choose to go? I feel like an SE degree means I'm going to be required to be the lead of projects eventually, but I'm not sure if that is what I want. I know the basic differences of each degree, but I think it'd be valuable for you guys with degrees to give me some input and a little guidance. I should probably talk to my adviser either way though, lol.

I have a SE degree but definitely feel like a CS degree would have been better. Maybe the school I went to just sucks but I felt like there were gaps in knowledge that I needed to fill in on my own.

For reference I've held both the low on totem pole dev and team/development lead positions. The SE degree sort of prepped me for lead dev concepts but not the actual day to day job.


And now I have a question. Do you guys tend to work on open source stuff? I've seen two lead dev job applications that want to see your Githib account. My entire body of work has been on commercial / government software which I obviously can't use as a reference of my code.

If so, do you just pick a project on Github in your language of choice and start fixing bugs/implementing features?
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
I have a SE degree but definitely feel like a CS degree would have been better. Maybe the school I went to just sucks but I felt like there were gaps in knowledge that I needed to fill in on my own.

For reference I've held both the low on totem pole dev and team/development lead positions. The SE degree sort of prepped me for lead dev concepts but not the actual day to day job.


And now I have a question. Do you guys tend to work on open source stuff? I've seen two lead dev job applications that want to see your Githib account. My entire body of work has been on commercial / government software which I obviously can't use as a reference of my code.

If so, do you just pick a project on Github in your language of choice and start fixing bugs/implementing features?

How I understand it, they are searching more for what kind of projects or things you work on outside of work. To see what you are interested in in your off time, or what you are able to accomplish when not forced to. That could be completely wrong though.

-----------

As far as CS vs SE degrees. At least in my case and at my school, the CS degree seems to be primarily focused on the theory side of things, whereas the SE degree is focusing on how to apply those theoretical concepts. (for what it's worth, the SE degree won't be implemented until Jan, but these views are based on what I've learned about what the degree will include)
FYI, the only deviations between the two are in the upper division courses, (I think 400/500 levels, or maybe 300 even). So a lot of the material is overlap between the two.

This may be different in other universities, but that's at least how it works here.

Job wise, I'm assuming that the SE degree would create more second looks or further investigations than the CS degree. A lot of it boils down to how you present yourself and how you present your previous work though.

On this topic, I'd highly recommend reading this article on job searching based on how you title/present yourself.
Article link
 

Mr.Mike

Member
http://blog.jetbrains.com/blog/2014/09/23/jetbrains-makes-its-products-free-for-students/

Hello everyone,

If you’re on social media, you may have noticed that we have our ears to the ground, always listening and looking for new ideas.

Who could have guessed that this tweet would become a reality one week later!

Everything starts with learning. And what we learn when we’re young defines what we become and quite often what we are able to achieve in our lives. So, how do we make sure today’s students learn from the best? We at JetBrains believe we can do something about this.

JetBrains has a proud tradition of supporting students and academia with discounted Academic Licenses. But today we are going a step further and announcing free licenses for eligible students and teachers around the world! JetBrains Student License makes our entire product line of IDEs AND .NET Tools (while TeamCity and YouTrack already have free versions or plans) freely available to anybody who meets our simple criteria.

So jetbrains is making their software free to students. Obviously this is an attempt to get people accustomed to their own IDE's before they get used to anyone else's products, but I can appreciate free software. That said, I'll have to wait a bit until they white list my schools domain.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
So jetbrains is making their software free to students. Obviously this is an attempt to get people accustomed to their own IDE's before they get used to anyone else's products, but I can appreciate free software. That said, I'll have to wait a bit until they white list my schools domain.

I was ecstatic to read this news because I was just looking into buying the student version of WebStorm.

Now I just have to decide if I want to go back to the awesomeness that is the IntelliJ platform, or stick with Brackets for my web dev.
 

Anustart

Member
In c#, if I'm needing an arbitrary number of a class, I can create it with say MyType temp = new MyType() in a loop and it will create a new one and no longer reference the old one.

How can I accomplish this in c++?

I'm needing an arbitrary amount of a certain type which is handled in a loop.
 
This is an slightly older post but I'll answer it now anyhow.

Why does the Javascript community love to have so many packages and libraries and dependencies just to run something. I'm working on a project that requires me to setup a Node.js server to serve a responsive website. Every tutorial I'm looking up has so many perquisites just to start. Install nodejs, get express, get angularjs, get all the dependencies for them, get grunt, bower, yeoman, bootstrap, sass, mocha, and not to mention everything has its own generation tools. I'm starting to feel so lost.

While someone might think something like this:

It's no coincidence this has only happened in the last few years. A lot of people came from other languages where this is the norm so they tried to replicate that crummy experience to make themselves feel like real programmers while using a language they hate.

I think it's quite the opposite. Does JavaScript community need to have so many packages and libraries and dependencies just to run something. Answer is no. Why does the community then love them so much.

So for your use case: Running a responsive website over Node JS server. So okay, to get started you need to do pretty much this:

- Install Node which installs npm and now you never have to worry about it again)

then run npm init to create your package.json

- Install Grunt with npm
- Install Bower with npm (which does depend on Git but hey, now you don't worry about that either)
- Install express with npm, which also installs the dependencies
- Install Bootstrap-sass with bower, which also installs the dependencies (including jQuery)
- Install mocha with npm

Use --save and --save-dev to save these to your package.json. This process took you around 5 minutes with a decent connection.

Next time you want to update any of those, you can use npm / bower again to update them. Next time you have to start a similar project, just copy your package.json and run npm install and it installs the same packages for you automatically.

Actually, you can skip a step or two by using a Yeoman generator, for instance using Angular-fullstack - https://github.com/DaftMonk/generator-angular-fullstack or meanseed https://github.com/jackrabbitsgroup/generator-mean-seed

So why do JavaScript developers love packages and libraries and dependencies? So you don't have to waste any time navigating to a some web page, downloading a zip file, opening it, copying the files to correct places etc. every time something updates (which is very frequently with JS libraries) / you start a new project / you need a component/library/script/whatever.

Do you need to use them? Or any library altogether? That's really up to you, use them if you need them, or don't use them if you don't need them.
 
I see. Out of curiosity, how would it differ say between,
A, hobbyist looking for an extra string in their bow
B, somebody not IT inclined seeking employment in that field.


My self. I'm bored and looking for something mentally challenging, but my primary passions lie elsewhere.
Javascript is the answer for both A and B, you really can't avoid learning it anymore.

For B, it should be supplemented with one or two extra languages though. What that language should be is depending on where you live/want to work:

Silicon Valley or some hipster startup? Probably python or ruby or some functional language.
For a corporate or government environment , you cant go wrong with Java or C#.
For lower level stuff C++ still reigns supreme afaik.
Data Science stuff, go for python and R.


Also, make sure you know at least one flavour of SQL. You dont have to know it in-depth like a DBA, but you should be able to at least know the difference between the different kind of joins and be able to mash out some basic queries.
 
In c#, if I'm needing an arbitrary number of a class, I can create it with say MyType temp = new MyType() in a loop and it will create a new one and no longer reference the old one.

How can I accomplish this in c++?

I'm needing an arbitrary amount of a certain type which is handled in a loop.

It works the same way. The only difference comes with whether you want to store your objects on the stack or the heap. Typically you want to use the stack as it automatically handles object destruction for you.

Something like:

Code:
    std::vector<Foo> fooList;
    for (int i = 0; i < 10; ++i) {
        Foo foo(i);
        fooList.push_back(foo);
    }

std::vector.push_back will make a copy of the object on insertion, so even though foo has gone out of scope after an iteration of the loop you're still good. In the event that you need to use the heap for object allocation, usually only because object copying is very expensive or you might have a very large amount of objects you can store pointers to Foo in the vector instead, but then you need to remember to clean up when done.

Code:
    std::vector<Foo*> fooList;
    for (int i = 0; i < 10; ++i) {
        Foo * foo = new Foo(i);
        fooList.push_back(foo);
    }

    // do stuff with them Foos

    for (unsigned int i = 0; i < fooList.size(); ++i) {
        delete fooList[i];
    }
 

Sharp

Member
Javascript is the answer for both A and B, you really can't avoid learning it anymore.
There's no reason to learn JavaScript if you don't do frontend web development (node.js is hardly universal and there are lots of alternatives). I think it's a pretty bad first language because it has enough idiosyncrasies that it's hard to extract universal programming concepts from it.
 
Has anyone tried this: http://exercism.io

It's supposedly great to learn how to code. You basically receive exercises other people have made and correct the errors. And vice-versa.

It forces you to DO, instead of just mimicking the exercises. This is something I found myself doing all the time when learning how to code on code-academy. The answer just stared at you. Too much handholding.
 

Ortix

Banned
Hey programming gaf!

Studying ICT (this is my second week, so yeah...), and main focus is on programming of course, but my first question is about something else.
We need to access Linux, either by installing it directly on our HD or by using a VM. VM looks a lot easier, but I'm using a mac and I'll probably need to use Linux or Windows for more than just our Linux course, such as Oracle Express 11g, and possibly some other things. Anyway, I heard a VM slows everything down a lot...

Is there anyone who can offer me some advice? Are there actually programmers using a mac? School said it wasn't a problem (and it isn't, it's just a bit more complicated), and my dad's a mac fanboy + I was used to working with them...
 

Tamanon

Banned
Macs are pretty big amongst programmers. You can get almost any tool(outside of Visual Studio I think), and can just run Bootcamp or Parallels to get a Windows OS if need be.

Linux VMs generally aren't that slow and I have Win 7 on Parallels on mine and it runs pretty decently. Worst case scenario, you just bootcamp another OS.
 

Sharp

Member
std::vector.push_back will make a copy of the object on insertion, so even though foo has gone out of scope after an iteration of the loop you're still good. In the event that you need to use the heap for object allocation, usually only because object copying is very expensive or you might have a very large amount of objects you can store pointers to Foo in the vector instead, but then you need to remember to clean up when done.

Code:
    std::vector<Foo*> fooList;
    for (int i = 0; i < 10; ++i) {
        Foo * foo = new Foo(i);
        fooList.push_back(foo);
    }

    // do stuff with them Foos

    for (unsigned int i = 0; i < fooList.size(); ++i) {
        delete fooList[i];
    }
In C++11 you can do this more sanely, and if you must use heap allocation I would definitely do it this way:

Code:
    std::vector<std::unique_ptr<Foo>> fooList;
    for (int i = 0; i < 10; ++i) {
        // Create a unique pointer to Foo.
        // This is an affine type that can only be destroyed or moved, never copied.
        std::unique_ptr<Foo> foo(new Foo(i));
        // Now we move it into the vector--it can no longer be referenced anywhere else
        fooList.push_back(std::move(foo));
        // if you try to dereference foo here, you'll get a segmentation fault (the internal pointer
        // has been set to nullptr).
    }

    // do stuff with them Foos
    // They get deterministically freed when the block ends; it is safe to do this since
    // there is only ever one valid reference to them.

Or the equivalent Rust code:
Code:
    // Variables in Rust are immutable by default.
    // Rust uses local type inference so you rarely need to
    // annotate variables with explicit types.
    let mut foo_list = Vec::new();
    // Rust uses external iterators for its for loops.
    for i in range(0, 10) {
        // box is how Rust allocates on the heap.
        let foo = box Foo(i);
        // In Rust, move semantics are universal and automatic.
        foo_list.push(foo);
        // If you try to use foo here, you'll get a compile time error.
        // Affine types are baked into the compiler.
    }
    // do stuff with them Foos.
    // Like C++, they are deterministically freed when foo_list goes out of scope.

One neat thing about Rust is that it has pretty good support for functional programming, so the above code can be replaced (without losing efficiency--in this specific case, it's actually more efficient since collect has an estimate of how large the Vec is going to be) by:
Code:
     let foo_list: Vec<_> = range(0, 10).map( |i| box Foo(i) ).collect();
    // do stuff with them Foos
(in both examples, changing it from heap allocated to stack allocated, which is usually what you want, is just a matter of removing the box keyword; the compiler infers the rest).
 

phoenixyz

Member
Hey programming gaf!

Studying ICT (this is my second week, so yeah...), and main focus is on programming of course, but my first question is about something else.
We need to access Linux, either by installing it directly on our HD or by using a VM. VM looks a lot easier, but I'm using a mac and I'll probably need to use Linux or Windows for more than just our Linux course, such as Oracle Express 11g, and possibly some other things. Anyway, I heard a VM slows everything down a lot...

Is there anyone who can offer me some advice? Are there actually programmers using a mac? School said it wasn't a problem (and it isn't, it's just a bit more complicated), and my dad's a mac fanboy + I was used to working with them...

If you need both Linux and Windows for certain software (on a Mac) you should just use VMs. I don't know much about the CPUs in Macs but they should probably have hardware acceleration for virtualization, so there is not that much slowdown/overhead compared to running the system natively.
 

BreakyBoy

o_O @_@ O_o
If you need both Linux and Windows for certain software (on a Mac) you should just use VMs. I don't know much about the CPUs in Macs but they should probably have hardware acceleration for virtualization, so there is not that much slowdown/overhead compared to running the system natively.

That's all accurate. Macs are sort of the defacto standard in some areas for developers. Honestly, everywhere I've been/visited on the west coast, it's a sea of Macs. Even when I visited the Microsoft campus, I saw a ton of Macbook Pros all over the place.

You can use VirtualBox if you want a free workable VM. Just grab that and an Ubuntu ISO and you're good to go.

Or, you could learn to use Vagrant, and learn how to spin up your own dev-box from the command-line in a matter of seconds. I highly recommend this option.
 

Ortix

Banned
Thanks for the input everyone, I'll just use a VM then. I've already got VirtualBox installed, so that's easy. Vagrant looks interesting, but what exactly is it for? Is it difficult to learn?
 
Thanks for the input everyone, I'll just use a VM then. I've already got VirtualBox installed, so that's easy. Vagrant looks interesting, but what exactly is it for? Is it difficult to learn?

Vagrant is a system that allows you to specify configuration and dependencies for a virtual machine so that you can execute a command and have a VM up and running with all the software and development libraries you need installed and ready to go on any machine or across multiple machines in a group. It's very powerful but it's a bit overlkill for a beginner. You're probably fine with VirtualBox for the time being but if you find yourself doing things like reconfiguring new VMs with different setups etc. it's worth looking into.
 

BreakyBoy

o_O @_@ O_o
You're probably fine with VirtualBox for the time being but if you find yourself doing things like reconfiguring new VMs with different setups etc. it's worth looking into.

Absolutely this, and I should have been more clear about it. Vagrant is a great way to handle this sort of thing if you're already used to it. If you're just starting out with VMs period, working with something like VirtualBox directly is the way to go. My intention was to just let you know that a more powerful/automated solution is out there in case this sort of things comes up often in the future.
 
Hey guys, just a couple quick questions.

This is my one question:

15) What is the Big Oh of method2? Is there a best case and a worst case?
http://pastebin.com/CvbcKPRL

I believe the Big Oh is O(n^2) but I am not sure about the best case and worse case.

Also,
17) Consider four programs—A, B, C, and D—that have the following performances:
A: O(log n) B: O(n)
C: O(n2) D: O(2n)
If each program requires 10 seconds to solve a problem of size 1000, estimate the time required by each program for a problem of size 2000.

I guess I am thrown off my the 2000 size; Do these seem correct?
17a.
17b. O(n); Time Multiplier is 2; O((2xn)^2) = 2x0(n) = 2 * Units = 2x10 sec = 20 seconds
17c. O(n^2); TM is 4; O((2xn) = O(2^2 x n^2) = O(4xn^2) = 40 seconds
17d. O(2^n); TM is 2^n; O(2^(2xn)) = O((2^2)^n) = O(4^n) = 10 x 2^n seconds

Also, can anyone explain the first one to me. Not sure about the time multiplier for logs.

This is Java, btw. Go easy, I am new lol
 
Top Bottom