• 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

If you just want material about the course, all the universities I've seen work alongside the book "Introduction to Algorithms" (not all of it, but it has a couple of chapters for DS), pretty tightly. Mine was too and it was fine, not hard at all to understand the material. I think the tests vary a lot depending on the professor though, and it can get really hard.

Is it algorithm analysis and data structures together, or have you had algorithm analysis before?
MIT algorithms course video lectures are brilliant, I've used them to review the topic before teaching a short course of my own.
http://ocw.mit.edu/courses/electric...algorithms-sma-5503-fall-2005/video-lectures/
edit: one of the lecturers is also an author of the Introduction to Algorithms book referenced by upandaway.
Thanks for the responses! I'll be sure to review both the book, and the video lectures before class.
 

upandaway

Member
Interesting question. Clearly it's convenient for the programmer to have the option to write a custom parameterless constructor for a struct, and that feature is present in C++ where it doesn't seem to be a problem. Maybe it wasn't originally put in C# for reasons of simplicity, dunno. Looks like language developers were looking to add it to C# 6.0, but decided against it due to issues that surfaced: https://github.com/dotnet/roslyn/issues/1029

From what I'm reading, this obstacle is simply a matter of inertia and cost, and there's no technical reason why the feature couldn't be added into the language while maintaining performance in all cases where a custom constructor is not used. Compilers could look at individual structs to determine whether a custom constructor is present and an optimization can be done, instead of clumping all structs together.
Thanks, that's a bit disappointing if that's the case. It doesn't hurt too much I guess, it just requires more discipline from the user.
 

Slavik81

Member
I started looking into a library I'm using because it popped up with some valgrind errors. What I found was not a great sign of quality...

Code:
bool TwGetKeyCode(int *_Code, int *_Modif, const char *_String)
{
    assert(_Code!=NULL && _Modif!=NULL);
    bool Ok = true;
    *_Modif = TW_KMOD_NONE;
    *_Code = 0;
    size_t Start = strlen(_String)-1;
    if( Start<0 )
        return false;
    while( Start>0 && _String[Start-1]!='+' )
        --Start;
    while( _String[Start]==' ' || _String[Start]=='\t' )
        ++Start;
    char *CodeStr = _strdup(_String+Start);
    for( size_t i=strlen(CodeStr)-1; i>=0; ++i )
        if( CodeStr[i]==' ' || CodeStr[i]=='\t' )
            CodeStr[i] = '\0';
        else
            break;

...
<20 lines of commented-out code>
<100 lines more string comparisons>
}

Anyways. The bad read only shows up with -O2 or higher. Any thoughts on how to best debug this?
 

Pegasus Actual

Gold Member
Debug? Buy a new hard drive, consult an exorcist on how to dispose of the one with that code on it, and then rewrite whatever that is supposed to be from scratch. And may God have mercy on us all.
 
I started looking into a library I'm using because it popped up with some valgrind errors. What I found was not a great sign of quality...

Code:
bool TwGetKeyCode(int *_Code, int *_Modif, const char *_String)
{
    assert(_Code!=NULL && _Modif!=NULL);
    bool Ok = true;
    *_Modif = TW_KMOD_NONE;
    *_Code = 0;
    size_t Start = strlen(_String)-1;
    if( Start<0 )
        return false;
    while( Start>0 && _String[Start-1]!='+' )
        --Start;
    while( _String[Start]==' ' || _String[Start]=='t' )
        ++Start;
    char *CodeStr = _strdup(_String+Start);
    for( size_t i=strlen(CodeStr)-1; i>=0; ++i )
        if( CodeStr[i]==' ' || CodeStr[i]=='t' )
            CodeStr[i] = '';
        else
            break;

...
<20 lines of commented-out code>
<100 lines more string comparisons>
}

Anyways. The bad read only shows up with -O2 or higher. Any thoughts on how to best debug this?
Parsers in imperative and object oriented languages are not pretty.

If a bug only shows up in a higher optimization level, then I would check for reliance of undefined behavior, such as integer rollover, weird non scalar casts, etc.
 

Onemic

Member
What would one need in terms of skills/languages if they wanted to become a graphics programmer? It's a field thats interested me for some time, but I really don't know enough about it
 

Slavik81

Member
Parsers in imperative and object oriented languages are not pretty.
Not just that. There's a bug in the code I quoted. Sadly, fixing that bug does not fix the valgrind error.

If a bug only shows up in a higher optimization level, then I would check for reliance of undefined behavior, such as integer rollover, weird non scalar casts, etc.
That reminds me, perhaps I'll run it through the Undefined Behaviour Sanitizer.
 
Not just that. There's a bug in the code I quoted. Sadly, fixing that bug does not fix the valgrind error.


That reminds me, perhaps I'll run it through the Undefined Behaviour Sanitizer.

Have you tried ASAN?

Also, can you post the rest of the function? For example, the variable _Code and _Modif aren't even used in this fragment. My guess is your compiler thinks that the two pointers don't alias even though they do.

Not just that. There's a bug in the code I quoted. Sadly, fixing that bug does not fix the valgrind error.

Could be a bug in the compiler, too.

That said, I see one immediate bug which is that size_t is an unsigned type, but you are doing signed comparisons. Start can never be less than 0.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
What would one need in terms of skills/languages if they wanted to become a graphics programmer? It's a field thats interested me for some time, but I really don't know enough about it
C++, linear algebra, some calculus, some physics, one or more graphics API like DirectX or OpenGL, 2D and 3D rendering theory
 

luoapp

Member
I started looking into a library I'm using because it popped up with some valgrind errors. What I found was not a great sign of quality...

Anyways. The bad read only shows up with -O2 or higher. Any thoughts on how to best debug this?

FWIW, Valgrind doesn't recommend using O2...

http://valgrind.org/docs/manual/quick-start.html
Use of -O2 and above is not recommended as Memcheck occasionally reports uninitialised-value errors which don't really exist.
 

injurai

Banned
Public service announcement: experienced programmers, if you haven't checked out Rust (developed by Mozilla), you should. :)

I love it. There are certain some challenging concepts, but it's such a joy to code in. They have an amazing community and infrastructure around it. I'd love to see jobs crop up more in the next few years. The language is maturing every day. So much system stuff is already written in c/c++ but Rust seems like it will really swoop into replace a lot of backend and application level implementations. Calling it from FFI and packaging libs is a joy and ease.
 

Slavik81

Member
That said, I see one immediate bug which is that size_t is an unsigned type, but you are doing signed comparisons. Start can never be less than 0.
Aww, you spoiled it for everyone. That's the only real bug I noticed, though, I'd also add that the assert should check _String.
Have you tried ASAN?

Also, can you post the rest of the function? For example, the variable _Code and _Modif aren't even used in this fragment. My guess is your compiler thinks that the two pointers don't alias even though they do.
Neither asan nor ubsan show anything wrong.

This was the self-contained example program I was using to test the function:
https://gist.github.com/cgmb/42e9955971ca2b5df803

FWIW, Valgrind doesn't recommend using O2...

http://valgrind.org/docs/manual/quick-start.html
I think this likely explains what I was seeing. Thank you very, very much.
 
I love it. There are certain some challenging concepts, but it's such a joy to code in. They have an amazing community and infrastructure around it. I'd love to see jobs crop up more in the next few years. The language is maturing every day. So much system stuff is already written in c/c++ but Rust seems like it will really swoop into replace a lot of backend and application level implementations. Calling it from FFI and packaging libs is a joy and ease.

They're trying to make everything as low of a barrier as possible, which is a great strategy and is paying huge dividends in mindshare. So you end up with a really quick feedback cycle of better tools -> more users -> better tools. Being backed by Mozilla helps, too.

I agree that it's a joy to code in. Rust just feels like a fun language to use. My favorite part is the trickiness the language inventors have pulled over people's eyes: you will not see them market it as such, but Rust is 2 steps away from SML and a mile from c++. It is not object oriented. At all. It supports ad-hoc, parametric, and bounded polymorphism. It is strongly typed. And yet it is (for most purposes) as fast as c++ but entirely memory safe without a garbage collector.
 

Slavik81

Member
What would one need in terms of skills/languages if they wanted to become a graphics programmer? It's a field thats interested me for some time, but I really don't know enough about it

C++, linear algebra, some calculus, some physics, one or more graphics API like DirectX or OpenGL, 2D and 3D rendering theory
This is literally the list I was going to make. In that order, too. That said, I'm not a professional graphics developer either.
 
This is literally the list I was going to make. In that order, too. That said, I'm not a professional graphics developer either.

While all of those are necessary, the list is not sufficient. I'm well versed in all of those aspects and I'm still a completely incompetent graphics programmer. The most important element missing from that list is practice. You have to sit down and just do stuff. I always fell over at this part because I'm horrible when it comes to art, and I'm not imaginative enough to think up ways to do graphics programming without being in control of the artwork I'm using. So I never got practice. But if you're serious about learning graphics programming, you have to do this. Go build 20-40 little toy games or simulations that involve graphics. Without it you're just a guy who knows math and programming.
 

wolfmat

Confirmed Asshole
You have to also understand the workflow of artists if you want to be truly professional, and should be conceptually cool with common tools. And you have to know a lot about optimization techniques in your language, and for the structures and metaphors you code.

Regarding practice: It helps immensely as a beginner if you build tools for empowering artists. Import / export plugins and code for understanding common file formats. Realtime heightmap editing as an executable. Animation visualization. Environment generators for ragdoll testing. Shader generator interfaces with sliders for variables, checkboxes etc, and the realtime result also.

There are so many cool tools that are interesting to hack, and they make you smarter each time you code them. Additionally: Tool programming is a career in and of itself.
 

Onemic

Member
C++, linear algebra, some calculus, some physics, one or more graphics API like DirectX or OpenGL, 2D and 3D rendering theory

While all of those are necessary, the list is not sufficient. I'm well versed in all of those aspects and I'm still a completely incompetent graphics programmer. The most important element missing from that list is practice. You have to sit down and just do stuff. I always fell over at this part because I'm horrible when it comes to art, and I'm not imaginative enough to think up ways to do graphics programming without being in control of the artwork I'm using. So I never got practice. But if you're serious about learning graphics programming, you have to do this. Go build 20-40 little toy games or simulations that involve graphics. Without it you're just a guy who knows math and programming.

Thanks for the explanations/advice. I pretty much have to start back at grade 10 math again and work my way back up :(
 

Daeda

Member
Hi guys, does any of you have any experience with Concurrent programming in Swift/Objective-C? Im working on a JSON parser that needs to parse large arrays and performance on iPhone 4 with sequential parsing isnt very good. So im trying to get the parser to work by parsing the arrays in multiple threads, but my locks dont seem to work properly. Basically what I need is this:

Code:
func parseArray(jsonArray: [JSON]) -> [AnyObject] {
        var array = [AnyObject]()
        let size = count(jsonArray)
	var lockA = lock(0)// create Lock
	var lockB = lock(size)
        let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
        for var i = 0; i < size; i++
        {
            let index = i
            let jsonObject: JSON = jsonArray[index]
            dispatch_async(dispatch_get_global_queue(priority, 0)) {
                if let parsedObject : AnyObject = self.parseObject(jsonObject)
                {
                    wait(lockA)
                    if index < count(array) {
                         array.insert(parsedObject, atIndex: index)
                    } else {
                         array.append(parsedObject)
                    }
                    release(lockA)
		    release(lockB)
                } else {
                    release(lockB)
                }
            }
        }

        wait(lockB) // Wait untill all released
        return array
}

I tried using a dispatch_semaphore_create(1) for lockA and a dispatch_group_create() for lockB, but whatever I do lockB never seems to unlock, deadlocking the whole process. Note that this funcion may also be called by parseObject (on a different instance and usually even different extension of the class)

Any ideas?
 
Hi guys, does any of you have any experience with Concurrent programming in Swift/Objective-C? Im working on a JSON parser that needs to parse large arrays and performance on iPhone 4 with sequential parsing isnt very good. So im trying to get the parser to work by parsing the arrays in multiple threads, but my locks dont seem to work properly. Basically what I need is this:

Code:
func parseArray(jsonArray: [JSON]) -> [AnyObject] {
        var array = [AnyObject]()
        let size = count(jsonArray)
	var lockA = lock(0)// create Lock
	var lockB = lock(size)
        let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
        for var i = 0; i < size; i++
        {
            let index = i
            let jsonObject: JSON = jsonArray[index]
            dispatch_async(dispatch_get_global_queue(priority, 0)) {
                if let parsedObject : AnyObject = self.parseObject(jsonObject)
                {
                    wait(lockA)
                    if index < count(array) {
                         array.insert(parsedObject, atIndex: index)
                    } else {
                         array.append(parsedObject)
                    }
                    release(lockA)
		    release(lockB)
                } else {
                    release(lockB)
                }
            }
        }

        wait(lockB) // Wait untill all released
        return array
}

I tried using a dispatch_semaphore_create(1) for lockA and a dispatch_group_create() for lockB, but whatever I do lockB never seems to unlock, deadlocking the whole process. Note that this funcion may also be called by parseObject (on a different instance and usually even different extension of the class)

Any ideas?

Never used this language before so I really have no idea what I'm talking about. But why don't you pre-allocate `array` to have `size` elements in it, and then inside the dispatch function just say array = parsedObject. Then you can just delete `lockA` as nobody would ever be contending over the same destination index in `array`.

Not sure that would solve your problem, however.
 

Daeda

Member
Never used this language before so I really have no idea what I'm talking about. But why don't you pre-allocate `array` to have `size` elements in it, and then inside the dispatch function just say array = parsedObject. Then you can just delete `lockA` as nobody would ever be contending over the same destination index in `array`.

Not sure that would solve your problem, however.


I probably cant do that, simply because Swift forces you to declare nullable objects explicitly. E.g. either my array must always get filled with a default instance of the (expected) object, or I must make it nullable. Anyway, while not a bad idea in itself, this will probably still require lockB, as swift arrays get copied when passed along, so pointers might not hold. Although admittedly I could hack past that if I really want to.
 
I probably cant do that, simply because Swift forces you to declare nullable objects explicitly. E.g. either my array must always get filled with a default instance of the (expected) object, or I must make it nullable. Anyway, while not a bad idea in itself, this will probably still require lockB, as swift arrays get copied when passed along, so pointers might not hold. Although admittedly I could hack past that if I really want to.

How's the debugging experience with Swift? Are you positive that when the deadlock occurs, none of the dispatch threads are still running? Maybe one of the lockA's is never getting released, for example if one of the array operations throws an exception (are exceptions a thing in swift even?) Depending on how well the debugger works you could stop during the deadlock and make sure no threads are still blocked in one of the asynchronous functions.

BTW, minor style nitpick. You write release(lockB) as:

Code:
if x
    ...
    release(lockB)
else
    release(lockB)

Might as well write:

Code:
if x
    ...

release(lockB)
 
https://github.com/blog/2047-language-trends-on-github

f15e22b4-3b7f-11e5-9496-12b6d811f0ea.jpg


Remember this is just for Github from 2008-2015.

Python deserves better. Pearl's free fall nose dive tho lol.
 

injurai

Banned
Man Ruby and JS are so popular for two things I've never touched. But Python and Ruby are both kind of falling off. I wonder if that's due to node.js? Actually the most surprising thing to me is how much C is falling off. Maybe it's a closer race though, this graph isn't the greatest tbh.
 

Siphorus

Member
Hi guys/gals, I'm currently applying to some big companies for jobs/internships depending on when I graduate.

I've been studying cracking the coding interview, practicing some problems on hacker rank, and going through them with a whiteboard at home. I'm doing this roughly six hours a day and then working on my projects in the mean time to get everything wrapped up (resume/projects/interview question practice/linked-in) and start sending out my resume by 8/30.

Anyways, I was wondering if any of you have gone through the process at larger companies and have any insight or comments on what I might be missing, thanks!
 

Chris R

Member
I've really enjoyed working with C# unlike my time with Java/Groovy. I'm glad we are seeing it's upswing. Is mono the only major open source implementation of it?

Microsoft has some kind of agreement with Xamarin I believe, should really help spread the language outside of just Windows platform. No idea on the mono front though.
 

injurai

Banned
Microsoft has some kind of agreement with Xamarin I believe, should really help spread the language outside of just Windows platform. No idea on the mono front though.

That's pretty cool actually. Probably better than giving it to apache prematurely.
 
I expect C# to continue to rise with the new open source focus Microsoft has.

In terms of github relative contribs, I kind of expect it to level off near where it is at myself. On a broader scope I don't know if it will ever escape its image of "first class development ecosystem, but only on Windows". That's not fair to it, but that's the breaks.

I thought everyone loves python though

I don't think the issue is as much Ruby or Python declining as it is Node's developer ecosystem being massive and how for a lot of people Node is insanely productive for demo/proof of concept/fuckaround work that can transition into a management backed project later. I'd still prefer Python or Ruby for basic functional programming work-as I mentioned in a previous page, the kind of one-off work that 'glues' the rest of your work together.
 
I think most everyone is OK with PHP riding into the sunset.

BTW someone mentioned Rust a couple of pages ago. Messed around with it over the last two days, it's fabulous. The foreign function interface in particular is solving me some big problems on a side project that I had been putting off for weeks.
 
I think most everyone is OK with PHP riding into the sunset.

BTW someone mentioned Rust a couple of pages ago. Messed around with it over the last two days, it's fabulous. The foreign function interface in particular is solving me some big problems on a side project that I had been putting off for weeks.

FFI as in calling Rust from C or calling C from Rust?
 

Onemic

Member
I think most everyone is OK with PHP riding into the sunset.

BTW someone mentioned Rust a couple of pages ago. Messed around with it over the last two days, it's fabulous. The foreign function interface in particular is solving me some big problems on a side project that I had been putting off for weeks.

what would replace PHP?
 
what would replace PHP?
Basically anything. Python, ruby, java, go, etcetcetcetc

What will replace it? Nothing. PHP is already inferior to nearly all other popular languages (thanks for taking one for the team, Javascript!), and yet it is still widely used and deployed with no signs of slowing down.

It will never die.
 

Godslay

Banned
You are correct, PHP being #4 is another bad omen. Thankfully the cavalry is coming.

Java -> Go
Javascript -> (your favorite language thanks to WebAssembly)
PHP -> PHP, it will never die

As long as MS continues to make C# a world class language and puts some backing behind F#, I'll be happy.

I'm afraid Java and Javascript won't die. It's like this generations COBOL. They are everywhere.
 
As long as MS continues to make C# a world class language and puts some backing behind F#, I'll be happy.

I'm afraid Java and Javascript won't die. It's like this generations COBOL. They are everywhere.
Well, I do agree that they aren't going to vanish. Inertia is a hell of a thing.
 

Ke0

Member
Javascript will never die, even when WebAssembly takes off. Some people are masochists and like the misery! Like I said earlier, thankfully developers are starting to realise that Node isn't answer for everything.
 

Godslay

Banned
Well, I do agree that they aren't going to vanish. Inertia is a hell of a thing.

I saw a job for a COBOL programmer not too long ago.

Paid well too.

Not trying to make fun of COBOL, since it rules the world from a loc point of view and does it's job faithfully.

It's just amazing the legs that some of these languages have.
 
Javascript will never die, even when WebAssembly takes off. Some people are masochists and like the misery! Like I said earlier, thankfully developers are starting to realise that Node isn't answer for everything.
Well, never is a long time. It'll diminish a lot once it's no longer the only show in town, but it'll be a long, long time before it dies out entirely.

I eventually see Javascript being used as a gimmick, toy language for small projects. Sort of a curiosity, "they used to code with this?!"
 

Ke0

Member
On the frontend I don't see JS waning any time soon, especially with Google and Facebook backing it with Angular and React respectively. Then you have Ember 2.0 that's suppose to finally get itself together.

I just want Node and the whole JS on server side to die out and I'll be happy or at least the "hot new tech" appeal to go away.
 
On the frontend I don't see JS waning any time soon, especially with Google and Facebook backing it with Angular and React respectively. Then you have Ember 2.0 that's suppose to finally get itself together.

I just want Node and the whole JS on server side to die out and I'll be happy or at least the "hot new tech" appeal to go away.
JS on the server side is really only a thing because JS on the client side is the only show in town. Lots of developers => "we should use the same language on the server" => node.

JS on the client side will be on the downturn in 5 years, IMO. I want it to go faster, but it's going to take some time for WebAssembly to stabilize. We need a consistent (non-JS) way of accessing the DOM as well. Once we're there, JS loses its captive audience.

None of Angular/React/Ember are particularly good. But it's not their fault, they're trying to make a language that was designed in two weeks (and has never really been redesigned!) do some crazy things.
 
Top Bottom