Unofficial Programming Thread II

Post » Tue May 17, 2011 4:23 am

What language do you write in? I use C# and am not familiar with how to load non-.NET assemblies yet. Using those written in .NET seems easy enough at least to reference them, dynamically loading them on the other hand is not as easy.

I use C# as well.
User avatar
sam smith
 
Posts: 3386
Joined: Sun Aug 05, 2007 3:55 am

Post » Tue May 17, 2011 2:09 am

What language do you write in? I use C# and am not familiar with how to load non-.NET assemblies yet. Using those written in .NET seems easy enough at least to reference them, dynamically loading them on the other hand is not as easy.

I'm not entirely sure what you mean by non-.NET assemblies in this case, but maybe you can communicate with it through the COM interface. I guess an "assembly" is what .NET uses in this context. Your problem can also have something to do with search paths for the dll's. To be sure, copy the dll to the same directory with the executable if you have not.

Maybe this link I ran across is related to your problem..
http://www.comanswer.com/question/how-to-register-a-non-strong-name-assembly-to-be-loaded-as-if-it-were-in-the-gac
User avatar
John N
 
Posts: 3458
Joined: Sun Aug 26, 2007 5:11 pm

Post » Tue May 17, 2011 2:14 am

Well I tried to use a DLL from WinRAR (they provided on their website if I recall correctly) and 7zip and was told by Visual Stduio I couldn't use them. I think to use them in a .NET application you need to do somethign special. I am not entriely sure yet.
User avatar
Kay O'Hara
 
Posts: 3366
Joined: Sun Jan 14, 2007 8:04 pm

Post » Mon May 16, 2011 11:56 pm

Hey guys, I wrote some code not long ago and haven't gotten around to testing it out until a few minutes ago. It's a program that takes user input, and stores it in a .txt file:
Spoiler

#include #include #include int main(){	//FreeConsole(); uncommented in build	char inp;	std::ofstream File("HelloWorld.txt");		std::cout << "Created file...";	do	{		inp = std::cin.get();		File.put(inp);	}while(inp != '~');		File.close();			std::cout << "Closed file...";	return 0;}



Now, the .txt file is over 54mb and when I used Python to read the first 5000 bytes (any word program would freeze up and crash opening it) it looked like this:
Spoiler

>>> fob = open("C:\\Users\\...\\Documents\\Visual Studio 2010\\Projects\\...\\Debug\\HelloWorld.txt")>>> sample = fob.read(5000)>>> print sample????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????>>> fob.close()


Is it a placeholder for no key being pressed? Is it because of cin.get()? It has also printed 'xff\' in place of the accented y's - can't remember what I did exactly. Google hasn't helped thusfar.
Thanks guys!
User avatar
Dominic Vaughan
 
Posts: 3531
Joined: Mon May 14, 2007 1:47 pm

Post » Mon May 16, 2011 10:54 pm

I cannot reproduce the problem on Linux. You could considering adding some error checking to check if cin has got any error flags set.

(Although I don't think the program would work if you uncommented the line FreeConsole(); You can't read input from a non existent terminal.)
User avatar
Big mike
 
Posts: 3423
Joined: Fri Sep 21, 2007 6:38 pm

Post » Tue May 17, 2011 11:07 am

What do you guys think of Hungarian notation? I've been reading through a lot of C# books and tutorials and most of them are against Hungarian notation when declaring variable/function names.

I personally use camelBack, so the first word is entirely lowercase and the second one starts with a capital letter. I'm not sure why, I just started doing this automatically when I was learning to program (before I even knew about CamelCase and Hungarian notation). So for example when I'm naming a button in an app that submits data I would name is submitButton :shrug:
User avatar
Bonnie Clyde
 
Posts: 3409
Joined: Thu Jun 22, 2006 10:02 pm

Post » Tue May 17, 2011 6:54 am

What do you guys think of Hungarian notation? I've been reading through a lot of C# books and tutorials and most of them are against Hungarian notation when declaring variable/function names.

I personally use camelBack, so the first word is entirely lowercase and the second one starts with a capital letter. I'm not sure why, I just started doing this automatically when I was learning to program (before I even knew about CamelCase and Hungarian notation). So for example when I'm naming a button in an app that submits data I would name is submitButton :shrug:


Hungarian notation is good in some cases, I tend to use a mix of it and your convention. For example, I'll always prefix a class name with a capital C (e.g. CLinkedList), and I tend to prefix class member variables with a lower case m (e.g. mData) just so that I can see from my code what they are at a glance.

It doesn't really matter what you do as long as you keep it consistent.
User avatar
Far'ed K.G.h.m
 
Posts: 3464
Joined: Sat Jul 14, 2007 11:03 pm

Post » Tue May 17, 2011 2:54 pm

What do you guys think of Hungarian notation? I've been reading through a lot of C# books and tutorials and most of them are against Hungarian notation when declaring variable/function names.

Which are we talking about. System or Application Hungarian notation?

IMHO they are both sins. Application Hungarian may be OK in some cases, but it is basically working around a bad type system that doesn't allow you to easily create new types (Not type aliases).

System Hungarian is stupid. If I can't see where the variable was defined from where I am using it, I am writing bad code. My text editor can tell me what type the variable is anyway.


For clarity, I do use a prefix for class members. Either m or _ depending on the language conventions. This is mainly a hang over from C++, where it wasn't required that I use `this` to access member variables.
User avatar
Rob Smith
 
Posts: 3424
Joined: Wed Oct 03, 2007 5:30 pm

Post » Tue May 17, 2011 5:24 am

What do you guys think of Hungarian notation? I've been reading through a lot of C# books and tutorials and most of them are against Hungarian notation when declaring variable/function names.

I personally use camelBack, so the first word is entirely lowercase and the second one starts with a capital letter. I'm not sure why, I just started doing this automatically when I was learning to program (before I even knew about CamelCase and Hungarian notation). So for example when I'm naming a button in an app that submits data I would name is submitButton :shrug:

I mainly use PascalCase (I think thats the name) for my variables and methods. When I do classes I try to prefix with a C but it doesn't always happen. my boolean variables always start with Is and I try to keep constants in all capitals. I think on the rare occasion I use an enum I will start doing those in all capitals as well.
User avatar
Jack
 
Posts: 3483
Joined: Sat Oct 20, 2007 8:08 am

Post » Tue May 17, 2011 7:05 am

While we're talking about conventions...
What do you guys name your class with the main method in it / main class?
User avatar
Cesar Gomez
 
Posts: 3344
Joined: Thu Aug 02, 2007 11:06 am

Post » Tue May 17, 2011 6:54 am

While we're talking about conventions...
What do you guys name your class with the main method in it / main class?

I just leave it with its default name. I prefix my forms with either an f or the whole word form, and then after that I stick with a shorthand version of the application name.
User avatar
x a million...
 
Posts: 3464
Joined: Tue Jun 13, 2006 2:59 pm

Post » Tue May 17, 2011 12:10 am

While we're talking about conventions...
What do you guys name your class with the main method in it / main class?

the default name
User avatar
ruCkii
 
Posts: 3360
Joined: Mon Mar 26, 2007 9:08 pm

Post » Tue May 17, 2011 7:13 am

(Although I don't think the program would work if you uncommented the line FreeConsole(); You can't read input from a non existent terminal.)

Thanks man, I didn't realize that. :P

Guess it's about time I learn how to write keyboard hooks.
User avatar
Travis
 
Posts: 3456
Joined: Wed Oct 24, 2007 1:57 am

Post » Tue May 17, 2011 6:41 am

Does anybody know about some good C# resources and tutorials?

I've been using C# Visual Studio 2010 a lot lately and I absolutely love this language, my most recent project was a Twitter client and I had a lot of fun developing that.
User avatar
Elizabeth Falvey
 
Posts: 3347
Joined: Fri Oct 26, 2007 1:37 am

Post » Tue May 17, 2011 2:12 am

Does anybody know about some good C# resources and tutorials?

I've been using C# Visual Studio 2010 a lot lately and I absolutely love this language, my most recent project was a Twitter client and I had a lot of fun developing that.

The book http://www.amazon.com/Essential-4-0-Microsoft-NET-Development/dp/0321694694, I used http://www.vijaymukhi.com/documents/books/csbasics/csharp1.html when I first started learning it. And of course, http://msdn.microsoft.com/en-us/library/618ayhy6%28v=VS.71%29.aspx.
User avatar
Niisha
 
Posts: 3393
Joined: Fri Sep 15, 2006 2:54 am

Post » Tue May 17, 2011 5:46 am

Does anybody know about some good C# resources and tutorials?

I've been using C# Visual Studio 2010 a lot lately and I absolutely love this language, my most recent project was a Twitter client and I had a lot of fun developing that.

I have two books: Wrox Beginning C# 2005 9 was required for a class so I got it before he said using 2008 was fine) and C# Step by Step by Microsoft. I prefer the Wrox book as it gives you projects to work on but the Microsoft one uses more WPF and I think coveres more recent stuff.
User avatar
Strawberry
 
Posts: 3446
Joined: Thu Jul 05, 2007 11:08 am

Post » Tue May 17, 2011 4:21 am

Anyone have any ideas for programs I could write to help teach myself the language? I am looking to a couple books labelled as 'professional' to use once I finish this Step by Step book, but I would rather jump into a project. I got a request to do a login to a website to pull notifications from but I am not sure where to start with that and to me it would be a multiple person project.

Also, I have an interview in a couple weeks for a potential programmer position, they told me of a second nonprogramming position but I figure if I can learnf rom it I may do it. Though the position would not be open until summer, I want to learn some more before I go to the interview at least, and then alot more by summer.

I also am stuck again with choosing between WinForms and WPF. It seems most books that target C# 2010 (using .NET 4) focus on WPF but to me that seems excessive for basic applications. Anyone have any input into this? I know I have probably mentioned it a couple times already.
User avatar
Oscar Vazquez
 
Posts: 3418
Joined: Sun Sep 30, 2007 12:08 pm

Post » Tue May 17, 2011 9:56 am

You can start by doing small things here and there, just familiarizing with what is possible, what's already there. I mean, I saw a pre-built UI component for a web browser in Visual Studio 2010. I picked WinForms, attached the browser into the form, added line input for the web address, and voila, I have a web browser. It probably just links an IE frame into the app, but it's so much faster to do this than start a web browser from scratch. I can take that further by adding a component to feed in several addresses, divide the view into multiple different web browser frames, or turn it into a web crawler of some kind that would fetch web sites and store them to disk for later viewing, maybe even alert me of changes. Shrugs. It would be fancy if it would just browse the web for me based on my preferences and then load just the pages I might be interested in. I mean, that would save me hours and probably takes only a week to do. However, it would then need fine tuning and that would take a lot longer.

Another thing that might help me with running Folding@Home and Boinc would be an app that simply starts and stop services and applications on a single click. I already have two list boxes, one for services and the other for apps, and I can do just that. The app is not very usable right now though, because it does not even save the list so that I could run it from the desktop. Kinda like what GameBooster already does. Come to think of it, GameBooster might allow adding custom services and apps to the list already, hmm..

Once you have tried a few basic things, built user interfaces etc, you might see which ideas you want to take further. It can be just a personal project. It does not matter if it's already been done since you are trying to learn things. It does not need to be that useful either at that point. Maybe if you intend to release it. In any case, that would be a great addition to your resume.

I used google and msdn to pull those off. I don't think I have any books on C# here at home, but it seems to me that it's quick to develop user interfaces with this thing so you can just try a few things out, do prototyping as they say. On Windows, I've worked with MFC and C++ mostly. I just started looking into .Net and WinForms out of curiosity, and don't even know what WPF is yet.
User avatar
Kevin Jay
 
Posts: 3431
Joined: Sun Apr 29, 2007 4:29 am

Post » Tue May 17, 2011 9:29 am

anybody know anything about Microsoft silverlight? i was thinking of creating apps for a windows phone
User avatar
GabiiE Liiziiouz
 
Posts: 3360
Joined: Mon Jan 22, 2007 3:20 am

Post » Tue May 17, 2011 3:00 pm

If anyone is interested in working on a project I am planning to work on a gradebook application using WPF. I write in C# but anyone who works in .NET is welcoem to join the project. If enough people are interested we can probably use GoogleCode to host it.

Time from for this project though: completed (or workable) by January 6, 2011. I am sure with even two or three people this can be met. If it goes on a little bit longer then it is no big deal since its not for a grade or job, but a personal project.

Anyone interested is welcoem to send me a PM.
User avatar
Lil Miss
 
Posts: 3373
Joined: Thu Nov 23, 2006 12:57 pm

Post » Tue May 17, 2011 1:27 pm

I recently noticed that the source code for Oblivion Stutter Remover / Fallout Stutter Remover / New Vegas Stutter Remover 4.1.0 was downloaded like 1600 times or something. That kind implies that there's a ton of people around here who know C++ and/or asm or at least think they might understand enough of it to get some of what's going on in the source code.
User avatar
Philip Lyon
 
Posts: 3297
Joined: Tue Aug 14, 2007 6:08 am

Post » Tue May 17, 2011 12:09 am

Can anyone who uses .NET (or a language that uses them) explaint o me what Interfaces are for? My book just really gives you the code and says "this is how you write it" then gives you an example of two shapes using the same interface for their size and color. Are they just used to access the default constructor easier if it requires parameters, or does it hold default values if there are no parameters?
User avatar
jaideep singh
 
Posts: 3357
Joined: Sun Jul 08, 2007 8:45 pm

Post » Tue May 17, 2011 12:05 pm

Can anyone who uses .NET (or a language that uses them) explaint o me what Interfaces are for? My book just really gives you the code and says "this is how you write it" then gives you an example of two shapes using the same interface for their size and color. Are they just used to access the default constructor easier if it requires parameters, or does it hold default values if there are no parameters?

One way to think of interfaces is as a kind of protocol, defining what sort of communication an object can process.

For instance, the Buttons in Android use listeners to handle a events. Specifically, there's an http://developer.android.com/reference/android/view/View.OnClickListener.html. It's an interface with a method onClick. A class implementing this interface indicates through polymorphism that it is an OnClickListener, and as such is able to process onClick events.

There's another http://en.wikipedia.org/wiki/Interface_(object-oriented_programming) about Java's Comparable.

The http://en.wikipedia.org/wiki/Strategy_pattern is also typically implemented using an interface.

Note: the protocol comparison was shamelessly ripped from Wikipedia. I actually had no idea how to explain interfaces. What's up with that?
User avatar
Benji
 
Posts: 3447
Joined: Tue May 15, 2007 11:58 pm

Post » Tue May 17, 2011 11:13 am

So i want to use it if two classes have common methods or constructors to ensure they get the right values?
User avatar
maria Dwyer
 
Posts: 3422
Joined: Sat Jan 27, 2007 11:24 am

Post » Tue May 17, 2011 1:12 am

So i want to use it if two classes have common methods or constructors to ensure they get the right values?

You cannot define a constructor in an interface, at least in Java. (If you want to force creation of objects of different types with the same type of parameters, you should take a look at the factory pattern.)

But other than that, yes, that's the general idea.

An interface is generally used to abstract the protocol from its implementation. For example, if all you want is to write some data, you might define an interface DataWriter, with a method write(byte[] buffer). A class that uses a DataWriter can then use any implementation of the DataWriter interface, regardless of how write(byte[] buffer) is implemented. This is the gist of the strategy pattern.

I hope I'm making sense.
User avatar
Cartoon
 
Posts: 3350
Joined: Mon Jun 25, 2007 4:31 pm

PreviousNext

Return to Othor Games