//TODO: professional stuff of software engineer 1001010
Tag Archives: programmer
value is not identical

Or: Fun with error messages!

Let‘s start with some crappy code I wrote in the Playground as I was going through the Swift language book.

let dict = [String:Float]()

dict["Bob"] = 1.0
dict["Joe"] = "dude"

Guess which dictionary insert line generated this error?
'@value $T5' is not identical to '(String, Float)' 

(insert Jeopardy suspenseful waiting music here)

If you’ve never written Swift I’m sure you’re probably at least partially right,
it was the “Joe” insertion

..and it was also the “Bob” insertion!

There are 3 problems here

  1. Mine: The dictionary is a String:Float, so setting a String value is wrong.
  2. Mine: The dictionary is “let” not “var“, so it’s read-only. Insertions are not allowed.
    The quick fix is to make it “var dict = [String:Float]()
  3. Swift: It’s a crappy error message. If it’s read only – then say it’s read only.

Dear Swift Language team at Apple,
When a user assigns a value to a read-only variable, please tell them root problem – not the immediate error message.  By being cryptic & indirect – you are reminding me of C++ template errors.

-Jason De Arte

Swift Playground setting dict key values

Fix’n Array type syntax on the fly

Apple seems to be raising the bar on auto correcting code editor UI

From the code in the swift book

let emptyArray = String[]()

Soon after I typed it in, Playground prompted me to use the new syntax – AND FIX IT IN PLACE
A quick click transformed it to

let emptyArray = [String]()

Nice Apple, very nice.

Swift Playground Array Syntax Change Notice



Now if they would also do the Auto “Fix-it” for dictionary declarations 😉


-Jason De Arte

Swift: prefix/postfix ‘=’ is reserved

Neat – Apple released x-code 6 beta for free! Which means I finally got a chance to try swift in the “playground”.

As I go through the book and teach myself all about this shiny new tech bauble I may comment on it here.

OH LOOK, a scuff mark already

Playground looks interesting, but where’s the “run” button?  The book tells me to try “println("Hello World")” – but I can’t figure out how to launch it.  Oh well, I don’t care that much.  It looks like it’s real value is a teaching environment to play with code structures & simple flow – sort of like a code calculator.

First “code” section: “Simple Values”

var myVariable = 42

myVariable = 50
let myConstant = 42

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l

That’s great – but I’m a terrible typist.  I ended up typing “var myVariable= 42”  And it errored.  WTF?

Swift irregular spaces around equal sign

As you can see, “x = y” and “x=y” are valid, but “x= y” and “x =y” are not.

W. T. F. ?

This.. is a new problem for me. In my experiences with C languages or Python, I’m not accustomed to casual compiler problems with spaces around an equal sign.  Looking at the error, there are a few things going through my head.

  1. The lexer is borked – it’s a new language after all, so not too unexpected
  2. Whitespace has meaning?  Yes, there are times where whitespace removes confusion in code.  Say in C++ where you have a template containing template params: std::map<int, std::vector<int>> needs to be std::map<int, std::vector> >” – but that’s a lexing issue.
  3. Someone is a fan of The Whitespace Programming Language
    It’s still early in the book – I hope they’re not a fan of brainfuck as well 🙁
  4. OK.. Let’s check the book

Damn it.  It’s in the book.  Here’s the relevant section..

Operators are made up of one or more of the following characters: /, =, -, +, !, *, %, <, >, &, |, ^, ~, and .. That said, the tokens =, ->, //, /*, */, ., and the unary prefix operator & are reserved. These tokens can’t be overloaded, nor can they be used to define custom operators.

The whitespace around an operator is used to determine whether an operator is used as a prefix operator, a postfix operator, or a binary operator. This behavior is summarized in the following rules:

If an operator has whitespace around both sides or around neither side, it is treated as a binary operator. As an example, the + operator in a+b and a + b is treated as a binary operator.
If an operator has whitespace on the left side only, it is treated as a prefix unary operator. As an example, the ++ operator in a ++b is treated as a prefix unary operator.
If an operator has whitespace on the right side only, it is treated as a postfix unary operator. As an example, the ++ operator in a++ b is treated as a postfix unary operator.
If an operator has no whitespace on the left but is followed immediately by a dot (.), it is treated as a postfix unary operator. As an[…]

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l

Matching space count and it’s a binary operator?  FOR EQUAL?

Space on one side only and it’s a PREFIX/POSTFIX UNARY OPERATOR?  FOR EQUAL?


Two pages in & two issues.  Maybe this is a journey into Brainfuck


-Jason De Arte

Remember CodeProject?

I forgot all about it too.  It’s still there, I even have a bit of sample code on their site.  Long-long ago I wrote a /delayload replacement because it was the cool thing to do. At the time it was the best spot to find Win32 code examples other than MSDN.  CodeProject did a decent job answering that core software engineer need for it’s readers: “How do I implement X?”.

Looking back I see that it was backwards.  It was an article/publisher model that relied on people to create the answers to the questions people might be seeking before the questions were answered.  Since psychic powers are in short supply among the technically minded, the reach will always be limited.

Today we have a better answer: StackOverflow.  Instead of waiting for someone to write an answer to the unwritten question, we have a place where we can write the actual question and (if it’s well written & not a plea from someone stuck on their CS homework) get quality answers.

Now the cool geek thing to do is to be the one that writes the best upvoted answers on StackOverflow. For a few of my co-workers, they’ve made a sport* of writing quality answers before anyone else.  It’s sort of like doing Project Euler problems on hard mode.

-Jason De Arte

*I know, a sport involves a ball. whatever

Testing a C/C++ plugin to do syntax highlighting

Got a new wordpress plugin from http://alexgorbatchev.com/SyntaxHighlighter/, let’s see how it works, by drawing on a recent facepalm bug that existed for many years in the codebase..

#ifdef linux
struct SomePThreadContainer {
	pthread_mutex_t mutex;
	int other_data[32];
#define ODD_DATA_SIZE sizeof(SomePThreadContainer)
#define ODD_DATA_SIZE sizeof(HANDLE)
class OddWrapper {
	byte m_oddAbsraction[ODD_DATA_SIZE];
	void DoStuff();
class OddContainer {
	OddWrapper oddOne;
	bool b1;
	OddWrapper oddTwo;
	void VerifyOneWorksOnUse();
	void VerifyTwoFailsOnUse(); // but will work if b1 is changed from a bool to an int

Many bothans were NEEDLESSLY lost to bring you this bug. 🙂

Next Page