|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
infinity21
Canada6683 Posts
On December 07 2012 04:44 RoyGBiv_13 wrote:Show nested quote +On December 06 2012 14:50 infinity21 wrote: Thanks guys. I'm not in any rush so I'll just take it slowly and explore what's been done in the area. I'm not sure what coding these data structures involves but on a high level, I essentially only need to do matrix multiplication and loops (albeit a lot of them). Not sure how much complexity CUDA will add to the equation but I'm hoping it's not too much lol I'll take a jab at your design since I once did something similar in an FPGA (drool, infinitely parallel computations makes neural nets fun and easy  ) For matrix multiplication, take a look at SO for suggestions of a fast library: http://stackoverflow.com/questions/2637249/whats-a-good-matrix-manipulation-library-available-for-cTheres a suggestion specific to CUDA: https://developer.nvidia.com/cublas Looks like those libraries are probably the best. Though what people say about needing to know a ton about memory allocations and data structures to write good code in C is true, you should never reinvent the wheel. A fantastic programmer would know exactly how the data structures are implemented within the library code in order to best accommodate it within their own code (for example, lookup times in a certain table may be fast, but adding something is slow, so you would add everything in the table at the beginning and modify values as you see fit). This is true of all languages though. For your system, you can trial and error your way to a workable code base without having to know everything about C and data structures. Honestly, as long as it runs, then you have written 'good' C code. I'm not sure exactly what machine learning model you want to use for your system, so I'll let you find the library for that yourself. In any case, please do take your time in tackling this  Just don't stress about the language part of it. C is pretty easy to pick up and use, but incredibly difficult to master, like most things in computers/life. I'll look into those links, thanks! My main motivation for using CUDA is for training deep neural nets and other variants of neural networks. There's just not enough computing power using a CPU even for small problems so I'm trying to use CUDA to speed up learning
|
What are the different things I can do with printf in C?
By this I mean what if I want to make a list of things align in a certain way like:
1 2 3 4 5 6 7 8 9
Is there any way to do this without a bunch of spaces and /n's? (may have chosen wrong slash) Is there away to align the 1 to the left, the 2 to the center, and the 3 to the right etc.?
|
Hyrule19082 Posts
foreach(i = 1; i < 10; i++) { stdout << i << ' '; if(i % 3 == 0) cout << endl; }
pretty basic
|
for ( i = 1; i < 10; i+3 ) { printf ( "%d %d %d\n", i, i+1, i+2 ); }
would be better?
maybe something like:
for ( i = 1; i < 10; i+3 ) { printf ( "%d%3d%3d\n", i, i+1, i+2 ); }
but im not entirely sure if thats correct though, give it a try, to my knowledge you can't 'align' something to the left or right, and newlines are only from \n.
|
sorry double
|
On December 07 2012 06:44 3FFA wrote: What are the different things I can do with printf in C?
By this I mean what if I want to make a list of things align in a certain way like:
1 2 3 4 5 6 7 8 9
Is there any way to do this without a bunch of spaces and /n's? (may have chosen wrong slash) Is there away to align the 1 to the left, the 2 to the center, and the 3 to the right etc.?
Take a look at http://www.cplusplus.com/reference/cstdio/printf/. I'm not sure centering text is available. What you're talking about is padding, I think, which is doable but only with 0s I think. The %d is where you can specify the formatting that you want for the string.
tofu's reference is about C++, not C. You guys are sorta missing the point. :s
|
There's no reason (IMO) to use C over C++ unless you have strict hardware limitations or are writing a seriously trivial program. C++ takes C's memory management to a new level. Deterministic destruction --the fact that the language makes guarantees about object lifetimes-- leads to some ridiculous powerful ideas, RAII being the core one. Not everyone's cup of tea, and not a beginner's solution, but definitely something to look into if you're not fully satisfied with the solutions that C offers (i.e. nothing but floating mallocs and frees).
|
On December 07 2012 07:03 Blisse wrote:Show nested quote +On December 07 2012 06:44 3FFA wrote: What are the different things I can do with printf in C?
By this I mean what if I want to make a list of things align in a certain way like:
1 2 3 4 5 6 7 8 9
Is there any way to do this without a bunch of spaces and /n's? (may have chosen wrong slash) Is there away to align the 1 to the left, the 2 to the center, and the 3 to the right etc.? Take a look at http://www.cplusplus.com/reference/cstdio/printf/. I'm not sure centering text is available. What you're talking about is padding, I think, which is doable but only with 0s I think. The %d is where you can specify the formatting that you want for the string. Space padding is default, you have to actually add the "0" in to make it pad 0s.
edit: "drop in" is probably ambiguous wording, I mean you have to do
%02d to make it print "02", if you don't add the 0 flag (%2d) you get space padding, the default.
|
On December 07 2012 07:39 Mstring wrote: There's no reason (IMO) to use C over C++ unless you have strict hardware limitations or are writing a seriously trivial program. C++ takes C's memory management to a new level. Deterministic destruction --the fact that the language makes guarantees about object lifetimes-- leads to some ridiculous powerful ideas, RAII being the core one. Not everyone's cup of tea, and not a beginner's solution, but definitely something to look into if you're not fully satisfied with the solutions that C offers (i.e. nothing but floating mallocs and frees).
Linus has something to say about this: http://article.gmane.org/gmane.comp.version-control.git/57918
Furthermore, from the compiler angle, C++ is an absolutely insane language. Just terrifying things can go wrong that you just can't diagnose. The object model and templates create some gnarly black magic in between the code you write and the machine code. Not to mention exception handling... At least, whenever you run across a difficult to design program in pure C, it is usually quick and simple to debug. The trade-off is that it's harder to design just about anything in pure C;
Note that I don't share Linus's views on the language itself. The design behind C++ is completely brilliant, and Stroustrup should win a Nobel Prize.
Its worth talking about the bad parts of adding features into a language along with the added benefit of simpler design concepts and useful guarantees. To each his own though...
|
It sounds like Linus primarily has some beef with a particular way people use C++. If C++ had to be the way he describes, I'd be frustrated too. Thing is, not everyone who writes C++ code uses a "real database", "nice object-oriented libraries", or "nice C++ abstractions". Not everyone who writes C++ code is ignorant to the "low-level issues", and not everyone who writes C++ code develops an "object model".
I'm not attached to any particular paradigm but I know the attitude that Linus is talking about; the ignorantly dogmatic one. Objected oriented for the sake of it; because you were taught that it was good; because your boss tells you to do it; etc...
"In other words, the only way to do good, efficient, and system-level and portable C++ ends up to limit yourself to all the things that are basically available in C"
I'm advocating exactly this: less is more. I think that if Linus had taken his chill pill for the day we could sit down and agree on quite a lot xD
Imagine an old carbureted V8. I just want to do some bolt on mods and switch the ignition and fuel injection to electronic. Linus makes it sound like you have no option but to scrap the whole car and buy a brand new one. I guess I should sympathise; it sounds like he has been bittered by so many people buying the newest model that he's forgotten you can even modify the classics.
--
What concerns you about some of the gnarls? Templates are quite gnarly indeed-- I usually find myself using them only in standard containers. Virtual functions are full of black magic but you don't have to use inheritance. I never do.
Can you give an example of something terrifying going so wrong that it can't be diagnosed?
|
Linus has to say a lot of things about a lot of stuff, and he's wrong about a lot of it. He's just a loudmouth who doesn't hold back when it comes to shouting his opinions.
Nobody who knows what they're talking about will ever make the argument to you that you should use C over C++ in a big project that doesn't have certain hardware or code safety restrictions (this might happen in fields like medicine, aviation, etc.). If anyone ever does, it's a C fanboy, C++ hater, or they genuinely believe what they say is objectively correct and they just don't have a clue.
And even if you have hardware-limitations or something like that, I'd argue that you should still use C++. Just don't use C++ with lots of inheritance and exceptions, or big classes which do a lot of things in memory that nobody knows about. Instead program C and add features where you deem reasonable, such as templates, better memory management and so forth, because a lot of things that C++ adds requires exactly 0 additional memory or runtime overhead compared to C, but makes programming a lot easier.
But then again, I'm not even sure if C++ compilers are available for all the C-centric platforms out there (e.g. microcontrollers and their different processor architectures which are used literally everywhere).
The same goes up the chain. Nobody who knows what they're talking about will ever make the point to you that you should use C++ over Java/C# in a big project that doesn't have certain hardware (e.g. execution time in games) or platform restrictions, and so forth.
|
About learning C++: http://abstrusegoose.com/249 ;-)
I think this: http://simpleprogrammer.com/2012/12/01/why-c-is-not-back/ expands beautifully on heishe's post above (it's not as negative as the title may sound like...). I think that nowadays most poeple who use C++ (in "real" projects, that is: a team of people working on a big amount of code for a long time) do it for two reasons:
1. because they have very clear performance requirements regarding runtime behaviour, memory consumption or they have a certain set or regulations regarding usage of a non-garbage-collected and strongly-typed language etc. (e.g. software for nuclear power plants has those constraints among others) or
2. they work on a large set of legacy code they feel they cannot live without or are not willing to port to a language that is easier to handle.
If I would start a part-time project right now I do not think I would choose C++ even for server-side/performance-heavy programming. Even with C++ being the language I am most fluent with I think it's too overloaded with functionality and stuff-you-need-to-know-to-get-things-right to be of any use in a project which does not fall into the categories above. If I had to choose for this I think I would recommend go (golang.org) instead.
Regarding learning a language to get started: I would advise to start with something (relatively) easy like Python or maybe Ruby (no actual experiences there, though). Don't bother with a book; there are really good online courses (http://learnpythonthehardway.org/ is _really_ neat since besides teaching basic programming it also conveys very nicely a good mindset for programming IMHO). Get good with using google and good reference / QA-sites (stackoverflow comes to mind here) when you run into problems (after a while you can structure your searches so you find your answers in one of the results on the first page, don't know how to explain but after a while it just works :-)).
After having worked throughout the book/online course/whatever, look for a small task to build a program for. Nothing fancy (that is: no gaming/video/3D, no heavy networking etc...), think of something you missed on your computer once or twice and build it. This should not exceed some thousand lines maybe. Just make it work in the first place and try to remember the things that were hard for you (keep notes if you can't remember). Then build it again from scratch and compare your old with your new code if you like; you _will_ see an improvement there. Read code by other people (for example on github) and try to understand what they are doing and why they are doing it the way they do.
If you are done with this try to switch languages (say to C# or Java for example). If you want to hurt yourself switch to C++
|
Hey guys
Anyone here that could help me with a small bit of assembly language through skype? It would be super appreciated <3
|
On December 07 2012 20:14 akarin wrote: Hey guys
Anyone here that could help me with a small bit of assembly language through skype? It would be super appreciated <3
Not through skype. Better just post it here, written advice is better for that kind of stuff anyways.
|
Maybe he means through Skype messenger XD
And just because Linus has done a lot for computer science doesn't make his opinions true or more relevant than others.
Also, I hate learning Go. As much as it's painful to say this, but I NEED SEMICOLONS FUUU. It feels so wrong writing lines without semi-colons, and I hate using gofmt to reformat my code.
|
On December 08 2012 03:37 Blisse wrote: Maybe he means through Skype messenger XD
And just because Linus has done a lot for computer science doesn't make his opinions true or more relevant than others.
Also, I hate learning Go. As much as it's painful to say this, but I NEED SEMICOLONS FUUU. It feels so wrong writing lines without semi-colons, and I hate using gofmt to reformat my code.
Yeah, Linus is a great guy but his opinions about programming are often very... controversial. I find myself to often disagree with his opinions, he sounds like someone who was burnt by poor OOP one time too much and now thinks all the modern techniques are always bad.
|
On December 08 2012 03:31 heishe wrote:Show nested quote +On December 07 2012 20:14 akarin wrote: Hey guys
Anyone here that could help me with a small bit of assembly language through skype? It would be super appreciated <3 Not through skype. Better just post it here, written advice is better for that kind of stuff anyways.
I'm new around here, but wouldn't the IRC channel (#tl.code, see the OP) be a better place than Skype for something like this? Sometimes it's nice to be able to communicate in real-time.
I'll be idling there for a few hours if you still want some help.
|
“I've come up with a set of rules that describe our reactions to technologies: 1. Anything that is in the world when you’re born is normal and ordinary and is just a natural part of the way the world works. 2. Anything that's invented between when you’re fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. 3. Anything invented after you're thirty-five is against the natural order of things.” ― Douglas Adams, The Salmon of Doubt
Linus reminds me of this.
|
On December 08 2012 03:37 Blisse wrote:I hate using gofmt to reformat my code. Uniformly formatted code is a fucking godsend for large codebases though. Keep in mind who wrote the language, and what their purposes are.
|
Oracle SQL Developer really needs a refactor button. I'm using a hackish notepad++ solution for it right now.
|
|
|
|