The online racing simulator
They're evil. I've never had a valuable use for them yet, but I still hate them because I have no idea where to use them.
Quote from dawesdust_12 :They're evil. I've never had a valuable use for them yet, but I still hate them because I have no idea where to use them.

They're good for validating complex input, such as telephone numbers. They're also good for quickly grabbing stuff from strings of input, or for manipulating strings.

To give 2 real world examples -

Many years ago I used to play a game called Planetarion - a web based online space strategy game. In it you could scan other planets to determine if they were worth attacking. Groups of players would form alliances and you'd want to share these scans. Unfortunately the only way to get them was to copy and paste from the browser. To deal with this many alliances would write little web based tools that their members could paste the scan into to update the database. Although each browser would copy a table into plain next in roughly the same format, it wasn't exact - some would place tabs between columns, others spaces. Regular expressions were the most sane and sensible way of getting the required data from these pasted scans and into a relational database for analysis.

I use regex's most days at work. At work I'm employed to be an outsourced sysadmin, but I also code for internal projects and so forth. For both elements of my job I will use regexs. For instance, using ldifde you can query an Active Directory server to get various bits of information about stuff in the AD (such as getting a list of users in an OU [organisational unit]). Unfortunately it normally returns a load of extra stuff you don't want and can't trim out through ldifde itself. Using regex's you can reliably remove these additional bits of guff. In our internal projects regex's are use for some of the more complex form validation, such as post/zip codes, email addresses and phone numbers.

For the coding aspect of my job it's handy when moving blocks of code or for refactoring. For instance I recently had to convert from using the Zend_Date object to our own. There were about 3 affected files, and about 4 instances created in each. I could've manually gone through and edited each file and each instance. However, using regex's I could simply perform :%s/Zend_Date/Better_Date/g (This is an example of using Vim's regex support to subsitute Better_Date for Zend_Date, through out the entire file, even if it occurs multiple times in the same line).

Unfortunately it becomes exceptionally easy to over use regexs.

For instance although you could use a regex to screen scrape from a website, it's a bad idea and you should really be using something that understands the DOM and allows you to query based on that - such as XPath or CSS selectors - the reason being that although a regex will probably work, it'll break if the website introduces new lines or additional attributes that your regex doesn't have support for. Something that understands the DOM will just continue working.

As I've said before, regex's are something you will absolutely hate. Until you get used to them.
Quote from the_angry_angel :As I've said before, regex's are something you will absolutely hate. Until you get used to them.

So it's like perl, a one line wonder tool for those willing to learn it.
I've written some pretty nasty (read: long) regexs, so describing them as one line wonders isn't 100% accurate, but you're pretty much right
I must be strange.. I actually like RegEx! I find them an interesting challenge (for want of a better phrase). Granted, they can cause hair loss, but still provide more fun to me than trying to do a Rubik Cube for example

It bugs me when coding in C++ as it's not a language I'll claim to be fluent in at all that I haven't yet grasped the use of RegEx construction and normally have to resort to using various split() type calls and arrays to finally drill down to the data I need to access.

One task I've been asked to resolve at work is to fix some things in a CSV file. The 2 fields clearly labelled 'first_name' and 'last_name' seem to occasionally get filled with 'Miss Blogs' and 'Miss Joe' or the 'first_name' field with 'Jack or Jill' and the 'last_name' field left blank (don't ask.. we're talking about the acting industry.. not renowned for their intelligence). If I had to do this with C++, due to my lack of knowledge, I'd have to split each line at the ',' char, then process the fields working on splitting at spaces and the likes. Using RegEx will make the task very simple as I only need to split the row at the ',' char, then work on the relative field with some simple RegEx. I expect nothing more than 20 lines of code to read in a file, process and write an updated version.

Maybe sadistic, but I find them fun to work with (although my usage is pretty much limited to Perl and PHP)



Regards,

Ian
Ahh, the effortless way of baiting Ian out of his hole... mention RegEx's
Quote from dawesdust_12 :Ahh, the effortless way of baiting Ian out of his hole... mention RegEx's

Heh.. have been sorting out trying buy a house and spend more time round my fiancé's place than I do in front of the screen after work these days... not a bad thing though



Regards,

Ian
Quote from Ian.H :It bugs me when coding in C++ as it's not a language I'll claim to be fluent in at all that I haven't yet grasped the use of RegEx construction and normally have to resort to using various split() type calls and arrays to finally drill down to the data I need to access.

Boost.RegEx? I personally prefer Spirit for my string parsing needs though.
Quote from wien :Boost.RegEx? I personally prefer Spirit for my string parsing needs though.

Maybe I'm just not getting it from the Spirit introduction page, but is Spirit a (better|different) objective version of Lexx?
Quote from the_angry_angel :Maybe I'm just not getting it from the Spirit introduction page, but is Spirit a (better|different) objective version of Lexx?

I've never used Lex, so I can't really comment on that in any detail, but it's basically a library that allows you to write the language grammar directly in EBNF form as plain C++ code. Lex requires preprocessing if I'm not mistaken? From what Wikipedia tells me Spirit fills the role of Yacc as well (parser generator), so Spirit = Lex + Yacc I guess you could say.
I've been playing around with VS2010 and it's really good actually. I was concerned, like many people were, about it being ported to WPF, but it runs very smoothly and the font rendering in the editor is crisp and sharp. If anything I'd say it runs a bit faster than VS2008.

In terms of the new features in .NET 4.0, I've not had time to play around with much of it yet, but I'm enjoying some of the new additions to C# 4.0 (SortedSet is awesome), and the WPF editor has received a lot of work and is much more robust.

I think the best thing though has to be the improvements to the WPF font rendering, the text looks perfect now and makes me actually want to write WPF apps.

All in all it looks like a good step forward.
I think the only thing I'll want in C# 4 is the ability to have optional parameters for functions. Kind of a pain in the ass what they currently have.
Quote from DarkTimes :If anything I'd say it runs a bit faster than VS2008.

Are you kidding, or are the .NET bits really that different from the C++ ones?

In my experience 2010 beta 2 is slow as molasses and horribly buggy to boot. Things like "go to declaration/definition" are completely unusable since they usually lock up the entire IDE for many seconds while it fails to find the declaration I asked for. Intellisense is still completely broken, even though they bragged that they had fixed it this time. It also uses more than twice the memory doing the same thing as VS2008, which on my 2GB laptop means even a simple compile of my framework leads to massive disk swapping.

Quite frankly I find it an unusable mess. If it weren't for the C++ compiler improvements (which are also rather buggy) I'd stay with VS2008.
Quote from wien :In my experience 2010 beta 2 is slow as molasses and horribly buggy to boot.

Yeah, that was another thing that put me off VS, I could type faster then it could render on the screen. I needed something lightweight and fast, so I use a NotePad2 Modification / Extension / Enhancement by Kai Liu for my programming needs.
#215 - Woz
I am looking forwards to the DLR integration with C#.

Covariance and contravariance are the big things I want as they really P me off being missing from C#

Why I could not cast

List<ClassA> to an IEnumerable<IMyInterface> when ClassA implements IMyInterface was beyond me. The hoop jump to solve was just dumb.
Quote from wien :Are you kidding, or are the .NET bits really that different from the C++ ones?

In my experience 2010 beta 2 is slow as molasses and horribly buggy to boot. Things like "go to declaration/definition" are completely unusable since they usually lock up the entire IDE for many seconds while it fails to find the declaration I asked for. Intellisense is still completely broken, even though they bragged that they had fixed it this time. It also uses more than twice the memory doing the same thing as VS2008, which on my 2GB laptop means even a simple compile of my framework leads to massive disk swapping.

Quite frankly I find it an unusable mess. If it weren't for the C++ compiler improvements (which are also rather buggy) I'd stay with VS2008.

Well I can only talk from my own experience, the C# editor is not any slower than in VS2008 for me, and the WPF editor is much, much better. That being said, the WPF support was awful before. I can understand that other potions of VS may not be all hugs and puppies, but for what I mainly use it for I'm pretty satisfied. Of course it is still a beta, and it does have a few bugs, but then that's what betas are for.
#217 - Woz
Quote from DarkTimes :Well I can only talk from my own experience, the C# editor is not any slower than in VS2008 for me, and the WPF editor is much, much better. That being said, the WPF support was awful before. I can understand that other potions of VS may not be all hugs and puppies, but for what I mainly use it for I'm pretty satisfied. Of course it is still a beta, and it does have a few bugs, but then that's what betas are for.

Depends how aggressive your are with your use of intellisense
Ever read some of your old source code and become, like REALLY embarrassed by it? You think to yourself, how where you ever that stupid? I bring this up, because I'm looking at SimFIA's code base, as I was just going to release it, then I realized that it was really, really bad code, and I would hate it if anyone picked up some bad programming habits from it.

Echoing huge blocks of raw HTML ... Oh, it was bad!
Yes, every time. I think that it's a good thing though, as to me it means I'm still improving. If I ever look back and think my old code is perfect, then it may well be time to give up. That doesn't mean I'm not embarrassed by it! Most of it.

One thing though that it took me a long time to learn, is that when you release code no one really notices how badly written it is. No one really cares. I guess cause everyone secretly thinks all their code is badly written too and doesn't want to draw attention to themselves.

In my view, no matter how something was written, if it works well and is useful to people, then it's something you should be proud of and you shouldn't hide away. Plus, I guarantee you that pretty much every other programmer in the world has definitely seen, and probably written, worse.
MySQL help needed
Guys, I need some help from some people who know MySQL.

I have two tables - users and layouts. Here are the structures (example):

Users
----------------------------------------
| id | int, auto_increment |
| username | varchar |
| etc...
----------------------------------------

Layouts
----------------------------------------
| id | int, auto_increment |
| user_id | int |
| etc...
----------------------------------------

Explanation - all users are stored in "users" table. Each user can have some layouts uploaded, so each layout is stored in "layouts" table also with the user ID of the uploader. All I want to do is, to do a SELECT query that would look like this and should be orderable by all columns.

Select all users and number of rows in layouts table with their ID
----------------------------------------
| username | number_of_layouts |
----------------------------------------
| Flame | 3 |
| Jack | 5 |
| Peter | 0 |
----------------------------------------

I have minimal MySQL experience but I believe it would be;

"SELECT number_of_layouts FROM _layout_table_here_ WHERE username = 'Flame'";

EDIT: I don't think this is what you were asking for anymore. But I believe that would give you the number of layouts for a particular user.
@Flame

Has been a while since I don't mess with SQL but it might be something along these lines:

SELECT U.username, COUNT(L.user_id) AS number_of_layouts
FROM Users U, Layouts L
WHERE U.id = L.user_id

This "count" thing returns the number of rows that match the condition. I guess. Never used it.

de Souza: I edited your query a little bit (yours didn't work as expected, returned one user and total number of all layouts). Now it returns all users and no. of layouts, but only from the users, who have at least 1 layout uploaded. I want this query to show a list of all users, so those, who have 0 layouts too. Here is my query so far:
SELECT U.username, COUNT(L.user_id) AS number_of_layouts
FROM users U, layouts L
WHERE U.id = L.user_id
GROUP BY U.id

Edit: As I am thinking about it, it isn't necessary to show all registered users on my site, so I will use the query above for now. You can still post any thoughts
If you still want to show all users (or use a similar query to something else, or just out of curiosity), try changing from...

FROM users U, layouts L
WHERE U.id = L.user_id

to...

FROM users U
LEFT JOIN Layouts L ON U.id = L.user_id

That way, if I'm not mistaken, the two tables are joined even if the second table has no corresponding value.
It returns me the same...
SELECT U.username, COUNT(L.user_id) AS number_of_layouts
FROM users U
LEFT JOIN layouts L ON U.id = L.user_id
WHERE U.id = L.user_id
GROUP BY U.id


The Off Topic Programming Thread!
(309 posts, started )
FGED GREDG RDFGDR GSFDG