This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Foo { | |
//Event | |
public event EventHandler UserLoggedIn; | |
//Typed delegate | |
public delegate void UserLoggedInDelegate(); | |
public UserLoggedInDelegate UserLoggedIn { get; set; } | |
//Generic delegate | |
public Action UserLoggedIn { get; set} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// What are the semantics of IsLoggedIn? | |
public int IsLoggedIn(); | |
//Wouldn't this be better? | |
public bool IsLoggedIn(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserManager { | |
public bool IsLoggedIn { get; private set; } | |
public void LogIn(string userName, string password) { | |
if (IsLoggedIn) { | |
throw new InvalidOperationException("The user is already logged in"); | |
} | |
if (userName == _userName && password == _password) { | |
IsLoggedIn = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserManager { | |
//This class allows other code to perform username/password validation. Which is the better way to do this? | |
public class AuthenticateUserEventArgs : EventArgs { | |
public string UserName { get; set; } | |
public string Password { get; set; } | |
} | |
// This is one way | |
public event EventHandler<AuthenticateUserEventArgs> AuthenticateUser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When a method outputs two or more values, use output parameters and return void | |
public void GetUserInfo(out string userName, out string password) { | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//What the hell is going on here? I can't read it! | |
public class Foo { | |
private string Name; | |
private string Password; | |
public string UserName { get { return Name; } set { Name = value; } } | |
public bool ValidateUser(string UserName, string Pass) { | |
string CurrentUserName = UserName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserManager { | |
// This property is doing WAY too much work to be a property | |
public string[] Users { | |
get { | |
var usersList = new List<string>(); | |
using (var connection = ConnectToDatabase()) { | |
var users = connection.GetUsersTable(); | |
users.Rows.ForEach((row) => usersList.Add(row.UserName)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserManager { | |
public void AuthenticatedUser(string userName, string password) { | |
if (userName != _userName) { | |
//WTF does 'ApplicationException' mean? It means "something didn't work" | |
//That's not very helpful | |
throw new ApplicationException("Invalid username"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class UserManager { | |
public void Authenticate(string userName, string password) { | |
try { | |
_userDatabase.Authenticate(userName, password); | |
} catch (Exception e) { | |
// Now if authentication fails, when you catch AuthenticationFailedException | |
// you have no idea what actually caused the authentication to fail. | |
// That will make debugging, especially in the field, very hard | |
throw new AuthenticationFailedException(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated on 2015-09-14 using generator-angular 0.12.1 | |
'use strict'; | |
// # Globbing | |
// for performance reasons we're only matching one level down: | |
// 'test/spec/{,*/}*.js' | |
// use this if you want to recursively match all subfolders: | |
// 'test/spec/**/*.js' | |
module.exports = function (grunt) { |
OlderNewer