Unofficial Programming Thread

Post » Thu Sep 23, 2010 10:39 am

http://i50.tinypic.com/2uh206d.jpg. I added in the colum to show the type and added a drop down menu for MD5, SHA1, and SHA256.

Yacoby it already does compare. If you fill in the original box and generate output it will compare. I am looking for testers still if anyone wants to give it a shot.

Since I added SHA I am wondering if I should just put all the conversion methods in one class or separate out MD5 and SHA. Because I think SHA1 and SHA256 could fall under the same class since they are similar hashes. It wouldn't make too much sence to separate them when I could just label the methods.

Also, I still do not understand why Expression Blend keeps crashing, both 3 and 4 crash. It would be nice to be able to use it to test interface designs without affecting my code.
User avatar
Dan Stevens
 
Posts: 3429
Joined: Thu Jun 14, 2007 5:00 pm

Post » Thu Sep 23, 2010 8:18 am

Since I added SHA I am wondering if I should just put all the conversion methods in one class or separate out MD5 and SHA. Because I think SHA1 and SHA256 could fall under the same class since they are similar hashes. It wouldn't make too much sence to separate them when I could just label the methods.

They aren't really though. SHA256 and SHA512 only differ by the message digest size but I am fairly sure SHA-1 and SHA-2 differ quite a lot.

I would question why any of them need their own classes at all? Unless you are writing your own algorithms you may be ending up with a abstraction of the underlying API where each method in the layer of abstraction contains another function call. I don't know exactly how your code is structured so I can't really comment :shrug:

If you are using something like http://msdn.microsoft.com/en-us/library/system.security.cryptography.hashalgorithm.aspx and want to have a wrapper method I would just write a class where you can decide on the algorithm to use using http://en.wikipedia.org/wiki/Dependency_injection (Pass an instance of the class to the constructor of the wrapper class). The alternatives would be to either something similar to the http://en.wikipedia.org/wiki/Strategy_pattern or write a http://en.wikipedia.org/wiki/Higher-order_function which could have the advantage of removing your relance on the hash algorithm having to inherit from System.Security.Cryptography.HashAlgorithm (It depends how versatile the language you are implementing it in is)

The alternative, although far more like abstraction for the sake of abstraction would be to have a base class of which all implemented algorithms are subclasses.
User avatar
Deon Knight
 
Posts: 3363
Joined: Thu Sep 13, 2007 1:44 am

Post » Thu Sep 23, 2010 12:03 pm

New to me...

Well it is how I would organize it but since they are separate classes I will write my method for each in their own class. Did you want to test out the program when I get SHA256 finished or as it is?
User avatar
Rob
 
Posts: 3448
Joined: Fri Jul 13, 2007 12:26 am

Post » Thu Sep 23, 2010 10:57 am

Well it is how I would organize it but since they are separate classes I will write my method for each in their own class. Did you want to test out the program when I get SHA256 finished or as it is?


Cryptographic algorithms are a really good example of where you should learn to use the Strategy pattern or dependency injection that Yacoby brought up.

It's important to be able to "tell" the program which algorithm to use at runtime and to be able to update the program to add algorithms easily. If you get into the mode of stuffing several algorithms into one class, or putting anything into the class that isn't immediately necessary for the algorithm itself, you will end up doing a lot more work each time you have to update the program.

If a crypto algorithm class is more complicated than:

Constructor
init() // where init() may take arguments like a key or salt
append() // which feeds an array, file, stream, whatever of data into the algorithm
result() // which reads out the result
Destructor

it's too complicated. (Note that by my definition, System.Security.Cryptography.HashAlgorithm is not only too complicated, it is a travesty.)

You then use the Strategy pattern (which is really constructor-based dependency injection) or dependency injection driven by the control that selects the algorithm to instantiate a crypto algorithm of the desired class and feed it to the class that handles input and presentation.
User avatar
Jennifer Munroe
 
Posts: 3411
Joined: Sun Aug 26, 2007 12:57 am

Post » Thu Sep 23, 2010 7:04 pm

So I have finally gotten my hash generator/comparer to an almost final state (I think, I still have some ideas for it) and was hoping to get some testers.

http://i48.tinypic.com/70ci00.jpg

Download temporarily removed. Will edit to replace it later.

The download is just the executable for the application itself. I didn't see a real need to put it in a .zip, though I could if needed. I may only leave it up for about a day or so to get some feedback.

This post is going to serve as the readme since its going to be very short.

The application does require .NET 3.0 to run. Since I am not familiar with threading yet if you open a large file it will cause the application to hang until it gets opened. I am currently looking into solving this issue though, and hopefully will have something soon. It does generate and verify hashes for both file and text data. The list at the bottom store any input processed in the current session, closing the application and reopening it does clear the list. I have an exporter planned but not sure how I want to approach it yet, I have either plain text or XML in mind.

I am looking for feedback and suggestions, also any errors or problems that are encountered as well.

Ideas remaining for this program:
- read a text file to process batch input
- threading for file and batch processing
- export processed data as either plain text or XML
User avatar
Rich O'Brien
 
Posts: 3381
Joined: Thu Jun 14, 2007 3:53 am

Post » Thu Sep 23, 2010 8:48 am

Does anyone know how to get constructors to work in JavaScript when you need to pass an unknown number of arguments up the constructor chain.

What I want to do is something like this

function SuperClass(arg1){    print(arg1);}function Class(){    this.__proto__ = new SuperClass(); //?This needs to be constructed with the arguments from constructing Class()}c = new Class('foo');


The issue I seem to be having is that I can't seem to create a new instances of SuperClass that takes the arguments from Class. I know it could be done using eval, but I want to avoid that if possible.


Ideas remaining for this program:
- read a text file to process batch input
- threading for file and batch processing
- export processed data as either plain text or XML


I cannot test ATM. I need to upgrade my Mono version...

Anyway, regarding exporting what about csv. It is easier to parse than XML...
User avatar
REVLUTIN
 
Posts: 3498
Joined: Tue Dec 26, 2006 8:44 pm

Post » Thu Sep 23, 2010 10:54 am

Does anyone know how to get constructors to work in JavaScript when you need to pass an unknown number of arguments up the constructor chain.

The correct way to do that is not to try to force the classic OO model on Javascript, or use a library that takes care of the gory details.

Anyway, regarding exporting what about csv. It is easier to parse than XML...

I think he's using C#, in which case dealing with XML takes just a few lines.
User avatar
Talitha Kukk
 
Posts: 3477
Joined: Sun Oct 08, 2006 1:14 am

Post » Thu Sep 23, 2010 2:23 pm


I cannot test ATM. I need to upgrade my Mono version...

Anyway, regarding exporting what about csv. It is easier to parse than XML...

I was thinking of giving the option. The text option would be csv but the user could also choose XML if they want. I may start with just csv though, options are always useful though.
User avatar
Austin England
 
Posts: 3528
Joined: Thu Oct 11, 2007 7:16 pm

Post » Thu Sep 23, 2010 4:36 pm

The correct way to do that is not to try to force the classic OO model on Javascript, or use a library that takes care of the gory details.


It isn't a major issue, as I can just write:

function SiteRow(db, tbl, id){    this.__proto__ = new Db.Row(db, tbl, id);}


I know it probably isn't the proper way to write JS, but then I have designed the application as I would a classical OO based one :P

Given that it is my first major JS app, I am resigned to the fact that it is going to get rewritten. Probably fairly soon :(

I think he's using C#, in which case dealing with XML takes just a few lines.
Ok. I haven't used C# in ages, and never to try and write XML.
User avatar
Laura Wilson
 
Posts: 3445
Joined: Thu Oct 05, 2006 3:57 pm

Post » Thu Sep 23, 2010 6:42 am

Another question.

When you do something like this:
function Foo(){}Foo.prototype.bar = 0;


What happens when you do this:
f = new Foo();f.bar = 1;


As:

function Foo(){}Foo.prototype.bar = 1;f1 = new Foo();f1.bar = 2;Foo.prototype.bar = 3;print(f1.bar);//2f2 = new Foo();print(f2.bar);//3

User avatar
ShOrty
 
Posts: 3392
Joined: Sun Jul 02, 2006 8:15 pm

Post » Thu Sep 23, 2010 3:23 pm

I think he's using C#, in which case dealing with XML takes just a few lines.

Yeah I am using C# and my current project was built using .NET 3.0. Since I am still getting used to working with XML it takes me a bit of code to get it all written but I think it might come out the same amount of code for both ways. Unless there is a better way to handle it then I currently do.
User avatar
Eileen Collinson
 
Posts: 3208
Joined: Thu Dec 28, 2006 2:42 am

Post » Thu Sep 23, 2010 3:03 pm


http://mckoss.com/jscript/object.htm is an excellent tutorial on doing OO in JS, and if you're interested, you might want to try Google's Closure library which takes care of all the nitty gritty details for you. However, I really dislike trying to use classical OO in JS. Every implementation or technique for it that I've tried is either too clumsy or too Javaesque for me. Just stick with normal object hierarchies and use ordinary (new-less) factory functions - it'll make your life easier.

Yeah I am using C# and my current project was built using .NET 3.0. Since I am still getting used to working with XML it takes me a bit of code to get it all written but I think it might come out the same amount of code for both ways. Unless there is a better way to handle it then I currently do.

You should look into http://msdn.microsoft.com/en-us/library/system.xml.serialization.ixmlserializable.aspx.
User avatar
CYCO JO-NATE
 
Posts: 3431
Joined: Fri Sep 21, 2007 12:41 pm

Post » Thu Sep 23, 2010 7:45 pm

http://mckoss.com/jscript/object.htm is an excellent tutorial on doing OO in JS, and if you're interested, you might want to try Google's Closure library which takes care of all the nitty gritty details for you. However, I really dislike trying to use classical OO in JS. Every implementation or technique for it that I've tried is either too clumsy or too Javaesque for me. Just stick with normal object hierarchies and use ordinary (new-less) factory functions - it'll make your life easier.

Thanks for the link. It is (as you say) excellent

The main thing that gets me so far is the fact that globals are implicit rather than explicit.
User avatar
Mandy Muir
 
Posts: 3307
Joined: Wed Jan 24, 2007 4:38 pm

Post » Thu Sep 23, 2010 6:34 pm

Thanks for the link. It is (as you say) excellent

The main thing that gets me so far is the fact that globals are implicit rather than explicit.


Implicit globals are common in script languages. (Perl has them too. PHP and Python, wisely, don't.)

JavaScript now has "use strict", but using it in a way that actually improves code is challenging.
User avatar
IsAiah AkA figgy
 
Posts: 3398
Joined: Tue Oct 09, 2007 7:43 am

Post » Thu Sep 23, 2010 8:54 am

Implicit globals are common in script languages. (Perl has them too. PHP and Python, wisely, don't.)

Wow, something PHP did right. I can't understand why anyone thought they are a good idea.

JavaScript now has "use strict", but using it in a way that actually improves code is challenging.

Ah, I didn't know about http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/. Thanks.
User avatar
Jessica Stokes
 
Posts: 3315
Joined: Fri Jul 28, 2006 11:01 am

Post » Thu Sep 23, 2010 1:06 pm

arr... I'm not used to spend much time on my other laptop, but due to recent events I've been forced to use it. The problem is, it has LinuxMint9, which isn't really a problem... but I've never really done much work on a unix-based operating system and I have no idea what programs to use. My favorite code editor on the Windows laptop I have is Notepad++ which isn't supported on linux. :cold:

What alternatives do I have? I'm looking for lightweight code editors with support for Python 3+ and C/C++

also, the first person to mention either Vim or Emacs will be kicked in the groin.
User avatar
Taylor Thompson
 
Posts: 3350
Joined: Fri Nov 16, 2007 5:19 am

Post » Thu Sep 23, 2010 11:58 am

I searched Google plenty of times but cannot find out how to write out a string in a Console one character at a time. I have done it in the past but I don't recall how and I do not have access to the project or the book I used at the moment. Anyone have any links to a tutorial for this? I spent a few hours on Google yesterday but my connection was iffy and quit loading the search pages.
User avatar
Laura
 
Posts: 3456
Joined: Sun Sep 10, 2006 7:11 am

Post » Thu Sep 23, 2010 11:11 am

arr... I'm not used to spend much time on my other laptop, but due to recent events I've been forced to use it. The problem is, it has LinuxMint9, which isn't really a problem... but I've never really done much work on a unix-based operating system and I have no idea what programs to use. My favorite code editor on the Windows laptop I have is Notepad++ which isn't supported on linux. :cold:

What alternatives do I have? I'm looking for lightweight code editors with support for Python 3+ and C/C++

also, the first person to mention either Vim or Emacs will be kicked in the groin.

Well, I use Vim... ow

You could try some of the default editors packaged with desktop managers. I still use gedit sometimes (with plugins of course).


I still say that Vim is worth it.
User avatar
James Shaw
 
Posts: 3399
Joined: Sun Jul 08, 2007 11:23 pm

Post » Thu Sep 23, 2010 8:08 am

So what's the deal with people biting my head off when I tell them I use Hungarian notation?
User avatar
Elizabeth Lysons
 
Posts: 3474
Joined: Fri Feb 02, 2007 7:16 am

Post » Thu Sep 23, 2010 8:34 am

So what's the deal with people biting my head off when I tell them I use Hungarian notation?

Because (IMHO) it is to some extent totally unneeded.

  • Your function shouldn't be large enough that you can't see the delcaration of all variables
  • Your IDE should be able to tell you what type the variable is
  • Type checking is now done by the compiler in statically typed languages
  • It makes code hard to refactor. If I change an int to a long, I have to rename a lot of variables, despite the fact functionality hasn't changed



It is generally viewed as a bad idea nowadays I think. The only thing I do, and I have seen done in quite a lot of code bases, is start class variables with a lower case m.
User avatar
Pumpkin
 
Posts: 3440
Joined: Sun Jun 25, 2006 10:23 am

Post » Thu Sep 23, 2010 9:55 am

So what's the deal with people biting my head off when I tell them I use Hungarian notation?


Apparently it kills newborn babies.

I don't get it either, it can be quite useful.
User avatar
Oceavision
 
Posts: 3414
Joined: Thu May 03, 2007 10:52 am

Post » Thu Sep 23, 2010 5:51 pm

Well, I use Vim... ow

You could try some of the default editors packaged with desktop managers. I still use gedit sometimes (with plugins of course).


I still say that Vim is worth it.

Vim is a pain in the butt.. I haven't seen the usability value of it yet. It must be light weight, but it's painful to use with no clues on the screen as to how to work with it. You have to read some sort of user manual before you should dare to launch. Otherwise you wouldn't even know how to quit it. kill -all vim seems like the only solution at first.
User avatar
Roddy
 
Posts: 3564
Joined: Fri Jun 15, 2007 11:50 pm

Post » Thu Sep 23, 2010 1:06 pm

Vim is a pain in the butt.. I haven't seen the usability value of it yet. It must be light weight, but it's painful to use with no clues on the screen as to how to work with it. You have to read some sort of user manual before you should dare to launch. Otherwise you wouldn't even know how to quit it. kill -all vim seems like the only solution at first.

Well, noone said the http://unix.rulez.org/~calver/pictures/curves.jpg was at an easy angle. You can basically get by with a couple of commands though (move around, save, delete, insert) until you pick up more.

If you are happy with what you have, why change though :shrug:
User avatar
мistrєss
 
Posts: 3168
Joined: Thu Dec 14, 2006 3:13 am

Post » Thu Sep 23, 2010 6:06 pm

Yup, to each their own, but I still can't understand the "fan base" behind vim. In my opinion a text editor should be easy to use because all you basically want to do is write down some text and save it to a file. I can't be bothered to search for the command for that, let alone how to exit from the editor when you are done. I'm only going to forget those commands the next time I'm using it anyways. I chose nano and pico over vim when I wanted to do some text editing, provided that neither of those were necessarily even available on the systems I logged myself on, but still. I think I completed my thesis using pico to edit some c++ code and the TeX document. Sorry, I always get jumpy when someone starts praising vim, lol. However, I think you are praising functionality and not the user interface.. I can live with that.
User avatar
STEVI INQUE
 
Posts: 3441
Joined: Thu Nov 02, 2006 8:19 pm

Post » Thu Sep 23, 2010 1:34 pm

Yup, to each their own, but I still can't understand the "fan base" behind vim. In my opinion a text editor should be easy to use because all you basically want to do is write down some text and save it to a file. I can't be bothered to search for the command for that, let alone how to exit from the editor when you are done. I'm only going to forget those commands the next time I'm using it anyways. I chose nano and pico over vim when I wanted to do some text editing, provided that neither of those were necessarily even available on the systems I logged myself on, but still. I think I completed my thesis using pico to edit some c++ code and the TeX document. Sorry, I always get jumpy when someone starts praising vim, lol. However, I think you are praising functionality and not the user interface.. I can live with that.

Oh, I am praising the user interface. It is the old thing that you can build something that is very easy to learn to use, or you can build something that is very hard to learn to use but is faster to use once you know how to use it.

Vim makes it far faster to do common tasks (for example, deleting a line is two keystrokes). I find that whatever editor I use now I miss the ability to do things without having to use the mouse. For example, in vim typing /Foo finds the next occurrence of Foo, you can then use n and N to move forwards and backwards to the next occurrence. Things like gedit you have to hit ctrl-F and then navigate a dialog box then press find. If you have to do that most of the time it is faster to use the arrow keys if you can see the next occurrence

I will admit is is exceeding hard to learn how to use and I am not even a tenth of the way there.
User avatar
Céline Rémy
 
Posts: 3443
Joined: Sat Apr 07, 2007 12:45 am

PreviousNext

Return to Othor Games