• 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

N

NinjaFridge

Unconfirmed Member
To get an indvidual character of a string, you can use
Code:
myString.charAt(index)

You'll also need to know that the numerical value of a character in Java is its ascii value. So basically all you need to do is cast the character to int, and you'll have the ascii value.

I assume anArray is specific to the problem you're trying to solve?

If I understand things correctly, you'll need a for-loop that wraps the code you have, going through the input string and setting the m value for each index.

I'm working on RSA for a group project. The anArray contains the binary for the value of e(27) which is used in part of the calculation for encrypting the letter.

I think I've made some progress. I'm in a better position than I was in yesterday which is good.


Thanks for the help btw.
 

Jokab

Member
I'm working on RSA for a group project. The anArray contains the binary for the value of e(27) which is used in part of the calculation for encrypting the letter.

I think I've made some progress. I'm in a better position than I was in yesterday which is good.


Thanks for the help btw.

No problem. Feel free to ask if you need more help.
 

upandaway

Member
How do you guys feel about comments? Can there be too much?

If there's a particularly messy line I can see myself adding like 3 lines of comments for it (say 15 words per line). Sure I try to write clear code but sometimes I hit a wall. I'm also not that smart so maybe just having a full explanation in English is better. But I don't know if this is okay to do.
 
How do you guys feel about comments? Can there be too much?

If there's a particularly messy line I can see myself adding like 3 lines of comments for it (say 15 words per line). Sure I try to write clear code but sometimes I hit a wall. I'm also not that smart so maybe just having a full explanation in English is better. But I don't know if this is okay to do.

Well a good rule of thumb is that if you have to spend time explaining why and how some piece of code does something instead of just declaring what it does it's probably better to refactor the code.
 

CrankyJay

Banned
How do you guys feel about comments? Can there be too much?

If there's a particularly messy line I can see myself adding like 3 lines of comments for it (say 15 words per line). Sure I try to write clear code but sometimes I hit a wall. I'm also not that smart so maybe just having a full explanation in English is better. But I don't know if this is okay to do.

Break out complex lines into simpler sub tasks if you can. Better for readability and debugging.

I also don't comment obviously readable code.
 
How do you guys feel about comments? Can there be too much?

If there's a particularly messy line I can see myself adding like 3 lines of comments for it (say 15 words per line). Sure I try to write clear code but sometimes I hit a wall. I'm also not that smart so maybe just having a full explanation in English is better. But I don't know if this is okay to do.

I don't comment individual lines. I'll document the method/function itself with a statement of purpose, the expected input, and the expected output. If the code has any side-effects on any passed in objects such as when doing an in-place sort on the array passed in, I document that.

The reason for doing this is for documentation generators like doxygen, pydoc, javadoc, jsdoc, etc.. That way I can provide users of the API a way to use the classes, functions. etc without always having to go into the code.
 

Jokab

Member
Well a good rule of thumb is that if you have to spend time explaining why and how some piece of code does something instead of just declaring what it does it's probably better to refactor the code.

I don't think there is anything wrong with explaining why the original programmer wrote the code in a certain way, or why that approach was chosen. However if you need to explain what the code is doing, it's probably bad code. Of course there are exceptions, like a complex mathematical function that is difficult to understand without specific domain knowledge.

The book Clean Code has a great section on this which really illuminated the subject for me. I encourage everyone to read it.
 

tuffy

Member
How do you guys feel about comments? Can there be too much?
If the logic of a function is especially complex, I'll write the comments first and fill it in with the implementation later. I can sometimes catch something that's not going to work at that phase and then reorganize it before I really get started.
 

iapetus

Scary Euro Man
Well a good rule of thumb is that if you have to spend time explaining why and how some piece of code does something instead of just declaring what it does it's probably better to refactor the code.

// This may look redundant, but if we don't do it, some Android 2.3 devices get very glitchy...

How exactly would you refactor a simple line that follows that comment? And if you don't comment that sort of thing, it gets removed, and a host of target devices stop working.

Also often worth commenting are calls to APIs with counterintuitive behaviour or unexpected return types. Sure, the documentation is probably there already, but in practice people are unlikely to read it.
 

Kansoku

Member
One problem that I have and that most of my teachers complain is that I don't comment. I just don't know how to. I could understand a comment on the beginning of the code, giving an overview of the code, but other than that, just reading the code will tell you what it does.
 

oxrock

Gravity is a myth, the Earth SUCKS!
After several hours of coding my brain just turns to mush with mental fatigue. I don't know how prevalent this is, but it pretty happens whenever i focus intently on something for several hours I guess. My question is, what do other people do to combat the mental mush? Or am I alone in this?
 

convo

Member
I have a simple question about member variables.
Suppose i want member variable in Class A, that just holds an address.
I would use int *address as a member probably in public.
Now would i access it through A.address or A.*address to return me an address?
 

Water

Member
After several hours of coding my brain just turns to mush with mental fatigue. I don't know how prevalent this is, but it pretty happens whenever i focus intently on something for several hours I guess. My question is, what do other people do to combat the mental mush? Or am I alone in this?
Take breaks. Break = get up and do something besides staring at a computer screen. I force myself to do that by using a timer. Without that kind of external aid, when I notice my brain has turned to mush, I have already wasted an hour at least.

Some particularly effective things to do on breaks: take a nap, exercise (even a little), meditate.
 

Jokab

Member
One problem that I have and that most of my teachers complain is that I don't comment. I just don't know how to. I could understand a comment on the beginning of the code, giving an overview of the code, but other than that, just reading the code will tell you what it does.

From my experience, teachers tell you to comment because they want to see that you understand what you've written. The kind of commenting they presumably want you to do is probably nothing to strive for in personal or professional projects because there is a ton of redundancy.
 

Water

Member
I have a simple question about member variables.
Suppose i want member variable in Class A, that just holds an address.
I would use int *address as a member probably in public.
Now would i access it through A.address or A.*address to return me an address?
With simple syntax questions like this, just go ahead and try it. In this case, one of those won't even compile so you'll know immediately. Faster than posting.
 

iapetus

Scary Euro Man
Take breaks. Break = get up and do something besides staring at a computer screen. I force myself to do that by using a timer. Without that kind of external aid, when I notice my brain has turned to mush, I have already wasted an hour at least.

Some particularly effective things to do on breaks: take a nap, exercise (even a little), meditate.

This, this and thrice this. Some people are afraid of taking breaks, and think that not working is wasted time. I've had an awful lot of inspired coding breakthroughs while taking a break...
 

maeh2k

Member
Has anyone of you ever worked at a place where they actually practiced Extreme Programming (including Pair Programming)?

I've applied for a job at a couple of companies including one that focuses on agile development. They do Pair Programming, Test Driven Development, Clean Code...

However, I haven't done any Pair Programming before. On one hand, I think this might be a good job for me, since I always liked collaboration in college projects and I like what I've read about TDD (never really used that either). Might be a good place to learn.
On the other hand, I'm not sure how I feel about working in pairs all the time. Maybe I work better alone. Maybe it would drive me insane :)

I already have a job offer at another place that might be a safer bet, but I've recently read quite a bit about Clean Code and Test Driven Development that resonated with me and there's a chance that agile company might be a good fit for me.


So, any experiences or opinions on that type of development?
 

Magni

Member
Has anyone of you ever worked at a place where they actually practiced Extreme Programming (including Pair Programming)?

I've applied for a job at a couple of companies including one that focuses on agile development. They do Pair Programming, Test Driven Development, Clean Code...

However, I haven't done any Pair Programming before. On one hand, I think this might be a good job for me, since I always liked collaboration in college projects and I like what I've read about TDD (never really used that either). Might be a good place to learn.
On the other hand, I'm not sure how I feel about working in pairs all the time. Maybe I work better alone. Maybe it would drive me insane :)

I already have a job offer at another place that might be a safer bet, but I've recently read quite a bit about Clean Code and Test Driven Development that resonated with me and there's a chance that agile company might be a good fit for me.


So, any experiences or opinions on that type of development?

I work at a startup and pair pretty much 90+% of the time. I definitely prefer it to programming solo, you tend to avoid going down stupid roads, and when you just start a new company it helps learning the codebase with someone who's had a bit more experience.
 

0xCA2

Member
Yeah, that's exactly what I meant. Understand that the really important thing about this is that the rule objects are created inside the loading code - that is what allows the main part of your game logic to be ignorant of the specifics of each level. It's best to start by just hardcoding the rule object creation in the level loading code. Loading them based on file contents is not essential, but organizing your code like this lets you easily do loading from file at any later point if you want to.

So I've figured out what my deeper problem was and I want to thank you (and everyone who helped) for even leading me to this path. I needed to learn about Design Patterns.

For anyone else having these problems, I found a book online that seems to solve every single problem I was having with game programming (not just the one I asked about), if not programming in general.

It's a book by a (former?) AAA programmer called Game Programming Patterns , and it has a specific chapter on observers and event queues. Lots of information and examples and it's a great read so far.
 

upandaway

Member
So I've figured out what my deeper problem was and I want to thank you (and everyone who helped) for even leading me to this path. I needed to learn about Design Patterns.

For anyone else having these problems, I found a book online that seems to solve every single problem I was having with game programming (not just the one I asked about), if not programming in general.

It's a book by a (former?) AAA programmer called Game Programming Patterns , and it has a specific chapter on observers and event queues. Lots of information and examples and it's a great read so far.
Oh hey, that's where I went to read about state machines in gaming. Really helped me out. I ended up turning something that seemed really complicated into something super simple.
 

Slavik81

Member
// This may look redundant, but if we don't do it, some Android 2.3 devices get very glitchy...

How exactly would you refactor a simple line that follows that comment? And if you don't comment that sort of thing, it gets removed, and a host of target devices stop working.

Also often worth commenting are calls to APIs with counterintuitive behaviour or unexpected return types. Sure, the documentation is probably there already, but in practice people are unlikely to read it.
I've seen functions like this before:
setXForGlitchyAndroidDevices()

In any case, I'd agree with it as a rule of thumb. Obviously, there are many exceptions, but it's a good prompt for you to think about your code.
 

mltplkxr

Member
So I've figured out what my deeper problem was and I want to thank you (and everyone who helped) for even leading me to this path. I needed to learn about Design Patterns.

For anyone else having these problems, I found a book online that seems to solve every single problem I was having with game programming (not just the one I asked about), if not programming in general.

It's a book by a (former?) AAA programmer called Game Programming Patterns , and it has a specific chapter on observers and event queues. Lots of information and examples and it's a great read so far.

I think it's great that you found out about design patterns after hitting your head against the wall on certain design issues. It's the best way to learn.
 
// This may look redundant, but if we don't do it, some Android 2.3 devices get very glitchy...

How exactly would you refactor a simple line that follows that comment? And if you don't comment that sort of thing, it gets removed, and a host of target devices stop working.

Also often worth commenting are calls to APIs with counterintuitive behaviour or unexpected return types. Sure, the documentation is probably there already, but in practice people are unlikely to read it.

Well, I meant to add that that's exactly the kind of behaviour that NEEDS to be commented but that got lost in the gibberish I wrote alongside of it so my bad :p

That said, if you know why the simple line is needed (unless it's magic) you could just change the comment to //Android 2.3.2 electric boogaloo specific fix @source.com/why so I don't actually have to remove that line, take a Android device and see what happens.
 

Slavik81

Member
So, any experiences or opinions on that type of development?
I can't stand pair programming. I've found it to be incredibly tedious coming to agreement about every little detail. You put two programmers together, and they operate at half the speed of a single programmer. Yes, the quality is more consistent, but I would only do it for training up beginners, or building key components of a feature/system. Any more than a few days in a row and I'd go batty.

That said, all the other attributes you listed a great things. Working with tested, well-factored code is a lot less frustrating.
 

Water

Member
I can't stand pair programming. I've found it to be incredibly tedious coming to agreement about every little detail. You put two programmers together, and they operate at half the speed of a single programmer. Yes, the quality is more consistent, but I would only do it for training up beginners, or building key components of a feature/system. Any more than a few days in a row and I'd go batty.
I think doing it now and then is good, and not just for training beginners. Everyone is a beginner in some tech, in some corner of the codebase they haven't previously dealt with, or shaky on some process. I haven't done a ton of PP, but when I have, it has always been helpful; a few hours a week sprinkled here and there feels about right. I'd reserve PP for tasks that are not trivial for the programmers.

To me it sounds like a mistake to try to come to agreement about every little detail. Between two non-beginners the pair programming work should be asymmetric, like pilot/navigator. One guy has their head in the code detail, and the other looks at the bigger picture, thinks ahead to the next task, makes sure they understand the code being written, considers/brings up issues. (Actual bugs, potential bugs, things that break project style guidelines, or things that could clearly be better - not stuff that is a matter of taste.)
 

poweld

Member
I think doing it now and then is good, and not just for training beginners. Everyone is a beginner in some tech, in some corner of the codebase they haven't previously dealt with, or shaky on some process. I haven't done a ton of PP, but when I have, it has always been helpful; a few hours a week sprinkled here and there feels about right. I'd reserve PP for tasks that are not trivial for the programmers.

To me it sounds like a mistake to try to come to agreement about every little detail. Between two non-beginners the pair programming work should be asymmetric, like pilot/navigator. One guy has their head in the code detail, and the other looks at the bigger picture, thinks ahead to the next task, makes sure they understand the code being written, considers/brings up issues. (Actual bugs, potential bugs, things that break project style guidelines, or things that could clearly be better - not stuff that is a matter of taste.)

couldn't agree more. i think that it has uses - my favorite is the one you mentioned, when working with a corner of the codebase you have no experience with, and don't have time to gain a deep understanding for it at the moment. i'd grab the correct dev to sit with me for an hour or two and 9 times out of 10 the problem will get solved way faster than if i'd tried it myself.
 

squidyj

Member
Has anyone used glew with qt? I am having the worst time getting it to link, either using msvc compiler or after building the libraries with mingw. I am stuck in a hell of unresolved external symbols
 

Slavik81

Member
Has anyone used glew with qt? I am having the worst time getting it to link, either using msvc compiler or after building the libraries with mingw. I am stuck in a hell of unresolved external symbols
Are they glew symbols or QObject symbols? The latter is often caused by forgetting to build or link the moc's generated files.
 

sdijoseph

Member
Quick question: Can strings include endl or \n? I know this is a weird question, but in this project I am working on I see the data is displaying two new lines and I can't seem to find where the extra new line is coming from.
 

Rapstah

Member
Quick question: Can strings include endl or \n? I know this is a weird question, but in this project I am working on I see the data is displaying two new lines and I can't seem to find where the extra new line is coming from.

Yes, that's a character. All kinds of crazy shit can be in just ASCII. I've had UART serial transmissions printing on a terminal on a computer and suddenly the text starts going upwards because the hardware sending the signals bugged out.
 
Had an internship interview at a startup on the 13th of March. Went well, and they were almost talking like they had already decided to hire me and just needed to go through the formalities. Was told "we'll get back to you within a few days, because we don't want to leave you hanging".

Nearly three weeks later, and they still haven't gotten back to me. Ugh. I sent a follow up/thank you note on the two week mark, but they haven't responded to that either. Really frustrating. I'm okay with waiting that long if they had just been honest up front about the wait, rather then saying "we'll get back with you in a few days". Or followed up during that time frame to tell me that it was going to be longer. Or just emailed me to tell me that they aren't going to hire me.

I have some other possible opportunities for the summer, although that was my first choice. Need to get it all sorted out soon, though. For those with more experience with job hunting in programming careers, do you think it would be too forward to send a second follow up mentioning that I have some other opportunities (not offers yet, per se, more of open doors at two places), and that I need to make the decision soon?
 
Had an internship interview at a startup on the 13th of March. Went well, and they were almost talking like they had already decided to hire me and just needed to go through the formalities. Was told "we'll get back to you within a few days, because we don't want to leave you hanging".

Nearly three weeks later, and they still haven't gotten back to me. Ugh. I sent a follow up/thank you note on the two week mark, but they haven't responded to that either. Really frustrating. I'm okay with waiting that long if they had just been honest up front about the wait, rather then saying "we'll get back with you in a few days". Or followed up during that time frame to tell me that it was going to be longer. Or just emailed me to tell me that they aren't going to hire me.

I have some other possible opportunities for the summer, although that was my first choice. Need to get it all sorted out soon, though. For those with more experience with job hunting in programming careers, do you think it would be too forward to send a second follow up mentioning that I have some other opportunities (not offers yet, per se, more of open doors at two places), and that I need to make the decision soon?

Don't wait on them. Either they went a different direction or their decision making is tied up in some bureaucratic mess, or perhaps they've even pulled the position. If another opportunity for experience comes along, take it. They might be your first choice, but don't get stuck with no choice at all.
 
Don't wait on them. Either they went a different direction or their decision making is tied up in some bureaucratic mess, or perhaps they've even pulled the position. If another opportunity for experience comes along, take it. They might be your first choice, but don't get stuck with no choice at all.

Agreed, good advice. The other two positions are at places I've previously interned at, who have told me that they would love to have me back this summer. They weren't great experiences, though, and I'd rather not go back. (I will if nothing else presents itself, though.)

I've applied at a ton of other places as well, but haven't had any luck yet, besides the two places I used to work at and this startup. The clock is ticking though, so I'll probably just follow up with one of the other two places and get the ball rolling there. If the startup contacts me before I accept an offer, then I can go with them.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Speaking of internships, when did you guys first start working / interning in the programming field?

I am coming up on finishing my first year in college, and I was wondering if it would be too early to search.

Agreed, good advice. The other two positions are at places I've previously interned at, who have told me that they would love to have me back this summer. They weren't great experiences, though, and I'd rather not go back. (I will if nothing else presents itself, though.)

I've applied at a ton of other places as well, but haven't had any luck yet, besides the two places I used to work at and this startup. The clock is ticking though, so I'll probably just follow up with one of the other two places and get the ball rolling there. If the startup contacts me before I accept an offer, then I can go with them.

I think this is a great decision. Like Randolph said, it is better to have the options there for you then to be stuck with nothing while trying for a certain place. The only thing I would recommend is to follow up with both of them, not just one.
 
Speaking of internships, when did you guys first start working / interning in the programming field?

I am coming up on finishing my first year in college, and I was wondering if it would be too early to search.

I'm a junior, and I've had an internship between freshman/sophomore and sophomore/junior years. I'd say definitely try and find one, if you can. A lot of places do prefer sophomores and juniors, but there are places that accept freshmen interns (at least in my limited experience). You probably wouldn't have as much responsibility as the sophomore/junior interns, but it's still possible to get one. I'd say definitely try looking, it doesn't hurt to apply.

I think this is a great decision. Like Randolph said, it is better to have the options there for you then to be stuck with nothing while trying for a certain place. The only thing I would recommend is to follow up with both of them, not just one.

Yeah, good points, thanks.
 

sdijoseph

Member
Yes, that's a character. All kinds of crazy shit can be in just ASCII. I've had UART serial transmissions printing on a terminal on a computer and suddenly the text starts going upwards because the hardware sending the signals bugged out.

Alright, thanks. I found out my getline function was collecting \n characters for some reason, but I found a way to get rid of them.
 

GK86

Homeland Security Fail
Any good sites to practice catching syntax errors? I have a test soon and I want to practice as much as possible.
 

usea

Member
Any good sites to practice catching syntax errors? I have a test soon and I want to practice as much as possible.
What language?

Type in notepad and then try to compile your code? Or if it's not compiled, a linter or parser?
 
Speaking of internships, when did you guys first start working / interning in the programming field?

I am coming up on finishing my first year in college, and I was wondering if it would be too early to search.
Never too early - good on you for being proactive! Don't feel like you don't have a shot, there are places that look specifically for underclassmen. I know there is at least the Microsoft Explore program which is for freshman (probably too late for you this year though, I think you want to apply in the fall) and sophomores. I'm sure the other big tech companies have something similar, and there are bound to be opportunities at smaller places as well, particularly locally, hit up your department's career services.

Getting any professional experience now will only open even bigger and better doors throughout the rest of your college career - I'm jealous you have this chance, I started CS halfway into my uni time and wish I would have had a full four years of opportunities, there are so so many.
 

NotBacon

Member
Speaking of internships, when did you guys first start working / interning in the programming field?

I am coming up on finishing my first year in college, and I was wondering if it would be too early to search.

I have another year until I get my transfer degree (to uni), and I've already been coding at a startup for months now. Go for it.

Also talk to your CS/Engineering advisor, I swear mine is posting up new flyers for jobs and internships every week and he always seems glad to help.
 

sdijoseph

Member
Code:
Name     Description  Category  Priority      Time    Status     Start Date       Due Date      Resources:

Objective1  Descrip1         2         4        56         C         1/9/13         9/5/7       Money       Truck
Task1  Descrip1         1/9/13         9/5/7        33         N        Res2        Res1
Task1A Descrip1A         1/9/13         9/5/7        33         N        Res2        Res1

Objective2  Descrip2         3         3        75         C         3/9/13         3/8/14    Internet       Paper    Notebook
Task2  Descrip1         1/9/13         9/5/7        33         N        Res4        Res3
Task2A Descrip2A         1/9/13         9/5/7        33         N        Res2        Res1

Objective3  Descrip3         1         5        87         C         5/3/13         8/4/14
Task3  Descrip1         1/9/13         9/5/7        33         N        Res6        Res5
Task3A Descrip3A         1/9/13         9/5/7        33         N        Res2        Res1

Objective4  Descrip4         4         1        87         N         5/9/7         8/2/13       Fruit       Pizza
Task4  Descrip1         1/9/13         9/5/7        33         N        Res8        Res7
Task4A Descrip4A         1/9/13         9/5/7        33         N        Res2        Res1

Objective5  Descrip5         1         4        87         N         4/9/12         8/4/6       Fruit
Task5  Descrip1         1/9/13         9/5/7        33         N        ResH        Res9
Task5A Descrip5A         1/9/13         9/5/7        33         N        Res2        Res1

So I am still working on this project, and my output of the program data to the console is the mess you see above. The output display is tricky because the program needs to accept names, descriptions, and resources that vary in size. I was wondering if there was a clever way to set the setw() function for displaying the header and data so that it was based on the size of the strings. If so, do I just need to try implementing the solution through trial and error (by seeing when the display looks acceptable), or is there a better way to do it? Also, please note that I know I a need to change the order of output for the tasks underneath the objectives to match the header. Thanks for any help!
 

usea

Member
I spent half the day fighting time zone issues. I thought I had fixed them yesterday, but they were back today.

The problem was actually that when I changed to testing against the production database (with readonly access), I forgot my user on the production database had a different timezone set. And that's why all the times were wrong.

-------------________________-----------------------------------------------
 

Water

Member
Any good sites to practice catching syntax errors? I have a test soon and I want to practice as much as possible.

You grow to spot syntax errors over time; it's not something you should practice separately. Just code stuff with what you've learned. If you don't feel like improvising, re-do previous exercises from scratch without referring to your previous solution. Don't reflexively compile every two seconds and see what happens - always figure out what you expect to happen first.
 

iapetus

Scary Euro Man
You grow to spot syntax errors over time; it's not something you should practice separately.

If you use a halfway decent IDE spotting syntax errors is even easier, too, as they'll have some manner of big red marker to point them out. :p
 
Top Bottom