Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts

Friday, 15 February 2019

Coding Standards - About Scopes (again)

Consistency is good, consistency is light, consistency is really what you need think about when creating code, no matter what format, language, platform or project you're on do things the same way, and even on your first pass do them your way consistently before you apply any locally demanded view of the code....

What do I mean by view?  Well, I'm talking about coding standards, but the non-functional side of things, hence the view.  You can look at code from any angle you choose, indeed there are multiple ways to achieve the same solution within code, the difficulty is to get things out there, put them down, then sort the wheat from the chaff.

I've done this in a couple of videos, where I move pieces of code from their own coding layout to my own, I have labelled these "coding standards", but in retrospect they've just the coding view.

One of my big points is the notation for the scope of variables, I love to use scoped notation.  Having been brought into programming when Hungarian notation was not only taught to you academically as required, but demanded by all projects you worked on (basically as you had no code completion tools, so knowing the type of a named variable whenever you utilised it was really very useful) but that was twenty plus years ago, now we have code completion I strongly feel your tools should be made to work for you.

Therefore, when I complete a call or variable name, I want that to communicate something to me, and the most useful is to check the scope, the code completion tells me the type and the name, but scoping isn't really fully covered in the tooling (please post below any suggestions for Visual Studio, Atom, CodeBlocks or Visual Studio Code which perform scope notation or checking on the fly).

When I complete my typing and pause I want to see all the m_ members together, all the c_ constants all the s_ statics and so many coding standards documents define these three.  However, it's just not far enough, what happens when you have locals named 'angle', 'view' and 'Gregorian'?  They're at very different points within the code completion window which pops up, you have to remove your hands from the keyboard to begin scrolling through them; or worse still start typing letters in order to guess the name (for instance we may start to type a c to see if 'Gregorian' comes up actually as 'calendar').

My solution?  The solution I've been pushing time after time, post after post, video after video?  Scope more things.

We can add "local" as "l_", parameters as "p_", we can compound them, so a static constant maybe "sc_" and we can tailor this in whichever manner we feel fits best, but be consistent.

Let me be utterly clear, this is not Hungarian notation of old, we are not adding "i" to integers or "l" to longs, we are not defining the type within the name, we are simply defining the scope and helping the tools to help us by grouping the various scopes of variables together.

I find it incredibly hard to read documents which go half way, defining members as "m_" (or just a leading m) is extremely common, ditto for constants and even statics, it's only with parameters people get a little squeamish.  "p_" is sometimes reserved for pointer, but that's a style edging back to Hungarian you're notifying the reader of the type and use rather than the scope, therefore I push "p_" as a parameter.  But I can also see arguments for "i_" and "o_" for parameters, which tell you it's an input or output to the function.  If one wanted to be a pedant you could go so far as to stress this with "pi_" and "pi_".

This isn't to say I'm for everything, for example in returning from a function:

int foo();

I will not define an "r_" as the return scope, I'm not interested in the semantics to that extent, and I don't feel code like this:

int foo()
{
int r_result(0);

... Some code to set r_result

return r_result;
}

Is communicating anything useful, so often in my code you will find:

int foo()
{
int l_result(0);

... Some code to set l_result

return l_result;
}

As the result remains a local until returned.

Which brings me back to my second bug bear of the month, one which I've already blogged about returning early.  I'll let you remind yourselves of my opinions.




And just a note to the world at large, if you're coding "m_" for members, but ALSO add Hungarian notations "m_iInteger" stop, stop it now... and yes that includes when you're doing pointers "int* m_pIntegerList"... argh, I want to pull my own arm off just to have something to throw at the screen when I see this one, it's a hybrid as annoying as the Alien in Alien Resurrection.


What's my solution?... Well the completely sane idea I use is "m_IntegerListPtr"... Yes, it's a pointer... I tell myself it's one, I'm not strange at all... Alright, maybe a little.


Saturday, 4 February 2017

Developer : What helps you picture a system?

Systems are complex things, they contain many components, from the physical to the ethereal software running around inside them, you have many considerations, from load to speed and timing, to ease of access and security, so many skills and so much to consider...

So how do you go about creating such systems?

I've had a wealth of experience, in different industries, which arm me with some hard earned experience of how I can best filter through all the complexities before committing too far in the wrong direction, and even more experience of how to rescue a system already too far in the wrong direction!

But as a new developer, a new system guy, or just an experienced guy joining a new team, how do should one best go about approaching the task at hand?

Here are my top tips...

1. Always listen, take notes, record or otherwise pin down the specification.... Walk and talk to the people asking for the system, get to know their mind-space as best you can.

2. Think before you act, many experienced developers take time to think of a solution, they'll diagram, discuss, brain storm or just walk through a problem.  These mental acrobatics are sometimes key to a project getting off on the right footing.  Younger, eager, developers often over look having a period of quiet contemplation.  Don't mix this up with not implementing the basics, an XML loader or a generic piece of code can be written, but what those general tools are put to use doing, the actual architecture, that needs thinking about.

3. Discuss the system, from top to tail.  If you're handed a spec, dissect it, talk to the author, talk to the target customer, talk to the developers who are going to lash themselves to the mast and go along with this vessel, whether it were to sink or sail.  Discussion is not thinking, from the previous point, you need to think your own path through the problem, and remember your path maybe different to others, your solution maybe different to others, this next tip to discuss the problem lets you exchange with others and ensure you are both reading from the same story sheet.

4. Repeat.  Once you have started to work, record what you are doing, talk to others about what you want to do, discuss how things are going and feed all this back into a new round of work, the next sprint, the next deliverable...

These are my positive tips... Have I got negative tips?... No, I have experience, and sadly I can't pass that onto you directly.

Monday, 10 October 2016

Software Engineering : 5 minutes 33 seconds every C++ developer should watch

Just... Just go watch this, digest it...


I've love to print this out frame by frame, phrase by phrase, and have developers walking through the door recite a line at random every morning.

Wednesday, 14 January 2015

Elite Dangerous - Making my First Million

Elite: Making my first million.... 

Lots of my tool writing for Elite is for market data, this is because I'd like to be able to easily turn a profit trading from the beginning, unfortunately in the year 3301 (when the game is set) they've clearly done away with any form of spreadsheet or useful market analysis... I mean, they give you a tab to check a price against a known other location, but you have to have bought the data and... argh it's all so annoying, when we today have tools to find the best buys why doesn't the Elite galaxy?.. Argh...

So, markets and trading aside, how would I go about making my first million?... Simple, here's how (takes a deep breath).

Start out in your Sidewinder, immediately start doing the short hop cargo & data delivery missions, until you have around 15,000.  This can be anything from 10 to 15 missions, as they generally pay around a grand, importantly though run into and out of the same station over and over, so you build reputation with that station.

Once you have friendly status you will start to see "Can you be the hero" type missions, these are where you are tasked to fly out into space and find things lost to the faction, like "Black Box" recordings from destroyed ships, "Art work" from convoys intercepted on their way to the station, "Rebel Transmissions" from opposing factions.

Accept these missions with relish!

Undock and fly to Unknown signal sources, when you land within them you're either going to find opposing ships, the feds or just the cargo flating around.

Obviously, if it's the cargo, scoop it up and fly home, more about that later.

If it's opposing ships, you can slowly learn to fight back, I do fight and defeat upto Cobra Mk III in my sidewinder, more about my fitting later.

If it's the feds however, and this is important for docking, if you are carrying the cargo more often than not that cargo is listed as "stolen", so if the feds (or a station) scan you you will get fined... Don't get fines!... Run away from the feds as fast as you can, never submit to an interdiction with the cargo on board, and if there are feds around when the cargo is found, wait for them to fly away then collect it up.

For docking, come into the station from frameshift and stay at least 8km away, move around at this distance without approaching the station, and align with the docking entrance.

Then, full power to engines, and boost... Request docking permission... and hopefully as they accept you should be about 5km from the opening going pretty fast... Stay aligned, boost again and get through that opening, the moment you pass the blue power curtains you are inside, you can drop your throttle to zero, remove power to your engines and drop your landing gear... this way you shed your speed quickly... A hard pull up or push down on your controls to turn the ship will also shed the speed you built up.

Hopefully you should be inside and can dock now, handing in the cargo for the mission reward.

But importantly you also want to be running these missions out of a station with a Black Market, because if you're sent off for 2 rebel transmissions, but you find 6!... well you can sell the remaining 4 on the black market, and this makes you a LOT of money, more than the mission!

Ancient Artifacts, Black Boxes, Rebel Transmissions and Rare Artworks are the four main items I've been smuggling this way...

If you're forced to undock with these kinds of cargo on board, get as lined up but far from the opening as you can, accellerate and boost out of the power curtains, then boost again as soon as possible, to speed in a straight line away from the station and avoid getting scanned.  Fed ships out there will be your main worry  rather than the instant death of the station opening up on you.

Now, for my fitting, I run the sidewinder as purchased, but have:

1 Pulse Laser (primary fire group) - fixed
1 Cannon (secondary fire group) - gimballed

Removed Basic Discovery Scanner for 2 x Cargo space.

This gives me a total of 6 cargo spaces, and enough punch on the offensive.  I use the laser to take shields down and then hammer targets with the cannon, with the cannon being a limited ammunition store also it forces me to go hand in my bounties and cargo sooner rather than when it's too late.

Other improvements to the ship have been a better set of power generators, power relays, life support, jump drive etc... everything has been slowly upgraded as I've found better, but my fire power has remained the same.

My engaging tactic is based on the shield status, if no shields I get behind the target and open up with the cannon and laser, if shielded I just lay on them with the laser until it's 1/3 of the way and then hammer them down.

An opponent Sidewinder will take (with no shields) maybe 5 cannon shells to go critical and explode.  Eagles take as little as 3.  Cobra's are harder nuts to crack - but I do crack them.

I can, running this set up, earn 100,000 credits in about 45 minutes, depending on how many bounties I hoover up, but just doing cargo one can easily make 16,000 per excusion.

The best trading run I found required me to have a Hauler (12 cargo slots) and 64,000 credits to buy metals and port them off to another station for 14,000 profits per run.  But I was vulnerable to attack, and it was very boring.  With this sidewinder driven approach, I got to experience a bit more of the universe, I experienced markets, black markets, missions and combat... Much more varied.

What was the rub?... Well, with the free sidewinder insurance I risked only my current haul of bounties and cargo each fight/docking... But even so the upgrades to rebuy the whole ship was very cheap, with a 15 light year jump range, a bunch of power and other best in class units my repurchase price is only 7,436 credits.  More than affordable to enjoy and play the started game.

My next challenge is at what credit balance to make the jump to a viper or cobra?... I have my cool first million... I think the viper might be the way to go for this play style... And start kitting it out.

Thursday, 21 August 2014

Story Time - My Worst Ever Date

Story Time - My Worst Date

I'm not going to profess to being a cassonova, but I've had my time with the ladies, some terrible, some very good...

I've turned up to dates, blind dates, exciting dates, scarey dates and one date I've wanted to chew my own arm off just to have something to hit the girl with!... Lets talk about that...

It was a late spring day, not cold, and I was given the number for this lass Claire... I can't remember how I got her number, I think though a guy at work... Anyways, we talked on the phone once or twice and then arranged to meet and she chose to meet by some shops in a nice part of the city, so I figured she lived near there and was a nice person (please note I was born in St Anns in Nottingham and grew up on Top Valley - you may see both in the news - so I'm not judging here, trust me).

Anyway, she described herself as an average build, shoulder length blond, with blue eyes and long legs... I myself am a post college karate toned hottie... Yes, I'll be honest, I was dark haired, clean cut, nicely dressed and a black belt toned body... Not a weekend went by I didn't have some interest from somewhere... Anyways....

I pull up, and look around for this long legged blond... No sign... There's a short fat girl by the shop door... Smoking... and she stubs out her cigarette and comes over... and the voice from the telephone comes out...

"Hi ya" <insert hacking cough>....

Yes, this was my first introduction to her, this hacking cough, a proper phlegm orgy in her throat... I didn't like the look of her, her clothes didn't fit, she was smoking (which I hate) and her face was not nice, she had what I can only describe as lines down her face, as if she'd had a tribal tatoo removed, and she'd used foundation to try to hide this, but she'd used three different shades of foundation, a bronzer across her forehead, a very white pale one over her cheeks and then a slightly yellow one over her mouth and down her neck...

She looked to all intents like a coughing ventriloquists dummy...

I shook her hand and said, "If you're not feeling well, we can do this another time, would you like a lift home?"...

A polite, get out of jail card, as I didn't like her, and she was clearly ill... But she did not take the hint...

"Oh no, I've booked a table at a restaurant now"...

SHIT she's not going to abort this... So we get in the car, it wasn't a big car, but normally people fit in it... She's so large she spills out the passenger seat and into me in the drivers seat... Normally this would be a good move in my car, but she was unaware of this spillage, it was her bingo wings on her arms and as she folded into a seating position this globulous hump came out her side... seriously.

So we set off, she assures me the restaurant is just around the corner... We turn and she directs me, and we turn again... and soon we're on the M1 motorway... This is not good... We go a junction, we're still in Nottinghamshire.... We go another junction... She's trying to talk, but everytime she tries she coughs this hacking cough, and I'm pretty sure she wanted to spit out of the window more than once...

As she coughs she's so heavy the car moves in its lane, so I'm holding the wheel and making small talk, but I'm essentially talking to the hacking rocking shoulder of this coughing lump...

And then her eyes start watering, she's coughing so much her eyes get blood shot with the effort, and tears start to stream down her face.

We've gone two more junctions by now... And we're leaving the county... How far is she taking me... "Where are we getting off the motorway?"

"Junction" Cough "27"... We set off from 25.... It is only 2 junctions. But it is now a long way, perhaps too long with this coughing lump.

So we get off the motorway, and she's got tears streaming, and I notice has her perfum evaporates she smells a little... not bodily... she smells kind of stale... I crack the window open, the sun is setting, it's gone the normal time one would be sitting down to eat.

And we're snaking around country lanes going to god knows where, she seems to know where... She says she's been to this place before.... And then I drop the bomb... "So long as its not a fish restuarant"... It is... It almost exclusively does fish and lobster... Fatty wants me to buy her lobster!  But I'm allergic to fish and shell fish in all forms!

So we pull up thie very posh, over posh, gravel drive and I realise she's trying to take me to this very posh place... Its like £70 a plate... We go in and she gives her name and they lead us to a table... This place is empty, dead, the last diners ate an hour before... We're the last to be seated in a completely empty dining room.  And her mascara has been running, so the tribal tatoo effect is just emphasised and she immediately goes off to the loo to sort out her face and I'm left with the waiter, impatiently wanting to take my order...

I order a steak, and ask what sides comes with it... None I would eat... No veg... no chips... Just a steak...  What will she have, no idea... And then we hear her coming back...

She's coughing her lungs up... hacking and choking.  The very posh waiter turns and lets her fall into the chair, which creaks under her weight... And she begins to order...

I'm having a single dry steak remember...

She's orders... 6 king spawn shrimps in some oil sauce thing... A lobster... A monk fish dish and a half bottle of red...

This duely arrives and she eats like a total pig... and I find fish very off putting, I really don't like the smell, and these dishes stink... My steak comes with her second course and its swimming in a fishy smelling sauce, so I don't touch it.

She scoffs and tries to talk between swallows and hacking coughs... And she's now got bits of seafood in her teeth, so as she coughs its landing on me, and at one point she coughs just as I open my mouth to speak and a piece of fish lands in my mouth, and I freak out, I go to the loo, wash my mouth out and take as long as I can.

"Sorry I took so long, I don't feel right, that's why I've not eaten"... I try to let her down easy, shes scoffing... She wants pudding... The waiter - who is the only member of staff left - comes and appologises but the kitchen is now closed, she can't order pudding... Its gone eleven by now she's eaten like a pig spitting bits of food, mouth open chewing, and this constant coughing... So she goes to the loo again and I pay the bill... £215... And I tip the guy £10, fuck 10% this shit just cost me so much and I didn't eat a bite.

We go out into the night and its cold, we get back in my car, and she's sweating now, she smells of fish and moldy wet bread... She's still not making very good conversation, still with this hacking cough, and I want out now, I've been polite, I've made small talk, I've paid through the nose for shit all and I look a complete fool with this girl...

We're back on the motorway and I'm speeding, I'm pushing my little car to 110mph and booking it down to drop her off...

"You didn't" mchhhhaaaaaaaough "have to pay, I have money"... and she did, she had £50... I just smiled...

"Ducky, that cost £215, and I only had a £10 steak"... She just looked at me...

"Oh my god, I".. mmmmmaaaaaaaough.... "didn't know it cost that much, we went".... hackkkkkakaough... "there for my 21st"....

So she'd been, but never paid... Classic... I pull up at these shops where I picked her up, and basically got her out the car, I was loosing my patience, and didn't want to be nasty to her, she was just clueless... She gets out the car, and she before she can come around I pull off...

But... I didn't notice her string like handbag handle had caught in the door....

And she has it hooked over her shoulder.... I drive off... And it yanks her over, but ths bag handle doesn't break, it digs a nasty red line into her already puffy flesh, drags over her face, stripping it over the layers of foundation, and it pulls her over so she bangs her chin on the ground...

I stop and get out appologising and offering to take her to hospital, she says she's fine, but she's sat there now and looking even more of a mess.

Where the foundation has been scrapped off her face its caked in a thick layer on the bag strap and up into her hair in lumps, her eyes are streaming again, she's coughing and as she wrinkles up her chin blood is seeping out the graze of curled abrasion, and her top is all over to one side as the bag strap twisted her to the ground.

All in all, a pretty impossible situation.

She called me again about a week later, and I pretended to be moving house and very busy to talk to her...

She called and called, in the end she finally asked... "are you not interested"....

"No, ducky, sorry I'm not interested at all..."  She seemed very surprised by this.

Monday, 30 June 2014

My Week Off & Software Dependencies

I've just had a week off, well when I say off I mean I didn't have to get up and go into the office, instead the house needed tending to... Lots of tending to...

I've laid a new floor, had a wall demolished, removed tonnes (literally) of old fencing, painted life preservers (for by the canal side), cut down (clipped not chopped) tree's to size, visited our second house to check on the tenants, and I've done multiple runs to the tip to get rid of tonnes of this junk.

All in all, I'm exhausted and thankful to be back in the office... So what has software been doing without me?

Well, it seems a quite able chap has been busy looking through the code, and has left a bunch of very good insights into fixes for the code, almost like a peer review, something this project sorely needed.

I've duly sent a rebuild and am now awaiting feedback, but whilst that all goes on I decided to look at some of the support tools I use, to see about sending them to various people in the building.

The first problem was this is that I didn't write half of these tools, they were written pretty much as a stop gap measure, and here they are nearing nine years old and still in use in their flaky, temporary, incarnations.

They rely on libraries people don't have, they use modules which are part of the source - meaning to use it you must have the whole source checked out - and they look terrible.

This reliance on other libraries is something I need to tackle, on some systems - like Linux - you can get away with assuming the user is able to go get the libraries your software needs (if you tell the user which are missing that is) but on windows its unforgivable to leave a piece of software to crash through some mysterious missing library problem.

And this is exactly what we get with these tools at the moment, I know why they're crashing, I know others know why they're crashing, and if other more dense users read the error message they'd know why its crashing and be able to ask for a solution.  But instead I'm met with the continual report that the program is broke, and then a wall of silence as to what's wrong with it.

So, developers out there the world over, if your software needs a library, and that library is only on your machine, let everyone know, make your software check for the presence of it, don't just let it run off the end of its runtime and crash!

Thursday, 23 January 2014

Network Guru Fails at Monitoring his own Bandwidth

Do I come on here to bemoan the seeming incompetence of others a lot?... Because I have  just had an annoying 20 minutes talking to one of our "Network Experts", there's a server box running Ubuntu, its actually a virtual machine, and it was being blamed for crippling the network on the host machine - which has to run several other Windows Server 2008 Virtual Machines.

For some reason, this came across my desk, because someone has decided that though I can't advise the company on Linux server usage or adoption, I can be called into sort out the problems other fools create.

So, this server was running, the administrator chap is sat there with PuTTY connected to it and he's saying there's too much network traffic coming from the box.

Looking at the process list the machine is doing nothing, when I ask for one of its users to be made to use it, the CPU usage is a time flitter and then the usage is over, it appears to me the Virtual machine host is waking the VM, using it, and closing it.

The processes being used are simple webservices, so there should be no network traffic unless someone is using the server.

So, I ask.. "What's your idea that this machine is causing the issue?"  Very smugly the admin presented me with an A4 sheet with two graphs, one shows all his servers running with the Ubuntu machine present, and there's a whole load of traffic going on... The next is the same graph, with the Ubuntu box removed, and there's nearly no network traffic.

Then within PuTTY connected to the box he opens iptraf...


And he points to the statistics and declares, "See, this is running multiple kilobytes a second"...

Lets recap... "This machine is crippling our network usage on this box".... "using up kilobytes a second"... If any of you don't grasp how absurd this is please stop reading now, because the guy was clearly serious.  He's not that old, he's younger than me, surely he realises kilobytes a second on a modern gigbit backbone is nothing?  No, he seriously wants the ubuntu box silent.

So, what's causing this tiny trickle of bandwidth... Of course, he's connected to this machine with PuTTY...

"Close this window and take me to the machine in the server room"

In we go, and from the console plugged into the machine I run iptraf... look what we see now...


Yes, its zero...

When he is running his measures and checks he's connected over the network to the machine, he's been measuring his own bandwidth administrating the machine, and apparently the kilobytes per second that took were too much for him, I feel like this guy should be thrown from the building, not be earning far more than me in the "superior" position of "network guru god" which hs holds...

So knowing the machine is idle, I wonder what causes the bandwidth, so with the iptraf still running, I call up the user and ask him to get working again... and sure enough there's little trickles of bandwidth from the Ubuntu box, no spikes, no major blocks of transmission.  Hence after a few minutes I conclude the Ubuntu box though active, is only taking a tiny amount of the total bandwidth available to the machine, and so I start to look at the other machines...

And with just perfmon on the two Windows Server 2008 boxes with the user operating his end, I can see that the Windows boxes are spiking their network traffic, just with task manager you can see one box taking 20% the total available to it, and the other over 45%... This is a gigbit connection, and 20% of it is taken for maybe 30-50 seconds each minute and then goes quiet, then the 45% hog is there for maybe every 10 seconds of each minute.

They're scheduled tasks, as the users input items into their programs, the programs process and send out instructions, e-mails and update other databses.  The trickle of data I/O to the ubuntu machine is just such a feed, the Ubuntu box sucks/queries data from MS SQL Server on one of the machines and squirts it into MySQL where a very old (like 8 year old) unmaintained program written in C with MySQLConnector picks it up and uses sendmail to e-mail a load of people.  Such notifications take maybe 0.25 seconds and run every 5 minutes, the amount of data is small, and looking at the physical name of the Ubuntu box "e-mailer relay" I think it's safe to say its not using a lot of bandwidth and the other machines are to blame.

How I educate the "network expert"... This is my next task.

Saturday, 5 October 2013

General Programming Tip: Control Alignment on Different Resolutions

I'm going to throw a piece of advice out there, to professional developers, and it might be a piece of advice many don't stumble upon.

Aligning things on your screen... If you have a piece of software, which fills the screen, or has a known size today, don't align the labels or controls on it to just fit that screen, use tricks like dock, and flow layouts, and alignments to layout the screen for any resolution.  It'll take more time now, but if you are planning to support the software on multiple platforms, or for many years, then it'll all be worth while.

Today your screen might be 800x600, and your label plonked on it might sit nicely...


But tomorrow...



Its a higher resolution, and its off to one side... So how might we quickly get around this?  Well, with a single label, its easy enough, make it fit the width of the screen, set the alignment to center... and voila.


Your text will always sit right... and this is a two second job... other patterns to achieve this take longer, but think about it now, save yourself some time in the future!