Unofficial Programming Thread II

Post » Mon May 16, 2011 11:00 pm

nifty, background worker seems like such a pain in the butt. I just create a new thread and do what I gotta do. If it works it works though hu.

A background worker is simply a thread with progress callback and cancellation mechanisms attached. If you spawn an ordinary thread and want to call back into the GUI thread for progress, you'll just end up reimplementing a background worker.
User avatar
Janette Segura
 
Posts: 3512
Joined: Wed Aug 22, 2007 12:36 am

Post » Tue May 17, 2011 3:29 am

I'm taking visual basic this semester, anyone have any advice for someone who hasn't taken any programming classes yet? :unsure:
User avatar
Brooke Turner
 
Posts: 3319
Joined: Wed Nov 01, 2006 11:13 am

Post » Tue May 17, 2011 12:53 am

I'm taking visual basic this semester, anyone have any advice for someone who hasn't taken any programming classes yet? :unsure:

Learn some VB now, it's not hard, and your classes will be easier.

Edit: Grammar.
User avatar
Naazhe Perezz
 
Posts: 3393
Joined: Sat Aug 19, 2006 6:14 am

Post » Tue May 17, 2011 3:13 am

I'm taking visual basic this semester, anyone have any advice for someone who hasn't taken any programming classes yet? :unsure:

VB is actually realtively easy. alot of the keywords and stuff are plain English so that helps.You could probably look it up and get a good grasp on it before you start your classes.
User avatar
Elena Alina
 
Posts: 3415
Joined: Sun Apr 01, 2007 7:24 am

Post » Tue May 17, 2011 2:06 pm

I'm going to be taking C# in a few days when school starts up again. So far I've done Python, C++, and the web programming languages (html, java, & server-side scripting languages). Anyone done any C# programming? I've heard its very similar to C++, but just curious if anyone has first hand experience.
User avatar
James Wilson
 
Posts: 3457
Joined: Mon Nov 12, 2007 12:51 pm

Post » Tue May 17, 2011 12:12 pm

C# is basically cleaned up Java. Strictly object-oriented, verbose, bytecode-compiled, etc, though not as portable. All in all not perfect but pretty decent if you ask me. Microsoft seems to be on a feature-adding binge with it though. Every year or two they come up with a new version of the language and add fairly major features (e.g. LINQ). The last dozen posts in this thread have been dealing with C# code if you'd like to take a look.
User avatar
Heather Stewart
 
Posts: 3525
Joined: Thu Aug 10, 2006 11:04 pm

Post » Tue May 17, 2011 1:09 am

I'm going to be taking C# in a few days when school starts up again. So far I've done Python, C++, and the web programming languages (html, java, & server-side scripting languages). Anyone done any C# programming? I've heard its very similar to C++, but just curious if anyone has first hand experience.

Like Max said alot of this thread (at least recently) has been C#. I tried C++ in high school, and VB.NET twice in college, plus a semester of C# and I have to say C# is the one that kept me hooked. I tried Java but couldn't really get the hang of it, not that I have a firm grasp on C# but im working on that.
User avatar
u gone see
 
Posts: 3388
Joined: Tue Oct 02, 2007 2:53 pm

Post » Tue May 17, 2011 9:35 am

Thanks guy ^_^

I got the progress bar working... kinda. I mean it would work if the copy code actually worked. Which it doesn't. :facepalm:

I don't really know how to copy the files without using a foreach loop
User avatar
Javier Borjas
 
Posts: 3392
Joined: Tue Nov 13, 2007 6:34 pm

Post » Tue May 17, 2011 7:51 am

Thanks guy ^_^

I got the progress bar working... kinda. I mean it would work if the copy code actually worked. Which it doesn't. :facepalm:

I don't really know how to copy the files without using a foreach loop

Can you post the code that helps the progress bar to work? I am curious as to the solution you found.
User avatar
Lewis Morel
 
Posts: 3431
Joined: Thu Aug 16, 2007 7:40 pm

Post » Tue May 17, 2011 7:53 am

I don't really know how to copy the files without using a foreach loop

Foreach loops are nothing more than syntactic sugar. They are identical to for (and even while) loops if you get down to it.

E.g. For arrays, this:
foreach (string newPath in Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories)) {  File.Copy(newPath, newPath.Replace(sourcePath, targetPath), true);}

is functionally identical to this:
var files = Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories);for (int i = 0; i < files.Count(); i++) {  var newPath = files[i];  File.Copy(newPath, newPath.Replace(sourcePath, targetPath), true);}

and this:
var files = Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories);int i = 0;while (i < files.Count()) {  var newPath = files[i];  File.Copy(newPath, newPath.Replace(sourcePath, targetPath), true);  i++;}

User avatar
mishionary
 
Posts: 3414
Joined: Tue Feb 20, 2007 6:19 am

Post » Tue May 17, 2011 1:22 pm

VB is actually realtively easy. alot of the keywords and stuff are plain English so that helps.You could probably look it up and get a good grasp on it before you start your classes.

When I signed up for this job, I knew only a little about VB and wanted to do C++. All I had was some knowledge of Basic constructs I learned 15-20 years ago with Vic20 and later QBASIC. It changed quite a lot during those years though, eh. I told them, ok, I know a little Basic, and was put to work with Basic scripting and PL/SQL from day one, and in about a month or two I was up to speed with both by mostly studying other scripts. I have helped other coders to get a quick start too. So, yes, Basic is kinda simple, and you can quickly test things as it is an interpreted language and does not require compiling between tests. So, experiment.

Depending on your current level, it does not take too long to familiarize yourself with how variables and arrays are declared. Then functions, loops and conditions, not going too far. Sub Main is where the execution starts. Maybe knowing that some function calls can "throw exceptions" would be good and how to control where the execution jumps "on error". That all you need to get a start, I think.

However, there are some pitholes in the way the language works, but it's workable. Sometimes you will have to work around some things, but you may not notice that until some practice and having to deal with error situations with localization, array init, etc. When you move to other languages, don't let the few "work arounds" carry over to the new language that may not have the same "features". With that said, it might be easier to move on to C# than C++ from VB (.Net).
User avatar
Angela Woods
 
Posts: 3336
Joined: Fri Feb 09, 2007 2:15 pm

Post » Tue May 17, 2011 2:56 am

I was actually just asked in an interview if I knew Visual Basic at all, I told the interviewer no I did not but since he saw I had C# experience I told him it shouldn't be too hard to pick up if I did get the job since I had done a couple intro courses for it before. The reason I had done a couple is due to untransferred credits and program requirements at a couple of colleges.

I also mentioned that for the moment I was focusing on the C# for personal learning since I have alot of other stuff I need to get done with that has to take priority.

I wonder if my instructor for my Windows Admin course will let me use our systems for testing applications I write. Will have to ask him about that today, since my recent project is for tweaking services. If I am writing on my machine I can be almost sure it does work but when working on others I cannnot be.
User avatar
Anthony Santillan
 
Posts: 3461
Joined: Sun Jul 01, 2007 6:42 am

Post » Tue May 17, 2011 1:34 pm

Started re learning Java for Uni. Ug.

I keep running into issues like looking for one line ways to apply a function to a collection. The amount of boilerplate code Java needs is INSANE. Even C++ is far better, having things like std::transform.

I want Haskell back :(
User avatar
Adam
 
Posts: 3446
Joined: Sat Jun 02, 2007 2:56 pm

Post » Tue May 17, 2011 7:14 am

Sometimes I really need to limit myself when working on various programs. I get ideas I have no idea how to even approach then get discouraged if I cannot figure it out. I tried an IRC for C# and another forum and never seem to get anywhere, I can get on the right track but then I get lost. and on the IRC they keep directing me to do things I can't really find good information on using Google or MSDN. Very frustrating but hopefully I can get a better understanding soon of certain things.
User avatar
Kristina Campbell
 
Posts: 3512
Joined: Sun Oct 15, 2006 7:08 am

Post » Tue May 17, 2011 4:15 am

Edit: Nevermind I got it.
User avatar
Phoenix Draven
 
Posts: 3443
Joined: Thu Jun 29, 2006 3:50 am

Post » Mon May 16, 2011 11:56 pm

A question:

I have a twos complement 32 bit integer.

I need to encode a version string into an integer so that when you do a simple less than comparison with the integer it acts as you would expect when you compared the version string:
1.2    < 1.33.5    < 10.51      < 1beta31beta3 < 1.3


While the first two conditions are trivial. Examples like the third and fourth are harder.

Does anyone have any ideas? I know in some cases it is always going to be lossy and if it can't be reasonably done it isn't a major problem. It just would be nice if it worked slightly better than my current version (that only takes into account the numbers).

The only consideration I came up with so far is to alter the version string so that beta becomes .0. and alpha would become .0.0. I keep thinking it feels rather messy and imprecise and that I may have missed something.
User avatar
Amber Ably
 
Posts: 3372
Joined: Wed Aug 29, 2007 4:39 pm

Post » Tue May 17, 2011 2:36 pm

A question:

I have a twos complement 32 bit integer.

I need to encode a version string into an integer so that when you do a simple less than comparison with the integer it acts as you would expect when you compared the version string:
1.2    < 1.33.5    < 10.51      < 1beta31beta3 < 1.3


While the first two conditions are trivial. Examples like the third and fourth are harder.

Does anyone have any ideas? I know in some cases it is always going to be lossy and if it can't be reasonably done it isn't a major problem. It just would be nice if it worked slightly better than my current version (that only takes into account the numbers).

The only consideration I came up with so far is to alter the version string so that beta becomes .0. and alpha would become .0.0. I keep thinking it feels rather messy and imprecise and that I may have missed something.

Your solution there was pretty much what I thought of as soon as I read the problem. I actually had a similar issue come up on a project myself, and I implemented it like that. I do have the feeling that there's a neater, but not particularly simple way of doing it.
User avatar
Maddy Paul
 
Posts: 3430
Joined: Wed Feb 14, 2007 4:20 pm

Post » Tue May 17, 2011 10:13 am

A question:

I have a twos complement 32 bit integer.

I need to encode a version string into an integer so that when you do a simple less than comparison with the integer it acts as you would expect when you compared the version string:
1.2    < 1.33.5    < 10.51      < 1beta31beta3 < 1.3


While the first two conditions are trivial. Examples like the third and fourth are harder.

Does anyone have any ideas? I know in some cases it is always going to be lossy and if it can't be reasonably done it isn't a major problem. It just would be nice if it worked slightly better than my current version (that only takes into account the numbers).

The only consideration I came up with so far is to alter the version string so that beta becomes .0. and alpha would become .0.0. I keep thinking it feels rather messy and imprecise and that I may have missed something.

Make your own class which will contain a string with nicely formatted version info (e.g. along the lines of http://www.gentoo.org/proj/en/devrel/handbook/handbook.xml?part=2&chap=1#doc_chap2) and a comparison operator. If you format the version info nicely, comparing two versions will almost boil down to simple lexicographical comparison (except for e.g. 3.5 < 10.5).
User avatar
Maeva
 
Posts: 3349
Joined: Mon Mar 26, 2007 11:27 pm

Post » Tue May 17, 2011 7:06 am

Make your own class which will contain a string with nicely formatted version info (e.g. along the lines of http://www.gentoo.org/proj/en/devrel/handbook/handbook.xml?part=2&chap=1#doc_chap2) and a comparison operator. If you format the version info nicely, comparing two versions will almost boil down to simple lexicographical comparison (except for e.g. 3.5 < 10.5).

The issue it is in a database and I want to be able to find the greatest version fast. Errors are not a big problem though so roughly is good enough.

EDIT:
Send thoughts, shouldn't version 1beta3 be less than version 1? My past self thought so, and my present self doesn't trust past self myself at 1:30 am, but my past self a 4 pm when it wrote the unit tests for what it should do.

EDIT:
Split the integer up into groups of 2 bits, followed by 6 bits.

It would work the same way as before, each bit of the version is stored in one of the 6 bits. However, if the group of bits refers a version following a string like 'beta', then the leading two bits is reduced by a factor.

I think that should work. No I have to rewrite my parser.

EDIT: :P
It doesn't. Messes up on: 1beta3 < 1.3

EDIT: Yay. Fixed (Or it passes all tests, which is good enough). Now I need to write some tests to see if I can break it again.
User avatar
Wayne Cole
 
Posts: 3369
Joined: Sat May 26, 2007 5:22 am

Post » Tue May 17, 2011 12:35 am

The issue it is in a database and I want to be able to find the greatest version fast. Errors are not a big problem though so roughly is good enough.

EDIT:
Send thoughts, shouldn't version 1beta3 be less than version 1? My past self thought so, and my present self doesn't trust past self myself at 1:30 am, but my past self a 4 pm when it wrote the unit tests for what it should do.

EDIT:
Split the integer up into groups of 2 bits, followed by 6 bits.

It would work the same way as before, each bit of the version is stored in one of the 6 bits. However, if the group of bits refers a version following a string like 'beta', then the leading two bits is reduced by a factor.

I think that should work. No I have to rewrite my parser.

EDIT: :P
It doesn't. Messes up on: 1beta3 < 1.3

EDIT: Yay. Fixed (Or it passes all tests, which is good enough). Now I need to write some tests to see if I can break it again.

I would say version 1 beta 3 could potentially be a lower version than version one depending on the context. If it is final version 1 then yes, but if it is beta version 1 then no. But beta usually comes before final anyways so that kind of gets thrown out the window.

Then again this is 2am ramblings as I refuse to sleep.
User avatar
Miguel
 
Posts: 3364
Joined: Sat Jul 14, 2007 9:32 am

Post » Tue May 17, 2011 10:57 am

The issue it is in a database and I want to be able to find the greatest version fast.

That's why your database is a http://www.cppreference.com/wiki/container/set/start and finding the greatest version is trivial and as fast as it can be. :huh: If you're not doing it in C++ just implement the set yourself; it's not a difficult thing to do - just make sure that each new entry gets put in its proper place in a (doubly-)linked list (and don't add it if it's already in it). Yes that means that adding a new version to the database will take a tiny bit longer (insignificantly longer) but since adding a new version to the database is not going to happen as frequently as checking for the latest version in the database that's not a problem. As a matter of fact, since any new version you'll be adding into the database will most probably be the latest version (i.e. greater than any which is already in the database), if you implement seeking for the proper place for a version in the (doubly-)linked list by starting from the end of the list (where the greatest version in the list is), both adding a new version and checking which version is the latest in the database will be almost instantaneous.
User avatar
Budgie
 
Posts: 3518
Joined: Sat Oct 14, 2006 2:26 pm

Post » Tue May 17, 2011 12:11 am

Database, as in a RDBMS, as in MySql. :)

The other alternative, which I am considering is to assign everything a version index, and then reorder in PHP when I add a new row. It isn't as expensive as it sounds due to their being probably at max 20 rows that would need reordering.
User avatar
bimsy
 
Posts: 3541
Joined: Wed Oct 11, 2006 3:04 pm

Post » Tue May 17, 2011 5:17 am

Database, as in a RDBMS, as in MySql. :)

Well then my next quite obvious advice is ditch that and just program your own program version database in C++ (or some other programming language). :shrug:
User avatar
Genevieve
 
Posts: 3424
Joined: Sun Aug 13, 2006 4:22 pm

Post » Tue May 17, 2011 4:52 am

Well then my next quite obvious advice is ditch that and just program your own program version database in C++ (or some other programming language). :shrug:

It isn't only version data. There are about 10 tables with an expected 100 000 to 500 000 rows in total.
User avatar
Roberta Obrien
 
Posts: 3499
Joined: Tue Oct 23, 2007 1:43 pm

Post » Tue May 17, 2011 2:36 am

It isn't only version data. There are about 10 tables with an expected 100 000 to 500 000 rows in total.

Each could be done quite simply as a class containing a doubly-linked list of your own classes (or structs) and appropriate managing functions.
User avatar
Juliet
 
Posts: 3440
Joined: Fri Jun 23, 2006 12:49 pm

PreviousNext

Return to Othor Games