18 November, 2011

C++ Extensions

by Y_Less — Categories: Uncategorized46 Comments

Introduction

I’ve seen many people complain about macros in C and C++, saying that they are bad because they hide details away from the user.  This is exactly why I love macros!  They’re like using a library – there the abstraction provides a consistent interface while leaving you with the ability to change the underlying implementation as much as you like.  Macros are like that, only for the front end – you can change how a function is called as much as you like without anyone else ever having to change their code.

With that in mind, I present two sets of macros I have developed for when I am working with C++ to make my coding job much simpler.
(more…)

31 October, 2011

Haskell Lessons

by Y_Less — Categories: Uncategorized49 Comments

Introduction

I have been learning Haskell for work recently (quite advanced Haskell if I do say so). People have in the past promoted the idea of learning a functional language (Haskell is nothing like any language like C/PHP/Javascript etc) as even if you never use it it will teach you entirely new ways of thinking about code – and it’s true. I didn’t notice it at first, but I’ve begun to notice one way in which programming in Haskell has affected my thoughts on programming, and that’s in function parameter orders.

In the past I would have almost universally done this:

void SomeFunction(int array[], size_t size);

Declaring a function that takes an array and the size of that array (importantly in that order). Haskell, however, has a feature called “currying” whereby you can pass some parameters to a function and return that partially evaluated function for later (vaguely similar to closures in Javascript):

func1 array size = {- Code goes here -}

func2 = func1 [10, 11, 12, 13, 14]

Here “func1″ has two parameters (“array” and “size” as before), “func2″ has none and calls “func1″ with only 1 parameter. The result is that “func2″ actually returns a function that takes a single parameter, or to put it another way “func2″ takes one parameter, you just don’t need to put it in. Not bothering to write parameters is called “point free” in Haskell – some people hate it, some love it, it serves to illustrate the point above. We could have also written:

func2 size = func1 [10, 11, 12, 13, 14] size

Here it is blatantly obvious that “func2″ takes one parameter and passes two to “func1″, the fact that in both cases the last parameter is “size” is what allows us to hide it.
(more…)

5 September, 2011

Anyone like my new mirrors?

by Y_Less — Categories: Uncategorized48 Comments

30 August, 2011

Facebook

by Y_Less — Categories: Uncategorized45 Comments

I quit Facebook after their recent change in terms and switch to using “http” as the default instead of “https”. I have never particularly liked Facebook, I joined because everyone else was – not to be a sheep but simply to keep informed of things in the place where they were being discussed. Recently my visits to Facebook usually consisted of “log on -> see I have no new notifications -> leave”.

What annoyed me the most was the fact that Facebook is not the internet, it is a single (proprietary) website, but people seemed to treat it as the center of everything! I don’t believe that our lives should be made to fit around a single website in that way. I also didn’t like the fact that such a huge website could get basic web design so fundamentally wrong as to not work at all without JavaScript, fortunately I found a way around this issue by using “m.facebook.com” instead of just “facebook.com” – that worked perfectly. I am in a number of clubs at university, most of whom communicate over Facebook, only one of which, however, offers an alternative by e-mailing copies of every group messages to members’ university e-mail addresses. Why is this? What does an American company have to do with English university clubs? There is no connection as far as I can see other than “people like it”. Fortunately I am the treasurer of one of these clubs (the Navigators) and am attempting to set up a new club (Parkour) for the new academic year, so my views on this will be voiced!

I don’t object to people using Facebook, I just object to people assuming that it is the center of the World’s communication.

22 July, 2011

Published Scholar

by Y_Less — Categories: Uncategorized43 Comments

Just a quick note to say that I am now officially a published scholar. My paper “An Analysis of Programmer Productivity versus Performance for High Level Data Parallel Programming” appeared in the recent “Communicating Process Architectures” conference (CPA ’11) proceedings. Links to this work can be found on the microsoft website (by whom I am sponsored), and the IOS press website (who published the proceedings):

http://research.microsoft.com/apps/pubs/default.aspx?id=148221
http://www.booksonline.iospress.nl/Content/View.aspx?piid=19804

Sadly you currently need to pay to get the work, but I believe I am allowed to post the work myself. I will confirm this and if so will post it here.

Edit: OK, I’m not too sure about the rules after consultation. If you want a copy and can’t get one through somewhere provided by an institution for free (which technically means money comes through to me, but not a lot and I don’t really care), just ask for a copy in the comments.

22 February, 2011

Haskell XML DSL

by Y_Less — Categories: Uncategorized — Tags: , , , 41 Comments

In my work recently I needed to load an XML file using Haskell. There are a number of toolkits for doing this, but after a bit of searching and research the one most suited to what I wanted to do seemed to be HXT (the Haskell XML Toolkit). It did the things I needed (with some persuasion) but did seem quite cumbersome. The following is an extract from the introduction example to “picklers” from the wiki (thanks to Uwe Schmidt for updating the information to the latest version there):

data Player = Player
    { firstName :: String
    , lastName  :: String
    , position  :: String
    , atBats    :: Maybe Int
    , hits      :: Maybe Int
    , era       :: Maybe Float
    } deriving (Show, Eq)

xpPlayer :: PU Player
xpPlayer
    = xpElem "PLAYER" $
      xpWrap ( \ ((f,l,p,a,h,e)) -> Player f l p a h e
             , \ t -> (firstName t, lastName t
                      , position t, atBats t
                      , hits t, era t
                      )
             ) $
      xp6Tuple (xpAttr           "GIVEN_NAME" xpText  )
               (xpAttr           "SURNAME"    xpText  )
               (xpAttr           "POSITION"   xpText  )
               (xpOption (xpAttr "AT_BATS"    xpickle))
               (xpOption (xpAttr "HITS"       xpickle))
               (xpOption (xpAttr "ERA"        xpPrim ))

That code defines the in-memory storage, file loading and file writing for the “PLAYER” XML element, i.e:


<PLAYER GIVEN_NAME="Ozzie" SURNAME="Guillen" POSITION="Shortstop" GAMES="83" AT_BATS="264" RUNS="35" HITS="73" />

There seemed to me to be a lot of repetition in there – the “data” declaration contains information on what is in the tag and wether it’s needed, so why replicate it all in the pickler? There is a generic pickler written by “lablog”, but it seemed a bit beyond my current abilities and so I set out to develop my own using Template Haskell as a learning excercise and to accelerate the writing of the code to load the rather large XML file I was initially dealing with. This will also serve as a good basis for later work in Haskell DSL development. (more…)

17 November, 2010

y–l.es/s and Apache 2′s RewriteRule

by Y_Less — Categories: Uncategorized142 Comments

Introduction

The other day I decided that I wanted a new domain, and I wanted it to be a clever domain hack based on the name “Y_Less”. y-less.com is great, but it’s a very normal looking domain, not like the hacker style domains you sometimes see. Anyway, the only good one I could get was “y–l.es”, obviously slightly too short, so I added a subdirectory “/s” on the end and set up rules to enforce this. However I decided to go one further and make it explicitly clear that the “/s” is part of the domain name, not part of the directory structure. To do this required a lot of playing about in .htaccess files with RewriteRules, which is what this post is about.

To give a consistent and unique identity the homepage of this new site is “y–l.es/s” and all other addresses look like: “y–l.es/s::page.html” or “y–l.es/s::dir”. There are no trailing slashes on directories as I hate them and all paths come after “s::” to give a clear separation between the website “y–l.es/s” and the requested file. Getting this working, especially for directories and files which don’t exist, took a lot of effort and work learning Apache’s mod_rewrite system for clever redirects.
(more…)

9 September, 2010

Google Instant

by Y_Less — Categories: Uncategorized46 Comments

Google unveiled its new instant search feature in the last day. It is very nice and gives some good results, though I type pretty quickly so it doesn’t really save me much time. One post I read about it, from one of the developers, asked doubters to give it a go, try it out for a while, hoping they will get used to it. This is a reasonable request, however I have tried it out enough to know that I will not be using it. In fact, the removal of your own previous searches from the drop down box may just push me over to Bing. Why? One very simple reason – just one, but to me it’s a big one:

My backbutton-less menu bar.

That’s my menu bar in Firefox, what do you notice? It’s very minimal – the main menu is entirely drop down, the litte arrows next to it are my bookmarks and, most importantly, there’s no back button. backspace goes back, shift+backspace goes forward – why do I need a back button? I use backspace without thinking to go back a page, I am not changing years of embedded use just for one site – that one site is Google Instant (actually, there’s a few websites on which the backspace button doesn’t work, I usually send an email of complaint and leave the site). backspace, no matter where on the page you have focus, deletes a character from your search. I’m fairly certain they had to code it to do that – why?

Anyway, I think I will be adding Google to my list of JavaScript disabled sites (technically removing it from the whitelist). Just so that I can get my back button and previous searches back. Or, as I mentioned, I wonder how Bing is looking now.

11 August, 2010

Mean Joke

by Y_Less — Categories: Uncategorized46 Comments

I’ve done this to a few people – it works well if you are with a fairly computer illiterate person on a windows computer. If they leave the room for a moment, don’t frape them – that’s frankly old and boring, do this instead:

Open a command prompt (run->cmd).
Type the following:

color 97
help for

Then press alt+enter. This will give a full screen white on blue gibberish messge (or appear that way and first glance) – then sit back and wait for the horror as they “realise” their computer has got a BSOD. Most people know enough about them to recognise them and know theyre bad, but not enough to be able to analyse the kernel dump messages.

13 May, 2010

Compile Time String Hashing 2

by Y_Less — Categories: Uncategorized42 Comments

Introduction

Barely days after writing the first compile time hashing post, I needed to use the information in it. As I said at the time it’s ugly, and the Boost license raises some questions for its use in all locations, so I developed a better solution as a separate tool, giving the much nicer overall syntax of:

#include "file_ext.cth"
switch (Hash(szInputString))
{
	case __H(hello):
		// Do something
	case __H(there):
		// Something else
	default:
		// Other
}

(more…)

© 2012 y-less.com All rights reserved - Wallow theme v0.46.4 by ([][]) TwoBeers - Powered by WordPress - Have fun!