Comment On Battleship Booleans

Barry’s first problem with the code was the use of magic numbers. If the application state variable held “127”, it then certain buttons would be enabled, but if it were “54”, then they should be disabled. [expand full text]
« PrevPage 1 | Page 2Next »

Re: Battleship Booleans

2012-11-13 05:20 • by Hatshepsut
394718 in reply to 394695
What is game of battleship?

It's like Battlesheep, but with ships.

Re: Battleship Booleans

2012-11-13 05:54 • by Cbuttius
Firstly the obvious WTF comment that a boolean needs to be a byte rather than a bit so it can hold a FILE_NOT_FOUND value as well as a true or false...

Now to the real issue of which one gives you better "performance".

If you plan to store millions of these in memory then using a bitset will occupy less memory.

It is marginally quicker in processing time to test a byte for true/false rather than testing a bit in a bitset, which requires first working out which bit of which byte before actually doing the bitwise operation. In reality though it is constant time and very fast either way.

Most of the time, choosing between them is likely to be a premature optimisation. I have never yet seen an application significantly sped up because they used an array of bytes rather than a bitset. I have seen large scale applications that store large amounts of data where a bitset was therefore more appropriate although if the plan is to iterate through it finding which bytes are set, and they are sparse, this is a linear search which is of course slow.

Specialising std::vector<bool> to use bitset internally is a WTF and everybody in the C++ world now knows it is. It is a premature optimisation on space which breaks the generic behaviour of std::vector, e.g. you can't do &v[0] to get an array of bool, and various other operations that will give you bools by reference. They added std::bitset for those who want it (which is also a WTF as it is not resizeable). boost provided dynamic_bitset which really is the best option to use for a bitset.

Storing a bitset as a static table would not really improve any efficiency and it would of course be harded to maintain. I would probably use 0 and 1 rather than T and x but it doesn't make a huge difference.

Of course if you were unable to locate this static table on your system, the result of a query on one of its values would genuinely be "file not found".

Re: Battleship Booleans

2012-11-13 08:02 • by brazzy
394721 in reply to 394685
That looks like it was synthesised from a HDL like Verilog or VHDL. Really shouldnt be in a software application. :)

My guess is that it was synthesized from an Excel table embedded in a Word document with "specification" or "requirements" in the title.

Re: Battleship Booleans

2012-11-13 12:37 • by Spewin Coffee (unregistered)
The movie Battleship was terrible. The script writers didn't even make the requisite "G4? It's a hit!" joke from the box cover.

Re: Battleship Booleans

2012-11-13 18:41 • by Silverhill
Isn't that "Bob" Dobbs on that cover?

Re: Battleship Booleans

2012-11-14 06:47 • by EuroGuy (unregistered)
394795 in reply to 394762
I like how the men on the box cover are playing the game, whilst the women have to occupy themselves with the dishes!

Re: Battleship Booleans

2012-11-15 05:13 • by Cbuttius
The actual WTF here is that he deleted the file containing the table, and missed a part of the code that still relied on it.

When that part of the code ran and tried to acquire the boolean result for the number, it got FILE NOT FOUND.

Re: Battleship Booleans

2012-11-16 04:38 • by LonesomeProgrammer (unregistered)
395046 in reply to 394681
Look, if you really understand computers you'd know that deep inside this is all there is. Massive acreage of Trues and Falses. OK maybe this guy represented them funny, with T and x instead of 1 and 0, but those are just symbols, not the actual bits, so it really doesn't matter what symbol you use as long as you are consistent.

If you can't grok a mass of bits you really should be in some other line of work.

Don't know if trolling or assembly programmer, but I'll bite. I have one word for you: abstraction. And it is your friend, your god, and your savior at the same time. Therefore you say thank you and make good use of it. The guy who wrote this code didn't.

Re: Battleship Booleans

2013-01-01 10:48 • by Joe Z (unregistered)
That table and the state variables reminds me an awful lot of the control PLA on the 6502. It's a big table very similar to that, and works under a similar principle.
« PrevPage 1 | Page 2Next »

Add Comment