Re: [Mono-list] Questions about coding style

2012-08-21 Thread Jonathan Pryor
On Aug 20, 2012, at 3:28 PM, Philippe Grohrock philippe.grohr...@gmail.com wrote: Thanks for the reply already and I'm sorry, I should've added the lines of code. static class GlobalVariables { public static MySqlConnection connection = new connection(); }

Re: [Mono-list] Questions about coding style

2012-08-21 Thread Stifu
To add to what Jonathan said, trying to reuse the same connection for everything can also lead to concurrent access issues, if more than one thread accesses the connection at a given time. I've seen such issues when using Entity Framework. Besides, creating a new connection is really cheap.

Re: [Mono-list] Questions about coding style

2012-08-20 Thread Jonathan Pryor
On Aug 17, 2012, at 5:49 PM, Philippe Grohrock philippe.grohr...@gmail.com wrote: 1. Is it bad/good style to have a public class that implements global variables? How do you define global variable? :-) `public static` fields are Very Badâ„¢, unless they're `readonly`. This is because there's

Re: [Mono-list] Questions about coding style

2012-08-20 Thread Philippe Grohrock
Thanks for the reply already and I'm sorry, I should've added the lines of code. This way the whole program has access to it and can modify/query the DB when needed (this is what I meant with global). At the moment I have 2 of my windows using that connection, but there might be more in the

Re: [Mono-list] Questions about coding style

2012-08-20 Thread James Wright
I'd create ConnectionFactory class, although feel free to ignore me, just thinking off the top of my head! :-) public class ConnectionFactory { private static MySqlConnection _connection; public MySqlConnection GetConnection() { if (_connection == null) {

Re: [Mono-list] Questions about coding style

2012-08-20 Thread IBBoard
Just in case no-one else spots it, you'll need a static keyword on that GetConnection() declaration, otherwise you have to create an instance to get a reference to the private static variable, which is just odd :) On 20/08/12 20:45, James Wright wrote: I'd create ConnectionFactory

Re: [Mono-list] Questions about coding style

2012-08-20 Thread Gabriel Ibanez
- From: Philippe Grohrock philippe.grohr...@gmail.com Date: Mon, 20 Aug 2012 19:28:07 To: mono-list@lists.ximian.com Subject: Re: [Mono-list] Questions about coding style Thanks for the reply already and I'm sorry, I should've added the lines of code.static class GlobalVariables

Re: [Mono-list] Questions about coding style

2012-08-20 Thread Philippe Grohrock
Be carefull about this way of working with DB. You must free the connections as fast as you can and I'm not sure you can do like this way. Basically the connection gets initialised when the application starts and every time I need a query, the connection gets opened, queried, closed, but not

Re: [Mono-list] Questions about coding style

2012-08-20 Thread James Wright
Unless I'm mistaken .NET connections are pooled for you, so I don't think you'll be gaining much from keeping one instance of the connection always open as the framework is already doing just that. My advice is don't worry about it until you have to... chances are it won't be a problem in

Re: [Mono-list] Questions about coding style

2012-08-20 Thread Philippe Grohrock
Unless I'm mistaken .NET connections are pooled for you, so I don't think you'll be gaining much from keeping one instance of the connection always open as the framework is already doing just that. My advice is don't worry about it until you have to... chances are it won't be a problem in

[Mono-list] Questions about coding style

2012-08-17 Thread Philippe Grohrock
Yes I am currently working alone, but I still think that learning about some coding style isn't too bad after all, so I have two questions and I thought I'd ask them both in the general section. 1. Is it bad/good style to have a public class that implements global variables? My program readys a