• 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

What does the code for the animation constructor and getShape methods look like?
I just found the error. When I call the constructor like this:
Code:
sf::CircleShape* circle = new sf::CircleShape(23.0f);
circle->setFillColor(sf::Color::Black);
animation animation(sf::Vector2f(15.f, 15.f), sf::Vector2f(15.f, 150.f), circle, 1.0f);
it works. However, when I try to pass the address of the shape stored in one of my enemy objects (&enemy.getShape() instead of circle as the shape argument) it crashes with that misleading error message. (something about a pure virtual function call) Interestingly, MSVC++ lets you take the address of a temporary object like that and won't even write a warning. clang++ and g++ don't even let you compile it.
 
Hey guys. I've just started with programming (python) and I know this is probably a really stupid question, but can anyone help me with this?

a = 95
b = 63
a += b
b += a

What is b? I've tried everything but I keep getting the wrong answer.
 
Hey guys. I've just started with programming (python) and I know this is probably a really stupid question, but can anyone help me with this?

a = 95
b = 63
a += b
b += a

What is b? I've tried everything but I keep getting the wrong answer.
Here's a hint:

x += y

is the same as

x = x + y
 

Haly

One day I realized that sadness is just another word for not enough coffee.
a = 95
b = 63
a += b is equivalent to a = 95 + 63 = 158
b += a is equivalent to b = 63 + 158 = 222
 
Out of interest, what ended up being the aspect that prevented you from figuring it out?

The tutorial I was reading didn't explain it well. I guess I was thinking too much like math. I wasn't quite sure what "a += b" meant and Google did me no favours. I imagined that a = a and b = b, but if a = a + b then that is of course not the case, unless b = 0. I tried a few different combinations, such as 95 + 63, and then that number + 95 (a + b + a, or 2a + b).

I see now that a = a + b and b = b + a. The number a changes, and I suppose that was the big issue I had.
 

usea

Member
The tutorial I was reading didn't explain it well. I guess I was thinking too much like math. I wasn't quite sure what "a += b" meant and Google did me no favours. I imagined that a = a and b = b, but if a = a + b then that is of course not the case, unless b = 0. I tried a few different combinations, such as 95 + 63, and then that number + 95 (a + b + a, or 2a + b).

I see now that a = a + b and b = b + a. The number a changes, and I suppose that was the big issue I had.
Ah, yeah. = is the assignment operator/statement. It's not a statement of equality like in math. It changes the value of the variable on the left to be equal to the expression on the right.

For example, if you put this it wouldn't even compile (in most languages). Because you can't change the value of 3 (even to itself).
Code:
3 = 3

http://en.wikipedia.org/wiki/Assignment_operator#Assignment_versus_equality You're not alone in being confused.
 

iapetus

Scary Euro Man
If you want to confuse yourself more, throw in some unary operators. :)

int a = 36;
int b = 17;
a += ++a + b++;
b += a++ + ++b;
 
If you want to confuse yourself more, throw in some unary operators. :)

int a = 36;
int b = 17;
a += ++a + b++;
b += a++ + ++b;
Thats so evil.

But to add to the discussion it's incredibly useful and helpful. I use them to keep statements more concise, unambiguous and I find it easier to read.
 
Can someone give me a hand with using Python. I've downloaded Python and Notepad++. Opening the programs work well. But when I write a code in Notepad++ and save it as a ".py" file it doesn't work to open in Python. Or rather, it seemingly stays open for like a fraction of a second and then shuts itself down.
 

injurai

Banned
Can someone give me a hand with using Python. I've downloaded Python and Notepad++. Opening the programs work well. But when I write a code in Notepad++ and save it as a ".py" file it doesn't work to open in Python. Or rather, it seemingly stays open for like a fraction of a second and then shuts itself down.

oh, yeah it's just executing to completion then closing before you can really see it's output.

You can enforce a wait for input or something at the end, I don't use python much but I remember running into this.
 

Zoe

Member
at the end

a == 91
b == 127

I got 90 and 125. (edit: whoops, forgot a increments in the second statement, and I was working off the original value of b in the second)

I'm a little uncertain on whether += always uses the original value, but don't forget that post++ and pre++ are different.
 

Tamanon

Banned
Can someone give me a hand with using Python. I've downloaded Python and Notepad++. Opening the programs work well. But when I write a code in Notepad++ and save it as a ".py" file it doesn't work to open in Python. Or rather, it seemingly stays open for like a fraction of a second and then shuts itself down.

It's working, the console just closes.

Add this line at the end of your programs for now:
Code:
raw_input()

This will leave the console open to view your stuff until you hit enter.

Alternatively, do your start in IDLE, the built-in Python editor. That way when you run from there, it opens in a console shell that stays open.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
If you want to confuse yourself more, throw in some unary operators. :)

int a = 36;
int b = 17;
a += ++a + b++;
b += a++ + ++b;

a == 36
b == 17

a += (++a) + (b++)
==
a = a + (++a) + (b++)
==
a = 36 + 37 + 17, a == 90, b == 18

b += (a++) + (++b)
==
b = b + (a++) + (++b)
==
b = 18 + 90 + 19, b == 127, a == 91

Is this right?
 

injurai

Banned
I got 90 and 125. (edit: whoops, 91, forgot a increments in the second statement)

I'm a little uncertain on whether += always uses the original value, but don't forget that post++ and pre++ are different.

don't forget?

I think you forgot!!!

a == 36
b == 17

a += (++a)+ (b++)
==
a = a + (++a) + (b++)
==
a = 36 + 37 + 17, a == 90, b == 18

b += (a++) + (++b)
==
b = b + (a++) + (++b)
==
b = 18 + 90 + 19, b == 127, a == 91

Is this right?

Yeah, that's what I did.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Also this should be established as a war crime.
 
a == 36
b == 17

a += (++a) + (b++)
==
a = a + (++a) + (b++)
==
a = 36 + 37 + 17, a == 90, b == 18

b += (a++) + (++b)
==
b = b + (a++) + (++b)
==
b = 18 + 90 + 19, b == 127, a == 91

Is this right?

I was curious, so I compiled it in Visual Studio:
Code:
#include "stdafx.h"
#include <iostream>

using std::cout; using std::endl;

int main(int argc, char **argv)
{
	int a = 36;
	int b = 17;
	a += ++a + b++;
	b += a++ + ++b;
	cout << "a = " << a << endl;
	cout << "b = " << b << endl;
	getchar();
	return 0;
}
Output is
Code:
a = 92
b = 129

Don't ask me how this comes to be, your solution seems pretty intuitive to me.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Well now my programming confidence is totally shattered.
 

Leezard

Member
a == 36
b == 17

a += (++a) + (b++)
==
a = a + (++a) + (b++)
==
a = 36 + 37 + 17, a == 90, b == 18

b += (a++) + (++b)
==
b = b + (a++) + (++b)
==
b = 18 + 90 + 19, b == 127, a == 91

Is this right?
The first one should be a=37+37+17==91,b==18.
Second should be b=19+91+19==129,a==92.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
The first one should be a=37+37+17==91,b==18.
Second should be b=19+91+19==129,a==92.

So you're saying

a += (++a) + (b++)

...actually expands to...

a = (++a) + (b++) + a?

That's the only way I can imagine it working out to 92.
 

Leezard

Member
So you're saying

a += (++a) + (b++)

...actually expands to...

a = (++a) + (b++) + a?

That's the only way I can imagine it working out to 92.
It does not matter if you type a + ++a or ++a + a, the ++ increases a by one before the statement is evaluated.
Edit: The statement
a = a + (b++) + ++a
Is equal to
++a;
a = a + (b++) + a;
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Okay, I see. So pre-increment is evaluated before any unary operation in a statement.
 
oh, yeah it's just executing to completion then closing before you can really see it's output.

You can enforce a wait for input or something at the end, I don't use python much but I remember running into this.

It's working, the console just closes.

Add this line at the end of your programs for now:
Code:
raw_input()

This will leave the console open to view your stuff until you hit enter.

Alternatively, do your start in IDLE, the built-in Python editor. That way when you run from there, it opens in a console shell that stays open.

Thanks. I tried adding that line to the end but it changed nothing. Using IDLE worked great though.
 

injurai

Banned
Well now my programming confidence is totally shattered.

It does not matter if you type a + ++a or ++a + a, the ++ increases a by one before the statement is evaluated.
Edit: The statement
a = a + (b++) + ++a
Is equal to
++a;
a = a + (b++) + a;

Okay, I see. So pre-increment is evaluated before any unary operation in a statement.

the nuances of programming amaze me, thanks for the moment of clarity
 
I'm running a MERGE to update/insert data into a table as it comes in. I'm not sure how I can prevent this deadlock from occurring or minimize it's occurrence.

Code:
<deadlock-list>
 <deadlock victim="process176af4988">
  <process-list>
   <process id="process176af4988" taskpriority="0" logused="1028" waitresource="KEY: 9:72057594041663488 (266fc93ba77f)" waittime="414" ownerId="20808905" transactionname="implicit_transaction" lasttranstarted="2013-07-18T14:42:31.483" XDES="0x19115b950" lockMode="U" schedulerid="4" kpid="8736" status="suspended" spid="134" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2013-07-18T14:42:31.483" lastbatchcompleted="2013-07-18T14:42:31.480" clientapp="jTDS" hostname="CLDEV4" hostpid="123" loginname="PANS_USER" isolationlevel="read committed (2)" xactid="20808905" currentdb="9" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
    <executionStack>
     <frame procname="CATE.dbo.pr_mergeCurrentPosition" line="24" stmtstart="1116" sqlhandle="0x03000900fd706e5bbc5df000ffa100000100000000000000">
MERGE
	CATE.dbo.CURRENT_POSITION_AIS WITH (UPDLOCK) AS cpa
USING (
	VALUES(@mmsiNbr)
) AS cpatemp (mmsi_nbr)
ON cpa.mmsi_nbr = cpatemp.mmsi_nbr
WHEN MATCHED THEN 
	UPDATE SET nav_status = @navStatus, rot = @rot, sog = @sog, pos_accuracy = @posAccuracy, lat = @lat,
	lon = @lon, cog = @cog, true_heading = @trueHeading, time_stamp_sec = @timeStampSec, special_maneuver_ind = @specialManeuverInd,
	raim_flag = @raimFlag, comm_state = @commState, updt_dt = @updtDt, position = @position,
	imo_nbr = @imoNbr, call_sign = @callSign, vessel_name = @vesselName
WHEN NOT MATCHED THEN	
	INSERT (mmsi_nbr,nav_status,rot,sog,pos_accuracy,lat,lon,cog,true_heading,time_stamp_sec,special_maneuver_ind,raim_flag,comm_state,updt_dt,position,
	imo_nbr, call_sign, vessel_name)
	VALUES(@mmsiNbr,@navStatus,@rot,@sog,@posAccuracy,@lat,@lon,@cog,@trueHeading,@timeStampSec,@specialManeuverInd,@raimFlag,@commState,@updtDt,@position,
	@imoNbr, @callSign, @vesselName)
;     </frame>
    </executionStack>
    <inputbuf>
Proc [Database Id = 9 Object Id = 1533964541]    </inputbuf>
   </process>
   <process id="process52dddc8" taskpriority="0" logused="29980" waitresource="KEY: 9:72057594041663488 (a8535ed1a10a)" waittime="387" ownerId="20808883" transactionname="implicit_transaction" lasttranstarted="2013-07-18T14:42:31.470" XDES="0x96688e80" lockMode="U" schedulerid="8" kpid="5256" status="suspended" spid="133" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2013-07-18T14:42:31.470" lastbatchcompleted="2013-07-18T14:42:31.460" clientapp="jTDS" hostname="CLDEV4" hostpid="123" loginname="PANS_USER" isolationlevel="read committed (2)" xactid="20808883" currentdb="9" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128058">
    <executionStack>
     <frame procname="CATE.dbo.pr_mergeCurrentPosition" line="24" stmtstart="1116" sqlhandle="0x03000900fd706e5bbc5df000ffa100000100000000000000">
MERGE
	CATE.dbo.CURRENT_POSITION_AIS WITH (UPDLOCK) AS cpa
USING (
	VALUES(@mmsiNbr)
) AS cpatemp (mmsi_nbr)
ON cpa.mmsi_nbr = cpatemp.mmsi_nbr
WHEN MATCHED THEN 
	UPDATE SET nav_status = @navStatus, rot = @rot, sog = @sog, pos_accuracy = @posAccuracy, lat = @lat,
	lon = @lon, cog = @cog, true_heading = @trueHeading, time_stamp_sec = @timeStampSec, special_maneuver_ind = @specialManeuverInd,
	raim_flag = @raimFlag, comm_state = @commState, updt_dt = @updtDt, position = @position,
	imo_nbr = @imoNbr, call_sign = @callSign, vessel_name = @vesselName
WHEN NOT MATCHED THEN	
	INSERT (mmsi_nbr,nav_status,rot,sog,pos_accuracy,lat,lon,cog,true_heading,time_stamp_sec,special_maneuver_ind,raim_flag,comm_state,updt_dt,position,
	imo_nbr, call_sign, vessel_name)
	VALUES(@mmsiNbr,@navStatus,@rot,@sog,@posAccuracy,@lat,@lon,@cog,@trueHeading,@timeStampSec,@specialManeuverInd,@raimFlag,@commState,@updtDt,@position,
	@imoNbr, @callSign, @vesselName)
;     </frame>
    </executionStack>
    <inputbuf>
Proc [Database Id = 9 Object Id = 1533964541]    </inputbuf>
   </process>
  </process-list>
  <resource-list>
   <keylock hobtid="72057594041663488" dbid="9" objectname="CATE.dbo.CURRENT_POSITION_AIS" indexname="CURRENT_POSITION_AIS_PK" id="locke97e7a80" mode="X" associatedObjectId="72057594041663488">
    <owner-list>
     <owner id="process52dddc8" mode="X"/>
    </owner-list>
    <waiter-list>
     <waiter id="process176af4988" mode="U" requestType="wait"/>
    </waiter-list>
   </keylock>
   <keylock hobtid="72057594041663488" dbid="9" objectname="CATE.dbo.CURRENT_POSITION_AIS" indexname="CURRENT_POSITION_AIS_PK" id="lock101f14a00" mode="X" associatedObjectId="72057594041663488">
    <owner-list>
     <owner id="process176af4988" mode="X"/>
    </owner-list>
    <waiter-list>
     <waiter id="process52dddc8" mode="U" requestType="wait"/>
    </waiter-list>
   </keylock>
  </resource-list>
 </deadlock>
</deadlock-list>
 
I've never used MERGE, but funny coincidence: we have a big project with AIS data, too.

Have fun with it. The parsing and storing of the data is just sort of ridiculous. If you have a global feed it's just so much data that it's hard to deal with. If you're getting it in raw NMEA format parsing it can be tough, and from my experience the open source parsers are pretty slow.

I was hoping to be able to concurrently update/insert AIS positions to the database, but whenever 2 transactions happen at once I get deadlocks galore. I'm not sure what I am doing wrong. I don't even know if JDBC supports snapshot isolation levels either. I basically have 1000 of those store proc calls in a single batch transaction. I was hoping to be able to execute multiple transactions at once to reduce the overhead from I/O across the network. I've basically just had to increase the batch size so that no actual concurrency occurs because of the frequency of the deadlocks.
 

injurai

Banned
Yeah I put values into my code and it worked but stupidly forgot to add them to the post :\
I only worked it by hand but
to me I read this as being 3 possible things

c += a++ + b++ + d -> 6 + 2 + 4 + 3 == 15
c += a++ + b + ++d -> 6 + 2 + 4 + 4 == 16
c += a + ++b + ++d -> 6 + 2 + 5 + 4 == 17

so iunno...
 

Water

Member
I tried running c += a+++b+++++d but it barfed on me
That doesn't work, because what comes after b gets parsed as ++ ++. Later in the compilation that turns out to have invalid semantics. The compiler doesn't go back to the parsing phase at that point and go, "hey, could there have been some other way to parse that"?

The reason b ++ ++ is broken is that the result of b++ is a temporary value you can't assign into, but the second ++ tries to assign into it.
 

usea

Member
Have fun with it. The parsing and storing of the data is just sort of ridiculous. If you have a global feed it's just so much data that it's hard to deal with. If you're getting it in raw NMEA format parsing it can be tough, and from my experience the open source parsers are pretty slow.

I was hoping to be able to concurrently update/insert AIS positions to the database, but whenever 2 transactions happen at once I get deadlocks galore. I'm not sure what I am doing wrong. I don't even know if JDBC supports snapshot isolation levels either. I basically have 1000 of those store proc calls in a single batch transaction. I was hoping to be able to execute multiple transactions at once to reduce the overhead from I/O across the network. I've basically just had to increase the batch size so that no actual concurrency occurs because of the frequency of the deadlocks.
Our project is in maintenance mode, having been cobbled together haphazardly before I joined the company. Ours isn't a global feed; just a single stretch of the Mississippi river. And it's still a ton of data, so I can only imagine the quantity you're looking at.
 
Our project is in maintenance mode, having been cobbled together haphazardly before I joined the company. Ours isn't a global feed; just a single stretch of the Mississippi river. And it's still a ton of data, so I can only imagine the quantity you're looking at.

Couple that with the fact that I am solo on this project module : )
 
Rant time again. I'll keep it short.

Jira is awful.
Greenhopper is awful.
Bonfire is awful.

All three of them together is an abomination unto mankind.
 

usea

Member
Greenhopper looks like Trello. Is that basically what it is? I like trello a lot for personal use.

As for Atlassian products, we use Crucible/Fisheye and Bamboo at work. They get the job done, but the UIs are terrible. Still better than not having them.

I've never used Jira. We use Fogbugz and Kiln.
 
Jira's okay as a bug tracker once you get used to the complete clusterfuck of an interface. There's some capabilities I'd like to have that don't exist (create filters based on project categories, be able to add a filter to all users instead of just me, etc.), but overall it does its job acceptably. I can't comprehend how one could actually use JIRA alone for projects that aren't in the "maintenance stage", the interface seems to be just too archaic for that.

I only mentioned Bonfire because it was the latest thing that was frustrating me.

Basically we have a Scrum project in Greenhopper. I deployed a release candidate of the latest version of our software to a server and want to begin testing. I want to be able to rapidly put bugs into the system and assign them automatically to the current sprint. You can *technically* do this, but the interface for doing so is clunky at best.

We don't actually use Scrum as a development methodology (really closer to waterfall than anything else). Greenhopper used to be perfect - you could assign tasks to versions as you see fit, while you were creating them, and move things between versions as well. They stopped supporting the interface that worked, and forced you into Scrum or Kanban (which seems to be even more useless).
 
Top Bottom