Unofficial Programming Thread IV

Post » Tue Jun 18, 2013 9:21 am

Can someone please help me with my previous question? The code I'm working with is in C#.
User avatar
Joey Avelar
 
Posts: 3370
Joined: Sat Aug 11, 2007 11:11 am

Post » Tue Jun 18, 2013 4:29 am

Do you have any code that you tried? http://msdn.microsoft.com/en-us/library/system.io.streamwriter.aspx is needed to write out the data, specifically the Write() or WriteLine() methods. http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx would be used to read the data from the file. In both cases this is for simple text files. You then just neeed to set the Text property fo the textbox to the read line from the file. However a more correct way would be to create properties on the form that controls the textbox properties rather than access it directly.
User avatar
Vickey Martinez
 
Posts: 3455
Joined: Thu Apr 19, 2007 5:58 am

Post » Tue Jun 18, 2013 10:22 am

Could you please write out the code that I need for my program. I have no clue what to type. As I have said before I'm fairly new to this.
User avatar
Kayleigh Williams
 
Posts: 3397
Joined: Wed Aug 23, 2006 10:41 am

Post » Tue Jun 18, 2013 7:12 am

I would start with a console application and get familiar with the use of the two classes I have linked. You should start with the basics and work up to the Windows Forms, though I do recommend WPF over forms if at all possible.
User avatar
Anthony Diaz
 
Posts: 3474
Joined: Thu Aug 09, 2007 11:24 pm

Post » Tue Jun 18, 2013 3:18 pm

Absolutely. I was speaking in the most general of terms. If someone is asking how variables work it probably wouldn't help to start talking about memory management.

Fair enough. The vast majority of open-source apps and tools I use personally are written in Java, but that's just my personal experience. For me it really depends on what my deployment targets look like. Java (as long as it's not too hardware specific) is easy to hand out and be confident that you get cross-platform support without too much fussing with packaging. For learning I suppose Python is a good choice. For some reason I've never been a huge fan of Ruby, though.

Absolutely. Fundamentals are the most important thing to learn. Everything else becomes relatively trivial once you have a good foundation. My first CS professor at uni was of the opinion that you should start off with a language that doesn't have a lot of shortcuts, so my first two college CS courses were all about Scheme.

Yeah, WPF is a HUGE improvement over Winforms. It's really the first Microsoft GUI framework that allows for sane MVC GUI design patterns like MVP and Presentation Model (I think MS calls it MVVM, though...Model View ViewModel).
User avatar
Danger Mouse
 
Posts: 3393
Joined: Sat Oct 07, 2006 9:55 am

Post » Tue Jun 18, 2013 11:25 am

MVVM is at least for me a bit much to wrap my head around but I think I partially got it with the programs I have done before, then again I could be wrong. All I know is I have issues with the concept as well as routed events but I still manage to get a halfway decent applications together using my own pretty low standards while I am learning.
User avatar
ezra
 
Posts: 3510
Joined: Sun Aug 12, 2007 6:40 pm

Post » Tue Jun 18, 2013 4:28 am

The general idea is that you create a logical model (the ViewModel) of a UI element and its behavior (like a window or user control) that exposes data that could be displayed by a view, but doesn't actually display anything...then you using the WPF binding framework to make the view be reactive to changes in the ViewModel and bind control values back to certain properties on the ViewModel. Have you explored using an IoC (Inversion of Control) framework to compose your GUI components? It makes designing things like that a lot easier. Microsoft offers the Managed Extensibility Framework in .NET 4. I personally use Spring.net for this, which is a .NET version of the Spring framework for Java.
User avatar
roxxii lenaghan
 
Posts: 3388
Joined: Wed Jul 05, 2006 11:53 am

Post » Tue Jun 18, 2013 12:03 am

I have an idea what MVVM is and what its supposed to do and all that but I don't think I have the skills yet to properly implement it, and I write small enough applications that it isn't really nessesary for them at this point. I do hope to figure it out eventually though.
User avatar
Sierra Ritsuka
 
Posts: 3506
Joined: Mon Dec 11, 2006 7:56 am

Post » Tue Jun 18, 2013 6:23 am

Writing some Python code! Woo! It's been a long time. First time I've really wrote Python in Linux, and I must say, Windows has a better selection of modules. Can't disclose what I'm working on, but it's fun to write, for sure. /biggrin.png' class='bbc_emoticon' alt=':biggrin:' />
User avatar
Krista Belle Davis
 
Posts: 3405
Joined: Tue Aug 22, 2006 3:00 am

Post » Tue Jun 18, 2013 11:58 am

inspirational. i could never handle the dedication of learning a programming language or whatever. good work, keep it up. and when your ready get together and make system shock 3!
User avatar
Bonnie Clyde
 
Posts: 3409
Joined: Thu Jun 22, 2006 10:02 pm

Post » Tue Jun 18, 2013 8:31 am


Never heard of it myself. Then again, I've only been programming in a professional capacity since the '80s. /tongue.png' class='bbc_emoticon' alt=':P' />
User avatar
Robert Jr
 
Posts: 3447
Joined: Fri Nov 23, 2007 7:49 pm

Post » Tue Jun 18, 2013 1:50 am

Using Python 3.2 I wrote the following class. I then have a bunch of functions below it which medify the properties of the class. When I run the program there is a function which generates an address and then through a chain of functions fills in the other addresses.

class netinfo:    addr = ''    netmask = ''    netaddr = ''    fhost = ''    lhost = ''    bcast = ''    hostcount = 0    netcount = 0

For some reason this function does not show the actual value of netinfo.addr even though I know it does have a value as I output it in the main section of the script below this function, and I cannot figure out why. Is there something I ammissingin the chain of functions above it? Right now this function is designedjust to show the data before I do anything with it.

def netaddrs():    noctets = netinfo.netmask.split('.')    print(netinfo.addr)    print(noctets)
User avatar
Lucy
 
Posts: 3362
Joined: Sun Sep 10, 2006 4:55 am

Post » Tue Jun 18, 2013 5:16 am

I know I should never use Many-to-Many relationships but what is the reason for this avoidance when creating database tables?
Like Developers and Skills would have such a link but for whatever reason those tables don't directly link but rather link to a new formed DeveloperSkills table which holds a One-to-Many relationship.
User avatar
m Gardner
 
Posts: 3510
Joined: Sun Jun 03, 2007 8:08 pm

Post » Tue Jun 18, 2013 1:45 am

I have never heard this? Do you have a link to a paper or anything like that?
User avatar
Luis Longoria
 
Posts: 3323
Joined: Fri Sep 07, 2007 1:21 am

Post » Tue Jun 18, 2013 6:26 am

This is the criteria I am working from: http://register.ofqual.gov.uk/Unit/Details/L_601_3203
A little http://gerardnico.com/wiki/data_modeling/relationship I found - not what I need though

I've found the answer myself, thanks for showing an interest though /smile.png' class='bbc_emoticon' alt=':smile:' />

Answer if you'd like to know in my words:
Spoiler
Many-to-Many relationships create countless rows of duplication, like for example in my Dev and Skills tables if I wanted to see how many skills I had, I would end up retrieving not only my skills but every piece of data in my Dev row (F+L name, address, phone number etc) and that would be repeated for every skill I received. So a new table DeveloperSkills is better equipped for the job as it will hold my ID from the Devs table and my skill ID from the Skills table thus decreasing the amount of duplication caused - down side though is all the Joins will decrease performance time. So a need to Join is neccesary but just how much joining is the question /tongue.png' class='bbc_emoticon' alt=':tongue:' />


Edit: Fixed the second link.
User avatar
GabiiE Liiziiouz
 
Posts: 3360
Joined: Mon Jan 22, 2007 3:20 am

Post » Tue Jun 18, 2013 3:00 am

Ah, ok. That is how I would implement a many to many relationship. Saying you should never use many to many is (I am fairly sure) wrong as it is the only way to model some relationships and even if you use another table in the database to represent it, at more abstract representations (Such as ER diagrams) it should be represented as many to many.

Implementing it using data duplication is wrong in most cases unless you are doing clever things with stuff like NoSQL but that in most cases would be sitting on top of a fully normalised database in any case.
User avatar
Miranda Taylor
 
Posts: 3406
Joined: Sat Feb 24, 2007 3:39 pm

Post » Tue Jun 18, 2013 4:40 am


This is the sort of thing that should really be answered by an experienced DBA, but I'd hazard a guess that the resulting index hairiness could potentially cause quite a performance hit, especially with mass updates.
User avatar
Enie van Bied
 
Posts: 3350
Joined: Sun Apr 22, 2007 11:47 pm

Post » Tue Jun 18, 2013 11:12 am

Yeah it was wrong to say "never" because some situations may not need the change and new table, but for the purpose of this document and criteria many-to-many is bad but apparently now so is a one-to-one relationship so I should explain why /bonk.gif' class='bbc_emoticon' alt=':bonk:' />
I wouldn't imagine them being as bad as M2M or would they be the same?
User avatar
Adam Porter
 
Posts: 3532
Joined: Sat Jun 02, 2007 10:47 am

Post » Tue Jun 18, 2013 2:34 pm

That is one problem it can cause, performance slows down when a system tries retrieving all the data over and over but creating the new table to implement One-2-Many joins also impacts the performance - it's a bit of a juggling issue but I cause the lateter is better as the duplication isn't an issue.
User avatar
Kortniie Dumont
 
Posts: 3428
Joined: Wed Jan 10, 2007 7:50 pm

Post » Tue Jun 18, 2013 3:35 pm

Does anyone have any suggestions for my Python 3 issue posted earlier? I still can't understand why I am getting such odd behavior, though the use of the class for just the variables seems a bit much, but I am used to not using globals so that is why I did it this way.
User avatar
Ellie English
 
Posts: 3457
Joined: Tue Jul 11, 2006 4:47 pm

Post » Tue Jun 18, 2013 2:16 pm

Using 2.6 right now but I assume classes work the same way! All you forgot was to add self. before the variable, which tells the class that this is a member. However, using global variables like that is impractical. Throw it in the __init__ function - this function is the constructor of Python classes. /biggrin.png' class='bbc_emoticon' alt=':biggrin:' />
Spoiler
class netinfo:	def __init__(self):		self.addr = ''		self.netmask = ''		self.netaddr = ''		self.fhost = ''		self.lhost = ''		self.bcast = ''		self.hostcount = 0		self.netcount = 0	def changeAddr(self):		self.addr = "123.456.789"	def getAddr(self):		print self.addrif __name__ == '__main__':	n = netinfo()	n.changeAddr()	n.getAddr()


In other news, I figured out the shortest - likely cross platform - way to grab global keyboard input in Python! This program only looks for the Escape key to be pressed, I'm threading something similar to mark the end of a program, but I included a way to test for more than just the Escape key.
Spoiler
# captures keyboard events, prints something out if escape is pressedfrom Xlib.display import Displayfrom Xlib import Xdef handle(mEvent):    keycode = mEvent.detail    if mEvent.type is X.KeyPress:        print keycodedef keyboardHook():    #get current display    display = Display()    root = display.screen().root    # subscribe to keypress events    root.change_attributes(event_mask = X.KeyPressMask)    # subscribe to escape key    root.grab_key(9, X.AnyModifier, 1, X.GrabModeAsync, X.GrabModeAsync)    # multiple keys can be subscribed to like so:    # for i in keylist: #keylist containing your list of desired keys' keycodes    #    root.grab_key(i, X.AnyModifier, 1, X.GrabModeAsync, X.GrabModeAsync)    while True:        event = root.display.next_event()        handle(event)if __name__ == '__main__':    keyboardHook()
Heavily based off a script I found, and influenced by pyxhook. Hope someone finds it useful!
User avatar
James Rhead
 
Posts: 3474
Joined: Sat Jul 14, 2007 7:32 am

Post » Tue Jun 18, 2013 1:36 am


Can I still assign them in other functions just using netinfo.variable? Or do I need functions for each to get/set them?

I think I did it this way since I have a bunch of functions and did not want an instance in eachone. Unless I can make the instance right under the class and use it throughout the program.
User avatar
JERMAINE VIDAURRI
 
Posts: 3382
Joined: Tue Dec 04, 2007 9:06 am

Post » Tue Jun 18, 2013 12:43 pm

I just did that so it'd be more understandable and show they're global members. You can call and set them whenever you want by using either self.variable inside the class or classinstance.variable outside of the class. Example of what I mean:
Spoiler
class netinfo:		def __init__(self):				self.addr = ''				self.netmask = ''				self.netaddr = ''				self.fhost = ''				self.lhost = ''				self.bcast = ''				self.hostcount = 0				self.netcount = 0		def changeAddr(self):				self.addr = "123.456.789"		def getAddr(self):				print self.addrif __name__ == '__main__':		n = netinfo()		n.changeAddr()		n.getAddr()		print n.addr		n.addr = "987.654.321"		print n.addr		n.getAddr()

I don't understand what you mean, care to elaborate?
User avatar
Davorah Katz
 
Posts: 3468
Joined: Fri Dec 22, 2006 12:57 pm

Post » Tue Jun 18, 2013 9:51 am


Uh what. He wasn't using global variables. Class variables aren't global. And no. You don't need a self in front of them as (1) self is not defined and (2) what self? there is no instance of the class as they are class variables.


@http://www.gamesas.com/user/19055-darkonevenzar/
You don't show enough code to show the problem. You need to post enough code for us to be able to reproduce the problem.
User avatar
Kira! :)))
 
Posts: 3496
Joined: Fri Mar 02, 2007 1:07 pm

Post » Tue Jun 18, 2013 12:46 am


I ended up making all functions part of the class and am now using an instance in my main function. I had to reorder a line int he genaddr function and it now works.
User avatar
Jessica Phoenix
 
Posts: 3420
Joined: Sat Jun 24, 2006 8:49 am

PreviousNext

Return to Othor Games