On a shitty game I'm working on with a friend, we had a quick discussion about what we were going to name 5 clone antagonists. I mentioned George, no objections, now we've gone too far to rename them. George1 - George5 and the protagonist is PlayerMan
Skeczi ยท 62 points ยท Posted at 19:57:59 on May 23, 2016 ยท (Permalink)
Why did you not call them GeorgeCloney1-GeorgeCloney5?
jimanri ยท 23 points ยท Posted at 00:31:53 on May 24, 2016 ยท (Permalink)
Stop lying to yourself, we all know you have a favorite
arturaz ยท 1 points ยท Posted at 04:21:01 on May 24, 2016 ยท (Permalink)
Until Unity introduced FormerlySerializedAsAttribute, renaming a public fields dropped all serialization references in the editor. That used to be "fun"...
I would research and link if i wasn't on cell with horrible internet but basically the character's sprite brush was drawn before he was named, so they saved the file as 'guybrush' and it stuck. There's some kind of origin story for Threepwood too but I don't remember off hand what it is. I'll look it up when I get off work.....
[edit] From Wikipedia:
The origin of the name "Guybrush" comes in part from Deluxe Paint, the tool used by the artists to create the character sprite. Since the character had no name at this point, the file was simply called 'Guy'. When the file was saved, Steve Purcell, the artist responsible for the sprite, added 'brush' to the filename, indicating that it was the Deluxe Paint "brush file" for the "Guy" sprite. The file name was then "guybrush.bbm", so the developers eventually just started referring to this unnamed 'Guy' as "Guybrush".[2][3]
And the surname:
Guybrush's surname "Threepwood" was decided upon in a company contest and is derived from P. G. Wodehouse's family of characters including Galahad Threepwood and Freddie Threepwood (with whom he shares similar characteristics).
// Initializing Foos with a list initializer.
List<Foo> FooList = new List<Foo>() {
new Foo('bar'),
new Foo('bat')
};
// This lets you use LINQ and anon functions (lambda syntax) to query your collection:
Foo myFoo = FooList.First(foo=>foo.property == 'bat')
If you expand upon this with a static factory, it gets even more concise:
public static class EnemyFactory
{
private static Enemy ScaryEnemy()
{
[insert complicated algoritm to get constructor params here]
return new ScaryEnemy(params) as Enemy;
}
private static Enemy WeakEnemy()
{
[insert complicated algoritm to get constructor params here]
return new ScaryEnemy(params) as Enemy;
}
public static List<Enemy> MakeMob(numberOfWeakEnemies, numberOfScaryEnemies)
{
var result = new List<Enemy>();
[iterate the private factory me thods, adding to result]
return result;
}
}
This is an example of what I would describe as a static factory class. It is a static class (obviously) which has factory methods.
Why are you questioning my common sense? Do you not understand OO design patterns?
There are four cornerstones and five principles which describe robust OO code (C# is a primarly OO language which supports FP as well).
The four cornerstones of Object Oriented Programming are Encapsulation, Abstraction, Polymorphism, and Inheritance (Thanks, /u/LyonesGamer, for pointing out my typo).
The five guiding principles are SOLID: Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion.
My approach is justified because it exemplifies encapsulation, abstraction, and single responsibility by letting a generic class (List) handle the inevitable management of the collection.
This approach, while technically valid, is going to be a real pain in the ass later. It makes iterative programming almost impossible. If we use a collection, we can quickly iterate and filter it. Trust me on this, you will thank me later.
There are infinite reasons to use iterable data structures to store groups of objects which have a common purpose. For example, suppose that you want all enemies within 10 meters of the player to aggro on him. With your approach, you would need to write something like this:
This alone is tedious as fuck! Imagine implementing aggro chaining (so all enemies in a cluster attack when the player gets in range of one). That would be almost impossibly tedious, and your source code would bloat soooo much.
If we use an iterative approach, we can write objectively better code to solve the same task (less development time, more maintainability, more extensibility):
Or without LINQ (because not everyone likes functional programming):
for(Enemy e in Enemies) {
if(Physics.Distance(enemy, Player) < 10) {
e.Attack(Player);
}
}
The approriate place to use a singular type is when we are working with a singular object.
The appropriate place to use a collection type is when we are working with a collection.
TL;DR: If you use tools appropriately, you will be a lot more productive. Use collections to handle groups of similar objects. Use singular types to handle individual instances. Microsoft has written some incredible tooling for the .NET Framework -- embrace it!
List enemies = new List(enemyOne, enemyTwo, enemeyThree):
in fact id even argue that not making a list until its needed is the iterative approach. If youre building infrastructure to your code before you need it then that isnt being iterative.
Agreed. Building infrastructure before building details is not iterative programming at all. It's just plain smart. That's why the .NET Framework exists -- so that you don't have to! However, the infrastructure we are talking about is centered around making groups of related variables iterable. The manner that the .NET framework implements this infrastructure is supported by decades of OO theory and has been refined by world-class developers to be extremely efficient. Why would you NOT use the tool that is freely available to you?
This takes a full screenshot, uploads it (AS LOSSLESS PNG, NOT JPEG), and copies the URL to your clipboard.
I have that bound to a keybind. Press that, paste in an SMS to whomever. Simple.
There's also imgur-screenshot, but you have to actually install and configure that, and I find imgur really unreliable anyways. Their jpeg compression is poop too.
LWdkw ยท 5 points ยท Posted at 17:01:22 on May 23, 2016 ยท (Permalink)
I bound it to a keybind and pressed it. I still haven't received a screen shot of my friend's monitor though. What did I do wrong?
Well, this will take a screenshot of the current computer's desktop. Press that keybind, and then Ctrl-V and Return in the URL bar of your web browser. You should see that screenshot load up.
If you want to send it, just paste that URL in an SMS or email, etc.
Make sure you have all of the programs called in the script installed. Most of it is standard on linux desktops, but you'll need scrot, notably. Also, it displays a confirmation notification, but you'll need libnotify installed and configured for them to display. I use dunst for notifications (highly recommended!).
You'll also need xclip installed for it to copy the URL to your clipboard, but you can substitute xclip for xsel, depending on your preferences. They both do the same thing. I actually prefer xsel because it's more straightforward and the commands are shorter (xclip -selection clipboard versus xsel -b, for example) ; I've been meaning to convert all of my scripts to xsel. Thanks for reminding me! :)
LWdkw ยท 4 points ยท Posted at 17:26:13 on May 23, 2016 ยท (Permalink)
Uh, so, thank you for being nice and explaining! I was really being an ass though and pointing out the fact that if your friend has something on their screen, doing whatever with your own PC won't help you :)
That's alright. I wasn't sure if you were being sarcastic or not, so I decided it would be best to assume you weren't.
Anyways, it's not an "ideal" solution, as it's not default behaviour (I know many people who can't wrap their heads around things that don't have a GUI). It is very simple to implement, though, and it's very efficient when it is.
Yeah. Why waste private variables when you don't need to do anything fancy in your getters/setters. Also, this is freaking C#, not JavaScript. Get your camel case right.
S1CKLY ยท 20 points ยท Posted at 16:33:00 on May 23, 2016 ยท (Permalink)
Why waste private variables when you don't need to do anything fancy in your getters/setters.
Because OP's code is in Unity3D which does not serialize properties.
00yoshi ยท 4 points ยท Posted at 17:55:11 on May 23, 2016 ยท (Permalink)
But these also contain a variable when compiled to IL code.
devluz ยท 1 points ยท Posted at 21:57:45 on May 23, 2016 ยท (Permalink)
Unity only serializes public variables. At least in default setup. And more and more universities use it to teach ... I hope the C# code reviewer are prepared for a culture shock ;)
00yoshi ยท 2 points ยท Posted at 22:17:01 on May 23, 2016 ยท (Permalink)
What do they teach? How to make a game? Well, at least you only need to program it once and can put it out for mobile and desktop and console. (Lets see how good my shaders will run on mobile...)
devluz ยท 1 points ยท Posted at 22:58:01 on May 24, 2016 ยท (Permalink)
It is often used to teach Game development and VR. Unity itself is great. It is just bad if people only know unity and think that is the "normal" way to use C#.
00yoshi ยท 2 points ยท Posted at 13:42:14 on May 25, 2016 ยท (Permalink)
Well, they really should start out with visual studio community (since it's free) and then go over to unity, after they learned the basics.
I think you mean {get; private set;}. The way you wrote it, the property can only be set by a constructor, and can't be changed in that instance anymore.
That's interesting. I work with a guy who has a degree in CS and ONLY uses the underscore notation (unless a group agrees on something else, of course). It seems like it's preference? You seem to vehemently oppose the notation, but others down below like it.
I do vehemently despise the notation, because it adds a bunch of useless noise to the code at no added value. It is a bit of a preference, and makes more sense in C/C++ code (which is where this convention comes from) but in C# it's not necessary.
This is one of those "religious" sort of code things where people sit on one side of fence or the other, and there's no way to convince them to change their opinion. They may go along with it if it's already the style in the codebase, but they may not be happy about it. (See also: tabs vs spaces, and where to put your braces)
grumbly ยท 3 points ยท Posted at 19:47:44 on May 23, 2016 ยท (Permalink)
Well, there was also the whims of the Microsoft Style guide. It started with underscore prefixes. Then they left. Then ReSharper came along and defaulted to underscore. Then stylecop had it's preference.
It's changed a bunch over the years and now we have conflicting authoritative sources. It's "fun" watching Roslyn and ReSharper bicker over style conventions.
I use that "stupid notation" everywhere I can. Why? Because if you forget how a member on your class is called, all you have to do is write "_", then ctrl+space and get a quick refresh of all the class members.
Yeah, you have the outline view (Which usually is also cluttered with, well, everything else) and other windows, but I guess is something out of personal preferences.
Of course, if told by my boss to stop bitching around, I will do as told, I'm not going to enter on a fight for a coding convention, just trying to provide a different point of view.
If you are doing anything related to modern desktop ui development in c# (WPF), you are required to back every field with a private member so that you can fire INotifyPropertyChanged in the setter. If you don't, you get no ui updates. If you ever want to have any extended logic besides simply getting/setting, ie lazy loading from a database you want private field backed properties. What would get someone laughed out of my office in this is the public field. No, kill it with fire.
There's a difference between "unnecessarily declaring a private backing field to a public property" and "declaring private members differently from public ones to easily differentiate them from each other." The former is perfectly fine to hate on, but it has nothing to do with prefixing a private member with an underscore.
yeh the whole underscore thing is totally retarded. The whole point of "properties" is they save space. If you start doing the underscore crap you might as well went old school because it doesnt save space anymore.
When writing classes, should variables/members/constants/methods/functions be preceded with this./this->
This is typically driven by code standards for a given team. Some teams like for you to explicitly have "this," and others don't. Brevity isn't always the answer, nor is verbosity always the way to go. Regardless of what you decide to do, just be consistent.
should constants always be static in a class
In C#, constants are static members, but do not require nor allow the static modifier. An interesting aside that is often overlooked is that constants are baked in to their referenced assemblies. A const in assembly A that's used in assembly B will be inline in assembly B.
should constants follow the "underscore to start class member" notation
Again, while this is ultimately a group decision of preference and consistency, there's not a lot of motive to do this in C#. People still follow the MY_CONSTANT_VALUE simply out of longevity. Most people see that and immediately think, "Well, that's a constant." That being said, the "general" acceptance would be to stick with Pascal casing for constants (MyConstantValue)
The most salient point about constants are that they are constant! That may seem pointless to mention, but often is the case that people use constants for values that aren't truly constant. Semantically, you typically want to strive to use constants for things that are truly absolute and unchanging.
Thanks! Those makes sense. I mostly know C++ but am trying to branch out into C#. I appreciate the answer.
oddark ยท 13 points ยท Posted at 16:20:42 on May 23, 2016 ยท (Permalink)
I may get hate for this, but I prefer to never use underscore notation and alway qualify member variables with this. It achieves the same thing (a quick way to tell if a variable is local or a member) but it's enforced by the language.
I also always qualify class variables with the class name. I even qualify every function call, which has helped me catch a few subtle private non-static functions that should should really be static.
00yoshi ยท 3 points ยท Posted at 17:59:15 on May 23, 2016 ยท (Permalink)
Qualified functions? What do you mean with that? And my only use for "this" is
oddark ยท 6 points ยท Posted at 18:55:55 on May 23, 2016 ยท (Permalink)
I use this so that it's obvious that the variable is a member variable.
public class Example {
private int member;
public void DoSomething(int n) {
this.member += n;
}
}
It's obvious here that member is a member variable and n is a local variable, even if I don't know anything else about the code. This is a lot more useful when dealing with large classes. I also find it more consistent since any other time I use a member variable, I have to qualify it with the object that owns it.
When I say I qualify function calls, I just mean that I write this.DoSomething (or Example.DoSomething if it's static) instead of just DoSomething. It's more verbose, but once you get used to it, I think it makes the code a lot more readable. Also, I've seen a lot of cases where a non-static function/variable (especially private ones) would really make more sense if it were static. I've even seen this from very experienced programmers. Qualifying the variable/function every time you use it forces you to consider if it should be a member function or a class function when otherwise it might not ever cross your mind.
Also, I think it's almost always better to be explicit, even at the cost of brevity.
Long answer:
You should really read up what "this" pointer is, it's really useful.
const refers to the variable's value, static refers to it's address in the memory. They serve 2 different functionalities.
Depends all up to you, I just leave consts all capitalized and I have a special color assigned to them in my editor so I can spot them easier.
dnew ยท 12 points ยท Posted at 16:31:11 on May 23, 2016 ยท (Permalink)
Technically, static refers to the lifetime and scope, not its address. It might be implemented such that static puts it in a separate address space, or might not.
oddark ยท 7 points ยท Posted at 16:12:29 on May 23, 2016 ยท (Permalink)
In C#, you can't have static const. It's basically always static by definition. You may be thinking of readonly.
1.) this is a pointer to the current object. Am I missing something?
2.) I know that. But if a class member is constant, is it ever necessary to have to create the member on each instantiation of the class?
3.) Okay.
This code is from an indie game I'm developing called Sight Unseen. It's an audio only horror game that involves using binaural audio.
I took and posted this pic on Twitter and the indie game developer group on facebook. I have no idea who OP is but he is not on my team and certainly did not take the photo.
00yoshi ยท 7 points ยท Posted at 18:26:46 on May 23, 2016 ยท (Permalink)
Audio only and unity... Yeah... Even worse than what I'm doing, I plan to switch to native DX but that doesn't have such good cross plattform compatibility.
I don't do much game development because it isn't my thing. I could see how it would be bad practice, but what's considered good practice?
Take a game like Candy Crush (using it only for its popularity) where each level is unique and has a set challenge. What would be good practice there?
I would have a "Level" class and then load properties and scripts into it from an external source (json, XML, maybe even just a flat file).
The level class could even be static, or if that horrifies you, in Unity you could have a "Level" object in each scene and manually tweak its properties in the editor.
Really there are so many ways to do it but creating a class for each individual level seems...odd.
00yoshi ยท 3 points ยท Posted at 17:42:33 on May 23, 2016 ยท (Permalink)
What is horrifying on static classes? Is good for global variables and stuff.
There is a school of thought out there that says static classes are inherently "bad", here is one discussion of it from stackoverflow. I just wanted to cover all the bases before we got into that debate on this thread ;)
There are things which should not be reinitialized (singletons). For example, network interfaces have a 1 to 1 relationship with hardware components -- trying to reinitialize these would introduce bugs. Network drivers contain stateful components, so this is a possible use case for mutable state in a static class.
00yoshi ยท 1 points ยท Posted at 18:12:17 on May 23, 2016 ยท (Permalink)*
I haven't used ScriptableObjects before, I'm reading up on them right now and wondering why I haven't! Maybe one day I'll read the entire Unity Manual top to bottom to make sure I'm not missing out on these types of things.
I really hate how Unity has no structure whatsoever. UE4 is much better in that sense. Tons of good structure that you can easily understand. Still has a component system but it's not insanely free and open.
In UE4 for things like that we have level blueprints and can adjust everything placed in a level by instance but our "level object" is the scene. You can't not have a level object because it defines the level.
00yoshi ยท 1 points ยท Posted at 17:43:04 on May 23, 2016 ยท (Permalink)
What is unstructured? You could create your own blueprint script in unity too.
It means it doesn't have a structure. It's basically a fully blank slate allowing/forcing you to write everything in the style and mistake ridden way that you would. Personally if I wanted that I'd go write in SFML/SDL/XNA for a 2D game. For 3D I would use an open source engine such as Orge (or UE4). UE4 offers structure. There is a full actor system with character, pawn, actor, character movement, pawn movement. Basically the base of the engine is fully completed where in Unity the base of the engine is like a metal framework that you don't get to touch.
It's basically a fully blank slate allowing/forcing you to write everything in the style and mistake ridden way that you would
Well isn't that just like life? Walk before you can run?
Any framework will let you do anything you want if you try to, Unity is actually pretty structured if you learn it and there are a lot of resources that can help you learn that.
Unity is suppose to be a game engine, not a framework. That's the biggest issue I have. No reason for it to be closed source if it's not providing anything other than a framework, most frameworks are open source. UE4, a full game engine, is 100% open and free up front. There is no reason for Unity to still be closed. They are getting left in the dust because of it. CryEngine, also a full game engine, also free up front, also 100% open source. There is no reason for Unity to still be closed. They are pricing themselves out of the market very quickly.
Well isn't that just like life? Walk before you can run?
No... This is like getting an apple but it's missing all of it's skin. Allowing you to paint on the color of apple you want.
Any framework will let you do anything you want if you try to
(Except when it's closed source like Unity.)
Unity is actually pretty structured if you learn it and there are a lot of resources that can help you learn that.
Yeah not to sound cocky but I'm probably more experienced with it than most developers. I've been a game developer for about 5 years now, professionally, getting paychecks for all 5 years.
No, I mean having just one level as a scene called Level (or something like that)
When loading Candy Crush level 1, you load that scene and in the Start() method or something you set up the level (Every level is the same, the layout is just a bit different). Maybe you have a class called GameConfig which has a variable called LevelLayoutToLoad. The Scene uses this and sets up that layout.
You could do that for every level in Candy Crush because every level is the same, except the layout of the grid in which the candies are in is different. (as far as I remember (I never really played it))
dnew ยท 4 points ยท Posted at 16:28:50 on May 23, 2016 ยท (Permalink)
This is pretty much the same thing, except you're using C# to interpret the configuration instead of writing your own parser. What's the advantage of doing a data-driven level design if the game is such that you have (for example) cutscenes at the beginning of each providing the intro?
Doing it this way is much better if the gameplay actually is different each level.
I guess you're right, but you could do it my way if every level is exactly the same. I'm new to programming with Unity and to creating games in general, so I'm still learning about ways to implement things
dnew ยท 3 points ยท Posted at 19:31:48 on May 23, 2016 ยท (Permalink)
Indeed. In essence, every level of a game is "the same, with different data" in some sense. Every unity game is just the same unity, with different data. To the person writing the game, it looks like different levels. To the programmers writing the game engine, it's just data for the game engine. Script this script that, all the same to us.
It's just a matter of which is easier, writing your own data-driven interpreter, or writing it in a script. Or writing an editor-plug-in to script your data. :-)
If you have different behaviors, it's easiest to code that behavior in a data format designed for coding behaviors, namely C# source code. :-)
oxysoft ยท 1 points ยท Posted at 03:30:54 on May 24, 2016 ยท (Permalink)*
I find that more people will write custom classes for each levels of their games when they are using just a rendering framework or during a game jam. Otherwise, those using game engines and more full fledged solutions will usually load levels from some external format and maybe even use scripting for games with lots of interaction (e.g. rpgs/jrpgs).
But the external data approach is usually considered to be superior and preferable as the data be easily reloaded at runtime and edited whilst the game is running, which is a great advantage. Note however that with C#, it is actually possible to compile C# code at runtime and run it dynamically as a scripting language.
jfb1337 ยท 1 points ยท Posted at 08:16:58 on May 24, 2016 ยท (Permalink)
Well there would only be a few types of levels (either compete it in x amount of time, or x number of moves, abd either get to A specific score, clear all the tiles, or drop some tiles to the bottom of the level), abs besides that, each level is the same except the layout. So you would have a class for each type of level, and then the levels themselves would be stored in a config file with their level type and their layout, which would be loaded dynamically.
This code is from an audio only indie game I'm developing called Sight Unseen. I snapped the photo when working with my programmer... I don't know who OP is but he is not on my team and certainly did not take the photo.
Yeah! It's a stealth survival game:)
We have physically modeled reverb, occlusion and diffraction. We also use tools like wwise so working through an engine like unity allows us to easily have multiplatform support while the use of external tools allow us to have boss audio capabilities since unity kind of has a shitty audio engine.
Actually in Unity if you make it public it allows you to edit the value from inside of the unity interface. That way you can assign a value to it by dragging a game object in a menu. It makes things easier if you are working with someone else who doesn't know how to code.
You can also declare the fields as private and add the [SerializeField] attribute to those that you wish to expose to the inspector, then create properties for the ones you need to expose to your other classes.
This is really helpful when you have a lot of variables that are set in the inspector but shouldn't be changed anywhere else in your code.
nami474 ยท 2 points ยท Posted at 20:35:55 on May 23, 2016 ยท (Permalink)
Thank you Thank you! Now I can stop feeling dirty making so many public fields! Private + SerializeField. Thank you kind sir.
Rhed0x ยท 8 points ยท Posted at 13:52:30 on May 23, 2016 ยท (Permalink)
Why can't you just use properties (and/or attributes)? WPF uses properties to expose it to the editor and so does every other piece of software that is using C#. Shitty Unity.
Unity's usage of C# is an abortion which uses an old version of Mono, before auto-properties existed. It is an archaic system which uses reflection at runtime in the designer UI to determine user editable properties, and doesn't include properties.
Hopefully now that the .NET framework is open source they'll work on fixing issues that were introduced by using Mono (which was needed for cross platform compilation), but it'll either take a long time or a semi / total rewrite. The only way I see it happening anytime soon is if Microsoft buys Unity (like they did with Xaramin) and decided to properly integrate it into .NET and Visual Studio.
Amen to that. I "love" how Unity overrides properties if you've touched them in the inspector, unless you set them in the "Start" method, causing confusing messes like "why the hell is my movement speed still 10 when I'm initializing it to be 50" and pretty soon you have no idea where any values are coming from at all.
Rhed0x ยท 2 points ยท Posted at 14:19:29 on May 23, 2016 ยท (Permalink)
Aren't they trying to get away from Mono with IL2CPP?
Unity can be a somewhat special case of C#, although I'm pretty sure it still supports properties. Their implementation of JavaScript is... Interesting, to say the least.
00yoshi ยท 2 points ยท Posted at 18:21:15 on May 23, 2016 ยท (Permalink)
It's called UnityScript for a reason.
[deleted] ยท 2 points ยท Posted at 15:00:30 on May 23, 2016 ยท (Permalink)
Link please, I wonder why that is.
Rhed0x ยท 3 points ยท Posted at 15:04:47 on May 23, 2016 ยท (Permalink)
Do not use instance fields that are public or protected
[deleted] ยท 2 points ยท Posted at 16:44:00 on May 23, 2016 ยท (Permalink)
Oh, okay, thanks! I'll definitely be using properties from now on.
dnew ยท 2 points ยท Posted at 16:33:49 on May 23, 2016 ยท (Permalink)
Because if you make it a property, then compiled code calls the stub to get the value. The JIT will generally optimize out that call, so it's just as efficient.
If you make it a public field, code compiled against it by others will access the public field directly, and you'd actually need to compile that code again if you wanted to change the public field to a property.
In other words, it's important if the person writing the class doesn't have control over the compilation of the clients.
[deleted] ยท -9 points ยท Posted at 12:09:44 on May 23, 2016 ยท (Permalink)
Rhed0x ยท 14 points ยท Posted at 13:04:30 on May 23, 2016 ยท (Permalink)
That's standard in C#.
It's part of the official Microsoft guidelines and basically part of every other C# coding style as well. (Except for maybe Unity cause Unity is weird)
In some other languages, like JavaScript, it's standard to have it on the same line. It just depends what language you're in and the style guides you're working with, but if a developer is used to one language then they might be thrown off when they see another and it's different from how they expect.
nitiger ยท 6 points ยท Posted at 14:06:42 on May 23, 2016 ยท (Permalink)
That's why it's best to follow the style that the document already is in when working with team mates.
[deleted] ยท 1 points ยท Posted at 16:09:31 on May 23, 2016 ยท (Permalink)
I am a bit of a programming noob, but why is it necessary to have two classes specifically for movement? Would it not have made more sense for the Enemy/Block classes to both be abstract with an abstract function called "movement"?
That feeling when a programmer takes a photo of his screen with a damn smartphone.
You could at least have programmed your own screenshot tool.
Sinidir ยท -1 points ยท Posted at 16:12:28 on May 23, 2016 ยท (Permalink)
Wow that is really funny, because the visibility qualifier, the type and the name of the variable form the popular phrase "public enemy number one" together.
[deleted] ยท 1 points ยท Posted at 18:10:36 on May 23, 2016 ยท (Permalink)
Thanks.
[deleted] ยท -27 points ยท Posted at 11:06:30 on May 23, 2016 ยท (Permalink)
LordQuinzulin ยท 155 points ยท Posted at 12:45:21 on May 23, 2016 ยท (Permalink)
On a shitty game I'm working on with a friend, we had a quick discussion about what we were going to name 5 clone antagonists. I mentioned George, no objections, now we've gone too far to rename them. George1 - George5 and the protagonist is PlayerMan
Skeczi ยท 62 points ยท Posted at 19:57:59 on May 23, 2016 ยท (Permalink)
Why did you not call them GeorgeCloney1-GeorgeCloney5?
jimanri ยท 23 points ยท Posted at 00:31:53 on May 24, 2016 ยท (Permalink)
Why not GeorgeCloney-GeorgeCloooooney?
Pink_Fedora ยท 4 points ยท Posted at 14:19:24 on May 24, 2016 ยท (Permalink)
GeorgeCloney1 GeorgeCloney11 GeorgeCloneyForReal GeorgeCloneyFinal GeorgeCloneyFinalForReal
Vakieh ยท 141 points ยท Posted at 15:34:19 on May 23, 2016 ยท (Permalink)
The fuck editor are you using, Notepad.exe? Refactor, or at least find&replace.
merthsoft ยท 181 points ยท Posted at 16:15:37 on May 23, 2016 ยท (Permalink)
It could be an emotional rather than technical restriction. Maybe they're attached to George.
tehserial ยท 58 points ยท Posted at 17:58:06 on May 23, 2016 ยท (Permalink)
George4 is best
jewdai ยท 25 points ยท Posted at 18:52:59 on May 23, 2016 ยท (Permalink)
I wonder what happened to George0
RommelTJ ยท 69 points ยท Posted at 20:08:51 on May 23, 2016 ยท (Permalink)
It took a pointer to the knee.
tehserial ยท 23 points ยท Posted at 19:10:31 on May 23, 2016 ยท (Permalink)
He was nullified!
zem ยท 18 points ยท Posted at 23:29:05 on May 23, 2016 ยท (Permalink)
he was lost at C
SDMF91 ยท 7 points ยท Posted at 20:33:05 on May 23, 2016 ยท (Permalink)
I ship George3 and George5
unchartedcubes ยท 3 points ยท Posted at 01:50:58 on May 24, 2016 ยท (Permalink)
Choosing the best George is like choosing a favorite child.
tehserial ยท 2 points ยท Posted at 02:09:30 on May 24, 2016 ยท (Permalink)
Stop lying to yourself, we all know you have a favorite
arturaz ยท 1 points ยท Posted at 04:21:01 on May 24, 2016 ยท (Permalink)
Until Unity introduced FormerlySerializedAsAttribute, renaming a public fields dropped all serialization references in the editor. That used to be "fun"...
JeremyR22 ยท 12 points ยท Posted at 15:18:46 on May 23, 2016 ยท (Permalink)
See also, the origin of Guybrush Threepwood's name...
Mikevin ยท 7 points ยท Posted at 18:09:39 on May 23, 2016 ยท (Permalink)
Please do tell!
JeremyR22 ยท 17 points ยท Posted at 18:15:39 on May 23, 2016 ยท (Permalink)*
I would research and link if i wasn't on cell with horrible internet but basically the character's sprite brush was drawn before he was named, so they saved the file as 'guybrush' and it stuck. There's some kind of origin story for Threepwood too but I don't remember off hand what it is. I'll look it up when I get off work.....
[edit] From Wikipedia:
And the surname:
https://en.wikipedia.org/wiki/Guybrush_Threepwood
Free_Math_Tutoring ยท 13 points ยท Posted at 19:43:44 on May 23, 2016 ยท (Permalink)
To be more precise, .brush was the file extension for the artwork program and in lieu of a name, they named the file guy. guy.brush
[deleted] ยท 1 points ยท Posted at 01:05:10 on May 25, 2016 ยท (Permalink)
[deleted]
Free_Math_Tutoring ยท 1 points ยท Posted at 03:37:36 on May 25, 2016 ยท (Permalink)
Weil, it would have been more precise if I hadn't been wrong.
As it turns out, the file was called guybrush.bbm
Edit: When I first commented, op was a lot more vague and had no qoutes.
Mikevin ยท 5 points ยท Posted at 18:30:01 on May 23, 2016 ยท (Permalink)
Ahh that's awesome. Luckily they didn't pick a silly name like Mancomb Seepgood.
[deleted] ยท 9 points ยท Posted at 17:21:19 on May 23, 2016 ยท (Permalink)
George Foreman named all 5 of his sons George.
Magnap ยท 7 points ยท Posted at 20:37:47 on May 23, 2016 ยท (Permalink)
George Faifman, hopefully.
Relevant_Monstrosity ยท 8 points ยท Posted at 19:30:06 on May 23, 2016 ยท (Permalink)
If you have numbered variables, I.E.
Then you should use a list or array.
If you expand upon this with a static factory, it gets even more concise:
InsidiousToilet ยท 3 points ยท Posted at 22:30:03 on May 23, 2016 ยท (Permalink)
OK, programmer who has very little common sense: what's a "static factory"?
Relevant_Monstrosity ยท 5 points ยท Posted at 01:46:07 on May 24, 2016 ยท (Permalink)*
An implementation of the Factory Pattern using a static class.
https://en.wikipedia.org/wiki/Factory_method_pattern
For example:
This is an example of what I would describe as a static factory class. It is a static class (obviously) which has factory methods.
Why are you questioning my common sense? Do you not understand OO design patterns?
There are four cornerstones and five principles which describe robust OO code (C# is a primarly OO language which supports FP as well).
The four cornerstones of Object Oriented Programming are Encapsulation, Abstraction, Polymorphism, and Inheritance (Thanks, /u/LyonesGamer, for pointing out my typo).
The five guiding principles are SOLID: Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion.
My approach is justified because it exemplifies encapsulation, abstraction, and single responsibility by letting a generic class (List) handle the inevitable management of the collection.
LyonesGamer ยท 4 points ยท Posted at 04:16:23 on May 24, 2016 ยท (Permalink)
Might want to double check that list. Or is that the joke?
Shadow_Being ยท 3 points ยท Posted at 21:56:56 on May 23, 2016 ยท (Permalink)
arrays are good yes, but theres nothing wrong with what he did. Sometimes you need direct convenient references to your instances as well.
Relevant_Monstrosity ยท 5 points ยท Posted at 22:13:49 on May 23, 2016 ยท (Permalink)*
This approach, while technically valid, is going to be a real pain in the ass later. It makes iterative programming almost impossible. If we use a collection, we can quickly iterate and filter it. Trust me on this, you will thank me later.
There are infinite reasons to use iterable data structures to store groups of objects which have a common purpose. For example, suppose that you want all enemies within 10 meters of the player to aggro on him. With your approach, you would need to write something like this:
This alone is tedious as fuck! Imagine implementing aggro chaining (so all enemies in a cluster attack when the player gets in range of one). That would be almost impossibly tedious, and your source code would bloat soooo much.
If we use an iterative approach, we can write objectively better code to solve the same task (less development time, more maintainability, more extensibility):
Or without LINQ (because not everyone likes functional programming):
The approriate place to use a singular type is when we are working with a singular object.
The appropriate place to use a collection type is when we are working with a collection.
TL;DR: If you use tools appropriately, you will be a lot more productive. Use collections to handle groups of similar objects. Use singular types to handle individual instances. Microsoft has written some incredible tooling for the .NET Framework -- embrace it!
Shadow_Being ยท 3 points ยท Posted at 22:37:12 on May 23, 2016 ยท (Permalink)
who says the two are mutually exclusive?
List enemies = new List(enemyOne, enemyTwo, enemeyThree):
in fact id even argue that not making a list until its needed is the iterative approach. If youre building infrastructure to your code before you need it then that isnt being iterative.
Relevant_Monstrosity ยท 3 points ยท Posted at 02:02:34 on May 24, 2016 ยท (Permalink)*
Agreed. Building infrastructure before building details is not iterative programming at all. It's just plain smart. That's why the .NET Framework exists -- so that you don't have to! However, the infrastructure we are talking about is centered around making groups of related variables iterable. The manner that the .NET framework implements this infrastructure is supported by decades of OO theory and has been refined by world-class developers to be extremely efficient. Why would you NOT use the tool that is freely available to you?
pvkooten ยท 1 points ยท Posted at 17:20:48 on May 24, 2016 ยท (Permalink)
you mean
for (George george in Georges) { ... }Relevant_Monstrosity ยท 1 points ยท Posted at 20:00:00 on May 24, 2016 ยท (Permalink)
Haha. Not my style (I use single letter variable names for iterators), but that is a little funny.
leBoef ยท 486 points ยท Posted at 08:14:20 on May 23, 2016 ยท (Permalink)
http://www.take-a-screenshot.org
๐๏ธ ThatPigeon ยท 310 points ยท Posted at 11:09:19 on May 23, 2016 ยท (Permalink)
Well, it's actually my friend's code. Snapping a picture would be much quicker instead of screenshotting + sending it to me.
Sorry for my sin u/leBoef
Hondros ยท 273 points ยท Posted at 12:51:35 on May 23, 2016 ยท (Permalink)
He's coming for your life, it's shia /u/leBoef
cmonster1697 ยท 162 points ยท Posted at 13:21:35 on May 23, 2016 ยท (Permalink)
He's brandishing a knife, it's shia /u/leBoef
๐๏ธ ThatPigeon ยท 140 points ยท Posted at 13:32:20 on May 23, 2016 ยท (Permalink)
Lurking in the shadows
Hollywood superstar shia /u/leBoef
Shabacka ยท 89 points ยท Posted at 13:38:38 on May 23, 2016 ยท (Permalink)
Killing for sport! (Shia /u/leBoef)
MemoryLapse ยท 61 points ยท Posted at 14:34:52 on May 23, 2016 ยท (Permalink)
It's actual cannibal Shia /u/leBoef!
Kaos9001 ยท 12 points ยท Posted at 16:44:40 on May 23, 2016 ยท (Permalink)
Eating all the bodies!
Bombtrust ยท 3 points ยท Posted at 23:29:54 on May 23, 2016 ยท (Permalink)
actual cannibal, shia u/leBoef
Jest0riz0r ยท 26 points ยท Posted at 16:21:00 on May 23, 2016 ยท (Permalink)*
Are you sure?
111poiss111 ยท 42 points ยท Posted at 11:14:54 on May 23, 2016 ยท (Permalink)
http://instacod.es/
Toma- ยท 19 points ยท Posted at 13:04:17 on May 23, 2016 ยท (Permalink)
It's terrible on mobile. :(
parenthesis-bot ยท 82 points ยท Posted at 13:07:04 on May 23, 2016 ยท (Permalink)
:)
This is an autogenerated response. source | /u/HugoNikanor
Toma- ยท 19 points ยท Posted at 14:05:25 on May 23, 2016 ยท (Permalink)
:{
BackFromVoat ยท 25 points ยท Posted at 14:13:42 on May 23, 2016 ยท (Permalink)
It's Mr Pringle
ypoora1 ยท 3 points ยท Posted at 12:37:49 on May 23, 2016 ยท (Permalink)
That's awesome
ThisIs_MyName ยท 2 points ยท Posted at 02:44:43 on May 25, 2016 ยท (Permalink)
Dude, your website breaks if you use the back button. Stop using JS magic.
111poiss111 ยท 1 points ยท Posted at 10:37:08 on May 25, 2016 ยท (Permalink)
Not my site
scriptmonkey420 ยท 1 points ยท Posted at 16:33:48 on May 23, 2016 ยท (Permalink)
Privacy Badger extension makes the site look like crap.
-Pelvis- ยท 6 points ยท Posted at 15:04:54 on May 23, 2016 ยท (Permalink)
I gots a script for you.
This takes a full screenshot, uploads it (AS LOSSLESS PNG, NOT JPEG), and copies the URL to your clipboard.
I have that bound to a keybind. Press that, paste in an SMS to whomever. Simple.
There's also imgur-screenshot, but you have to actually install and configure that, and I find imgur really unreliable anyways. Their jpeg compression is poop too.
LWdkw ยท 5 points ยท Posted at 17:01:22 on May 23, 2016 ยท (Permalink)
I bound it to a keybind and pressed it. I still haven't received a screen shot of my friend's monitor though. What did I do wrong?
-Pelvis- ยท 2 points ยท Posted at 17:20:32 on May 23, 2016 ยท (Permalink)
Well, this will take a screenshot of the current computer's desktop. Press that keybind, and then
Ctrl-VandReturnin the URL bar of your web browser. You should see that screenshot load up.If you want to send it, just paste that URL in an SMS or email, etc.
Make sure you have all of the programs called in the script installed. Most of it is standard on linux desktops, but you'll need
scrot, notably. Also, it displays a confirmation notification, but you'll need libnotify installed and configured for them to display. I use dunst for notifications (highly recommended!).You'll also need xclip installed for it to copy the URL to your clipboard, but you can substitute xclip for xsel, depending on your preferences. They both do the same thing. I actually prefer xsel because it's more straightforward and the commands are shorter (
xclip -selection clipboardversusxsel -b, for example) ; I've been meaning to convert all of my scripts to xsel. Thanks for reminding me! :)LWdkw ยท 4 points ยท Posted at 17:26:13 on May 23, 2016 ยท (Permalink)
Uh, so, thank you for being nice and explaining! I was really being an ass though and pointing out the fact that if your friend has something on their screen, doing whatever with your own PC won't help you :)
-Pelvis- ยท 3 points ยท Posted at 17:33:33 on May 23, 2016 ยท (Permalink)*
That's alright. I wasn't sure if you were being sarcastic or not, so I decided it would be best to assume you weren't.
Anyways, it's not an "ideal" solution, as it's not default behaviour (I know many people who can't wrap their heads around things that don't have a GUI). It is very simple to implement, though, and it's very efficient when it is.
Scripts are great! Automate the boring/repetitive stuff!
JenMog ยท 13 points ยท Posted at 13:07:19 on May 23, 2016 ยท (Permalink)
Start menu
Snipping Tool, mark what you want
Copy (ctrl-c)
https://imgur.com while on main page press ctrl-v
????
Chirimorin ยท 7 points ยท Posted at 16:00:44 on May 23, 2016 ยท (Permalink)
Alternatively:
ViperCodeGames ยท 2 points ยท Posted at 02:04:01 on May 24, 2016 ยท (Permalink)
I second sharex. Super convenient and lots of options.
LucaYo ยท 5 points ยท Posted at 13:22:31 on May 23, 2016 ยท (Permalink)
He clearly sent it through text, why would his friend go through that trouble???
[deleted] ยท 4 points ยท Posted at 13:36:50 on May 23, 2016 ยท (Permalink)
To get some sweet internet points???
White_Party_Hat ยท 1 points ยท Posted at 07:52:33 on May 24, 2016 ยท (Permalink)
Snipping tool automatically saves to clipboard, no need for step 3.
JenMog ยท 1 points ยท Posted at 13:38:51 on May 24, 2016 ยท (Permalink)
That's true.
zacharythefirst ยท 1 points ยท Posted at 16:41:04 on May 23, 2016 ยท (Permalink)
plug for puush
s0ft_ ยท 1 points ยท Posted at 21:06:09 on May 23, 2016 ยท (Permalink)
Gyazo has gifs tho
zacharythefirst ยท 1 points ยท Posted at 21:53:27 on May 23, 2016 ยท (Permalink)
This is the first I've heard of it, looks cool though
s0ft_ ยท 1 points ยท Posted at 22:31:39 on May 23, 2016 ยท (Permalink)
I prefer it because with Puush I always forgot what the number did, with Gyazo it's just ctrl+shift+c (or g for gifs)
guaranic ยท 1 points ยท Posted at 22:43:01 on May 23, 2016 ยท (Permalink)
The quality is pretty potato, though.
s0ft_ ยท 1 points ยท Posted at 22:51:48 on May 23, 2016 ยท (Permalink)
Potato quality is better than no quality
loozerr ยท 1 points ยท Posted at 01:21:49 on May 24, 2016 ยท (Permalink)
ShareX can upload video to gfycat, for instance.
s0ft_ ยท 1 points ยท Posted at 09:38:22 on May 24, 2016 ยท (Permalink)
Didn't know about it. Trying it right now
inthemanual ยท 1 points ยท Posted at 02:38:48 on May 24, 2016 ยท (Permalink)
Snipping tool is pretty quick
Sinity ยท 5 points ยท Posted at 19:57:06 on May 23, 2016 ยท (Permalink)
Screenshots lack soul.
Zarlon ยท 10 points ยท Posted at 10:49:52 on May 23, 2016 ยท (Permalink)
I'm sure he could code a screenshot-grabber, but not use one
xConorrr ยท 1 points ยท Posted at 00:59:01 on May 24, 2016 ยท (Permalink)
Where's the Linux tab? /s
cheezballs ยท 195 points ยท Posted at 13:01:07 on May 23, 2016 ยท (Permalink)
In c# you should name your public variables with capitals at the front for consistency with other APIs. public Enemy NumberOne.
Pinguinsan ยท 40 points ยท Posted at 15:34:35 on May 23, 2016 ยท (Permalink)
This seems like a good place to ask: When writing classes, should variables/members/constants/methods/functions be preceded with this./this->?
Followup question, should constants always be static in a class?
Second followup, should constants follow the "underscore to start class member" notation?
TranquilMarmot ยท 88 points ยท Posted at 15:40:12 on May 23, 2016 ยท (Permalink)*
NO I frickin hate that stupid stupid underscore notation.
In C# you should just do
Then only the class can set it, but anybody else can get it
Edited; have to explicitly declare private set
SolarLiner ยท 38 points ยท Posted at 15:44:38 on May 23, 2016 ยท (Permalink)
Yeah. Why waste private variables when you don't need to do anything fancy in your getters/setters. Also, this is freaking C#, not JavaScript. Get your camel case right.
S1CKLY ยท 20 points ยท Posted at 16:33:00 on May 23, 2016 ยท (Permalink)
Because OP's code is in Unity3D which does not serialize properties.
00yoshi ยท 4 points ยท Posted at 17:55:11 on May 23, 2016 ยท (Permalink)
But these also contain a variable when compiled to IL code.
devluz ยท 1 points ยท Posted at 21:57:45 on May 23, 2016 ยท (Permalink)
Unity only serializes public variables. At least in default setup. And more and more universities use it to teach ... I hope the C# code reviewer are prepared for a culture shock ;)
00yoshi ยท 2 points ยท Posted at 22:17:01 on May 23, 2016 ยท (Permalink)
What do they teach? How to make a game? Well, at least you only need to program it once and can put it out for mobile and desktop and console. (Lets see how good my shaders will run on mobile...)
devluz ยท 1 points ยท Posted at 22:58:01 on May 24, 2016 ยท (Permalink)
It is often used to teach Game development and VR. Unity itself is great. It is just bad if people only know unity and think that is the "normal" way to use C#.
00yoshi ยท 2 points ยท Posted at 13:42:14 on May 25, 2016 ยท (Permalink)
Well, they really should start out with visual studio community (since it's free) and then go over to unity, after they learned the basics.
Relevant_Monstrosity ยท -1 points ยท Posted at 19:21:51 on May 23, 2016 ยท (Permalink)
Properties are stateless anyway, there is no reason to serialize them.
jasie3k ยท 10 points ยท Posted at 20:23:32 on May 23, 2016 ยท (Permalink)
This is actually PascalCase. camelCase is used more in Java.
SolarLiner ยท 1 points ยท Posted at 21:46:44 on May 23, 2016 ยท (Permalink)
Well, I stand corrected here. What are the differences?
TheIncredibleWalrus ยท 9 points ยท Posted at 00:13:30 on May 24, 2016 ยท (Permalink)
You honestly can't spot the difference?
SolarLiner ยท 1 points ยท Posted at 05:31:15 on May 24, 2016 ยท (Permalink)
Well if this is the only difference, then of course I can!
Chirimorin ยท 5 points ยท Posted at 16:04:48 on May 23, 2016 ยท (Permalink)
So
private setis implied? I always wrote this kind of stuff asTranquilMarmot ยท 9 points ยท Posted at 16:19:47 on May 23, 2016 ยท (Permalink)
The way you have it is right; I edited my comment
IAMANullPointerAMA ยท 5 points ยท Posted at 16:02:19 on May 23, 2016 ยท (Permalink)
I think you mean {get; private set;}. The way you wrote it, the property can only be set by a constructor, and can't be changed in that instance anymore.
TranquilMarmot ยท 3 points ยท Posted at 16:19:17 on May 23, 2016 ยท (Permalink)
Hmm I think you're right. Edited.
Pinguinsan ยท 2 points ยท Posted at 17:10:20 on May 23, 2016 ยท (Permalink)
That's interesting. I work with a guy who has a degree in CS and ONLY uses the underscore notation (unless a group agrees on something else, of course). It seems like it's preference? You seem to vehemently oppose the notation, but others down below like it.
TranquilMarmot ยท 11 points ยท Posted at 18:04:41 on May 23, 2016 ยท (Permalink)
I do vehemently despise the notation, because it adds a bunch of useless noise to the code at no added value. It is a bit of a preference, and makes more sense in C/C++ code (which is where this convention comes from) but in C# it's not necessary.
This is one of those "religious" sort of code things where people sit on one side of fence or the other, and there's no way to convince them to change their opinion. They may go along with it if it's already the style in the codebase, but they may not be happy about it. (See also: tabs vs spaces, and where to put your braces)
grumbly ยท 3 points ยท Posted at 19:47:44 on May 23, 2016 ยท (Permalink)
Well, there was also the whims of the Microsoft Style guide. It started with underscore prefixes. Then they left. Then ReSharper came along and defaulted to underscore. Then stylecop had it's preference.
It's changed a bunch over the years and now we have conflicting authoritative sources. It's "fun" watching Roslyn and ReSharper bicker over style conventions.
Neuromante ยท 1 points ยท Posted at 19:17:18 on May 23, 2016 ยท (Permalink)
I use that "stupid notation" everywhere I can. Why? Because if you forget how a member on your class is called, all you have to do is write "_", then ctrl+space and get a quick refresh of all the class members.
Yeah, you have the outline view (Which usually is also cluttered with, well, everything else) and other windows, but I guess is something out of personal preferences.
Of course, if told by my boss to stop bitching around, I will do as told, I'm not going to enter on a fight for a coding convention, just trying to provide a different point of view.
ToddlahAkbar ยท 1 points ยท Posted at 20:53:12 on May 23, 2016 ยท (Permalink)
If you are doing anything related to modern desktop ui development in c# (WPF), you are required to back every field with a private member so that you can fire INotifyPropertyChanged in the setter. If you don't, you get no ui updates. If you ever want to have any extended logic besides simply getting/setting, ie lazy loading from a database you want private field backed properties. What would get someone laughed out of my office in this is the public field. No, kill it with fire.
Diosjenin ยท 1 points ยท Posted at 00:27:57 on May 24, 2016 ยท (Permalink)
There's a difference between "unnecessarily declaring a private backing field to a public property" and "declaring private members differently from public ones to easily differentiate them from each other." The former is perfectly fine to hate on, but it has nothing to do with prefixing a private member with an underscore.
Shadow_Being ยท 0 points ยท Posted at 21:58:40 on May 23, 2016 ยท (Permalink)
yeh the whole underscore thing is totally retarded. The whole point of "properties" is they save space. If you start doing the underscore crap you might as well went old school because it doesnt save space anymore.
SykoHoseBeast ยท 12 points ยท Posted at 16:29:16 on May 23, 2016 ยท (Permalink)
This is typically driven by code standards for a given team. Some teams like for you to explicitly have "this," and others don't. Brevity isn't always the answer, nor is verbosity always the way to go. Regardless of what you decide to do, just be consistent.
In C#, constants are static members, but do not require nor allow the static modifier. An interesting aside that is often overlooked is that constants are baked in to their referenced assemblies. A const in assembly A that's used in assembly B will be inline in assembly B.
Again, while this is ultimately a group decision of preference and consistency, there's not a lot of motive to do this in C#. People still follow the MY_CONSTANT_VALUE simply out of longevity. Most people see that and immediately think, "Well, that's a constant." That being said, the "general" acceptance would be to stick with Pascal casing for constants (MyConstantValue)
The most salient point about constants are that they are constant! That may seem pointless to mention, but often is the case that people use constants for values that aren't truly constant. Semantically, you typically want to strive to use constants for things that are truly absolute and unchanging.
Pinguinsan ยท 2 points ยท Posted at 17:07:25 on May 23, 2016 ยท (Permalink)
Thanks! Those makes sense. I mostly know C++ but am trying to branch out into C#. I appreciate the answer.
oddark ยท 13 points ยท Posted at 16:20:42 on May 23, 2016 ยท (Permalink)
I may get hate for this, but I prefer to never use underscore notation and alway qualify member variables with
this. It achieves the same thing (a quick way to tell if a variable is local or a member) but it's enforced by the language.I also always qualify class variables with the class name. I even qualify every function call, which has helped me catch a few subtle private non-static functions that should should really be static.
00yoshi ยท 3 points ยท Posted at 17:59:15 on May 23, 2016 ยท (Permalink)
Qualified functions? What do you mean with that? And my only use for "this" is
oddark ยท 6 points ยท Posted at 18:55:55 on May 23, 2016 ยท (Permalink)
I use
thisso that it's obvious that the variable is a member variable.It's obvious here that member is a member variable and n is a local variable, even if I don't know anything else about the code. This is a lot more useful when dealing with large classes. I also find it more consistent since any other time I use a member variable, I have to qualify it with the object that owns it.
When I say I qualify function calls, I just mean that I write
this.DoSomething(orExample.DoSomethingif it's static) instead of justDoSomething. It's more verbose, but once you get used to it, I think it makes the code a lot more readable. Also, I've seen a lot of cases where a non-static function/variable (especially private ones) would really make more sense if it were static. I've even seen this from very experienced programmers. Qualifying the variable/function every time you use it forces you to consider if it should be a member function or a class function when otherwise it might not ever cross your mind.Also, I think it's almost always better to be explicit, even at the cost of brevity.
Relevant_Monstrosity ยท 3 points ยท Posted at 19:22:59 on May 23, 2016 ยท (Permalink)
Correct. Remember the maintenence programmer.
SpacebarYogurt ยท 7 points ยท Posted at 15:50:59 on May 23, 2016 ยท (Permalink)
Short answer.
No, No and No.
Long answer: You should really read up what "this" pointer is, it's really useful.
const refers to the variable's value, static refers to it's address in the memory. They serve 2 different functionalities.
Depends all up to you, I just leave consts all capitalized and I have a special color assigned to them in my editor so I can spot them easier.
dnew ยท 12 points ยท Posted at 16:31:11 on May 23, 2016 ยท (Permalink)
Technically, static refers to the lifetime and scope, not its address. It might be implemented such that static puts it in a separate address space, or might not.
oddark ยท 7 points ยท Posted at 16:12:29 on May 23, 2016 ยท (Permalink)
In C#, you can't have
static const. It's basically always static by definition. You may be thinking ofreadonly.Pinguinsan ยท 3 points ยท Posted at 17:08:33 on May 23, 2016 ยท (Permalink)
Thanks, I didn't know this. I appreciate it.
Pinguinsan ยท 3 points ยท Posted at 16:00:58 on May 23, 2016 ยท (Permalink)
1.) this is a pointer to the current object. Am I missing something?
2.) I know that. But if a class member is constant, is it ever necessary to have to create the member on each instantiation of the class?
3.) Okay.
_Aardvark ยท 1 points ยท Posted at 17:49:26 on May 23, 2016 ยท (Permalink)
I believe Microsoft's preferred C# style is to precede class members with "this." This is what StyleCop enforces by default.
Relevant_Monstrosity ยท 1 points ยท Posted at 19:20:08 on May 23, 2016 ยท (Permalink)
Use autoproperties if you don't have any logic except a simple get/set.
Lykeuhfox ยท 1 points ยท Posted at 21:32:10 on May 23, 2016 ยท (Permalink)
or better yet:
public Enemy NumberOne { get; set; }
00yoshi ยท 0 points ยท Posted at 17:53:33 on May 23, 2016 ยท (Permalink)
Underscore? Uh... Either the specs on msdn are wrong or I did something wrong. I always write variables lowercase like
and some properties like
Vider7CC ยท 2 points ยท Posted at 18:27:52 on May 23, 2016 ยท (Permalink)
What about properties? I use lower camel case for public variables and upper camel case for properties.
Richard_Fey ยท 1 points ยท Posted at 23:57:28 on May 23, 2016 ยท (Permalink)
You should never really have public fields and if you do the standard is still upper camel case.
CoderHawk ยท 0 points ยท Posted at 18:34:11 on May 23, 2016 ยท (Permalink)
Or not have public variables.
cheezballs ยท 1 points ยท Posted at 02:56:17 on May 25, 2016 ยท (Permalink)
C# has auto getters and setters, which is what ideally you'd use.
CoderHawk ยท 1 points ยท Posted at 03:01:53 on May 25, 2016 ยท (Permalink)
Yea, which is why I was saying don't use public vars
devluz ยท 0 points ยท Posted at 21:51:32 on May 23, 2016 ยท (Permalink)
Sadly no one cares in Unity :/ not even the developers of it ...
NibblyPig ยท -5 points ยท Posted at 16:56:58 on May 23, 2016 ยท (Permalink)
Should be a const anyway
public const int NumberOne = 1;
Since obviously that's what OP means right, you wouldn't call a variable that's obviously the number one 'NumberOne' otherwise?
eastballz ยท 1 points ยท Posted at 21:15:21 on May 23, 2016 ยท (Permalink)
What
NibblyPig ยท 0 points ยท Posted at 21:55:27 on May 23, 2016 ยท (Permalink)
He used the name 'NumberOne' for a variable which isn't a very good name unless it stores the value '1'.
Thus I made a joke about it.
It was a terrible joke made worse by having to explain it.
cheezballs ยท 1 points ยท Posted at 02:57:19 on May 25, 2016 ยท (Permalink)
No, NumberOne is of type Enemy - so it holds a reference to an Enemy object, which likely would never be const.
Spicybrownsounds ยท 80 points ยท Posted at 14:43:46 on May 23, 2016 ยท (Permalink)
This code is from an indie game I'm developing called Sight Unseen. It's an audio only horror game that involves using binaural audio.
I took and posted this pic on Twitter and the indie game developer group on facebook. I have no idea who OP is but he is not on my team and certainly did not take the photo.
Proof: @blackout_vr's Tweet: https://twitter.com/blackout_vr/status/734106919602954240?s=09
XxMONKABONKAxX ยท 16 points ยท Posted at 18:22:02 on May 23, 2016 ยท (Permalink)
Dammit OP
00yoshi ยท 7 points ยท Posted at 18:26:46 on May 23, 2016 ยท (Permalink)
Audio only and unity... Yeah... Even worse than what I'm doing, I plan to switch to native DX but that doesn't have such good cross plattform compatibility.
Spicybrownsounds ยท 1 points ยท Posted at 18:38:53 on May 23, 2016 ยท (Permalink)
What are you working on?
00yoshi ยท 2 points ยท Posted at 20:32:58 on May 23, 2016 ยท (Permalink)
Something similar to factorio
[deleted] ยท -2 points ยท Posted at 20:07:29 on May 23, 2016 ยท (Permalink)*
[deleted]
Deranged40 ยท 6 points ยท Posted at 21:48:55 on May 23, 2016 ยท (Permalink)
https://www.reddit.com/r/ProgrammerHumor/comments/4kmwwz/when_your_variable_naming_is_on_point/d3g8jjl
First reply to top comment
psi- ยท 150 points ยท Posted at 12:04:16 on May 23, 2016 ยท (Permalink)
.. and nobody else is bothered that the level is actually hardcoded?
thecoolracer ยท 56 points ยท Posted at 12:51:52 on May 23, 2016 ยท (Permalink)
That's probably because he hasn't set up a generic system for scripted events(like triggers work in the Source engine)
shareYourFears ยท 51 points ยท Posted at 13:22:58 on May 23, 2016 ยท (Permalink)
I'm not all that bothered by it since he is at least extending a base class, but I did laugh at it being called "Level15".
Unless of course it's the sort of game where that is literally the only way it's defined.
Example: Don't Shoot the Puppy
danieltobey ยท 6 points ยท Posted at 22:14:41 on May 23, 2016 ยท (Permalink)
The name of that website is amazing.
pmmecodeproblems ยท 5 points ยท Posted at 16:49:23 on May 23, 2016 ยท (Permalink)
Wow I just played that game. I couldn't get past level 2.
FaithForHumans ยท 18 points ยท Posted at 15:08:19 on May 23, 2016 ยท (Permalink)
I don't do much game development because it isn't my thing. I could see how it would be bad practice, but what's considered good practice?
Take a game like Candy Crush (using it only for its popularity) where each level is unique and has a set challenge. What would be good practice there?
oyok2112 ยท 24 points ยท Posted at 15:59:35 on May 23, 2016 ยท (Permalink)
I would have a "Level" class and then load properties and scripts into it from an external source (json, XML, maybe even just a flat file).
The level class could even be static, or if that horrifies you, in Unity you could have a "Level" object in each scene and manually tweak its properties in the editor.
Really there are so many ways to do it but creating a class for each individual level seems...odd.
00yoshi ยท 3 points ยท Posted at 17:42:33 on May 23, 2016 ยท (Permalink)
What is horrifying on static classes? Is good for global variables and stuff.
oyok2112 ยท 2 points ยท Posted at 17:50:46 on May 23, 2016 ยท (Permalink)
There is a school of thought out there that says static classes are inherently "bad", here is one discussion of it from stackoverflow. I just wanted to cover all the bases before we got into that debate on this thread ;)
buttlickk ยท 3 points ยท Posted at 18:14:28 on May 23, 2016 ยท (Permalink)
I, personally, don't have a problem with static classes if they're stateless.
Relevant_Monstrosity ยท 2 points ยท Posted at 19:35:07 on May 23, 2016 ยท (Permalink)
The whole point of a static class is to define a class with no mutable state, soooo....
Zeroto ยท 2 points ยท Posted at 19:55:45 on May 23, 2016 ยท (Permalink)
but the language does allow it
Relevant_Monstrosity ยท 2 points ยท Posted at 20:01:25 on May 23, 2016 ยท (Permalink)
There are things which should not be reinitialized (singletons). For example, network interfaces have a 1 to 1 relationship with hardware components -- trying to reinitialize these would introduce bugs. Network drivers contain stateful components, so this is a possible use case for mutable state in a static class.
00yoshi ยท 1 points ยท Posted at 18:12:17 on May 23, 2016 ยท (Permalink)*
http://stackoverflow.com/a/1315280, and are public static variables good? For example ones that point to the object itself.
salmonmoose ยท 2 points ยท Posted at 23:43:14 on May 23, 2016 ยท (Permalink)
It's Unity.
The correct solution is to use a ScriptableObject - this saves data in YAML.
oyok2112 ยท 1 points ยท Posted at 15:04:30 on May 24, 2016 ยท (Permalink)
I haven't used ScriptableObjects before, I'm reading up on them right now and wondering why I haven't! Maybe one day I'll read the entire Unity Manual top to bottom to make sure I'm not missing out on these types of things.
pmmecodeproblems ยท 3 points ยท Posted at 16:51:42 on May 23, 2016 ยท (Permalink)
I really hate how Unity has no structure whatsoever. UE4 is much better in that sense. Tons of good structure that you can easily understand. Still has a component system but it's not insanely free and open.
In UE4 for things like that we have level blueprints and can adjust everything placed in a level by instance but our "level object" is the scene. You can't not have a level object because it defines the level.
00yoshi ยท 1 points ยท Posted at 17:43:04 on May 23, 2016 ยท (Permalink)
What is unstructured? You could create your own blueprint script in unity too.
pmmecodeproblems ยท 1 points ยท Posted at 19:58:57 on May 23, 2016 ยท (Permalink)
It means it doesn't have a structure. It's basically a fully blank slate allowing/forcing you to write everything in the style and mistake ridden way that you would. Personally if I wanted that I'd go write in SFML/SDL/XNA for a 2D game. For 3D I would use an open source engine such as Orge (or UE4). UE4 offers structure. There is a full actor system with character, pawn, actor, character movement, pawn movement. Basically the base of the engine is fully completed where in Unity the base of the engine is like a metal framework that you don't get to touch.
RedPandaIsBestPanda ยท 1 points ยท Posted at 20:06:24 on May 23, 2016 ยท (Permalink)
Well isn't that just like life? Walk before you can run?
Any framework will let you do anything you want if you try to, Unity is actually pretty structured if you learn it and there are a lot of resources that can help you learn that.
pmmecodeproblems ยท 1 points ยท Posted at 20:34:31 on May 23, 2016 ยท (Permalink)
I've worked with Unity in a few positions.
Unity is suppose to be a game engine, not a framework. That's the biggest issue I have. No reason for it to be closed source if it's not providing anything other than a framework, most frameworks are open source. UE4, a full game engine, is 100% open and free up front. There is no reason for Unity to still be closed. They are getting left in the dust because of it. CryEngine, also a full game engine, also free up front, also 100% open source. There is no reason for Unity to still be closed. They are pricing themselves out of the market very quickly.
No... This is like getting an apple but it's missing all of it's skin. Allowing you to paint on the color of apple you want.
(Except when it's closed source like Unity.)
Yeah not to sound cocky but I'm probably more experienced with it than most developers. I've been a game developer for about 5 years now, professionally, getting paychecks for all 5 years.
sander1095 ยท 2 points ยท Posted at 15:28:35 on May 23, 2016 ยท (Permalink)
Maybe just have 1 level, and have some classes that create the layout of the level?
decster584 ยท 5 points ยท Posted at 15:51:15 on May 23, 2016 ยท (Permalink)
Isn't that exactly what he's doing here? Level15 extends the class Level.
sander1095 ยท 6 points ยท Posted at 16:00:04 on May 23, 2016 ยท (Permalink)
No, I mean having just one level as a scene called Level (or something like that)
When loading Candy Crush level 1, you load that scene and in the Start() method or something you set up the level (Every level is the same, the layout is just a bit different). Maybe you have a class called
GameConfigwhich has a variable calledLevelLayoutToLoad. The Scene uses this and sets up that layout.You could do that for every level in Candy Crush because every level is the same, except the layout of the grid in which the candies are in is different. (as far as I remember (I never really played it))
dnew ยท 4 points ยท Posted at 16:28:50 on May 23, 2016 ยท (Permalink)
This is pretty much the same thing, except you're using C# to interpret the configuration instead of writing your own parser. What's the advantage of doing a data-driven level design if the game is such that you have (for example) cutscenes at the beginning of each providing the intro?
Doing it this way is much better if the gameplay actually is different each level.
sander1095 ยท 2 points ยท Posted at 17:13:15 on May 23, 2016 ยท (Permalink)
I guess you're right, but you could do it my way if every level is exactly the same. I'm new to programming with Unity and to creating games in general, so I'm still learning about ways to implement things
dnew ยท 3 points ยท Posted at 19:31:48 on May 23, 2016 ยท (Permalink)
Indeed. In essence, every level of a game is "the same, with different data" in some sense. Every unity game is just the same unity, with different data. To the person writing the game, it looks like different levels. To the programmers writing the game engine, it's just data for the game engine. Script this script that, all the same to us.
It's just a matter of which is easier, writing your own data-driven interpreter, or writing it in a script. Or writing an editor-plug-in to script your data. :-)
If you have different behaviors, it's easiest to code that behavior in a data format designed for coding behaviors, namely C# source code. :-)
oxysoft ยท 1 points ยท Posted at 03:30:54 on May 24, 2016 ยท (Permalink)*
I find that more people will write custom classes for each levels of their games when they are using just a rendering framework or during a game jam. Otherwise, those using game engines and more full fledged solutions will usually load levels from some external format and maybe even use scripting for games with lots of interaction (e.g. rpgs/jrpgs).
But the external data approach is usually considered to be superior and preferable as the data be easily reloaded at runtime and edited whilst the game is running, which is a great advantage. Note however that with C#, it is actually possible to compile C# code at runtime and run it dynamically as a scripting language.
decster584 ยท 3 points ยท Posted at 16:02:02 on May 23, 2016 ยท (Permalink)
OK, I'm with you now. That makes sense.
[deleted] ยท 1 points ยท Posted at 16:13:33 on May 23, 2016 ยท (Permalink)
In case of a game with preset levels, load level data from files on the hard drive.
In case of Candy Crush, they probably got a random level generator written,
Relevant_Monstrosity ยท 1 points ยท Posted at 19:33:48 on May 23, 2016 ยท (Permalink)
Favor composition. Define a template level, then use behavioral patterns to flesh it out:
https://en.wikipedia.org/wiki/Behavioral_pattern
jfb1337 ยท 1 points ยท Posted at 08:16:58 on May 24, 2016 ยท (Permalink)
Well there would only be a few types of levels (either compete it in x amount of time, or x number of moves, abd either get to A specific score, clear all the tiles, or drop some tiles to the bottom of the level), abs besides that, each level is the same except the layout. So you would have a class for each type of level, and then the levels themselves would be stored in a config file with their level type and their layout, which would be loaded dynamically.
btowntkd ยท 5 points ยท Posted at 18:11:07 on May 23, 2016 ยท (Permalink)
I'm not sure "hard-coded" is fair.
Yes, it's physically coded in C#, but in Unity C# files are considered 'scripts.'
He scripted his level, which seems reasonable.
localuser- ยท 3 points ยท Posted at 13:03:59 on May 23, 2016 ยท (Permalink)
Something in me got really upset about it, but really, for very small games I imagine it helps to keep the gameplay a bit more dynamic.
dnew ยท 3 points ยท Posted at 16:27:03 on May 23, 2016 ยท (Permalink)
Nah. Thief had that, and there was a separate configuration file saying what levels came in which order. It's just the name of the class, after all.
rbnc ยท 4 points ยท Posted at 16:27:43 on May 23, 2016 ยท (Permalink)
Exactly, whenever I see numbers in a variable, class or property I know there's probably a problem.
Cringing already.
00yoshi ยท 6 points ยท Posted at 17:49:25 on May 23, 2016 ยท (Permalink)
That time I didn't knew that arrays existed... Just tried to save the elements on the hdd, the filename being the index.
Get-ADUser ยท 0 points ยท Posted at 12:47:20 on May 23, 2016 ยท (Permalink)
Yes.
VRMac ยท -6 points ยท Posted at 12:17:37 on May 23, 2016 ยท (Permalink)
I came here to point this out.
OneMansGlory ยท 31 points ยท Posted at 11:54:23 on May 23, 2016 ยท (Permalink)
EnemyMovement.cs? What is your friend developing OP?
lunch431 ยท 57 points ยท Posted at 12:03:03 on May 23, 2016 ยท (Permalink)
#justISISthings
Spicybrownsounds ยท 26 points ยท Posted at 14:51:26 on May 23, 2016 ยท (Permalink)
This code is from an audio only indie game I'm developing called Sight Unseen. I snapped the photo when working with my programmer... I don't know who OP is but he is not on my team and certainly did not take the photo.
Proof: @blackout_vr's Tweet: https://twitter.com/blackout_vr/status/734106919602954240?s=09
sugardeath ยท 5 points ยท Posted at 17:28:13 on May 23, 2016 ยท (Permalink)
That's weird, because over here OP claims the code belongs to his friend.
/r/karmacourt
Spicybrownsounds ยท 4 points ยท Posted at 18:39:17 on May 23, 2016 ยท (Permalink)
Yeah i probably would have let it slide if not for that comment :/
sugardeath ยท 0 points ยท Posted at 19:30:20 on May 23, 2016 ยท (Permalink)
You should probably stab him.
OneMansGlory ยท 1 points ยท Posted at 15:03:11 on May 23, 2016 ยท (Permalink)
Nice! I look foward to seeing that when it's released.
Mikevin ยท 4 points ยท Posted at 18:16:24 on May 23, 2016 ยท (Permalink)
I see what you did there.
OneMansGlory ยท 1 points ยท Posted at 23:46:09 on May 23, 2016 ยท (Permalink)
hehehehehe
00yoshi ยท 1 points ยท Posted at 18:25:31 on May 23, 2016 ยท (Permalink)
So you make an audio-only game in unity?
Spicybrownsounds ยท 2 points ยท Posted at 18:38:28 on May 23, 2016 ยท (Permalink)
Yeah! It's a stealth survival game:) We have physically modeled reverb, occlusion and diffraction. We also use tools like wwise so working through an engine like unity allows us to easily have multiplatform support while the use of external tools allow us to have boss audio capabilities since unity kind of has a shitty audio engine.
b1ack1323 ยท 12 points ยท Posted at 12:17:17 on May 23, 2016 ยท (Permalink)
Thats using the unity gaming engine, so a video game.
MemoryLapse ยท 1 points ยท Posted at 14:38:41 on May 23, 2016 ยท (Permalink)
It's a component in an entity-component-system.
aaziz88 ยท 10 points ยท Posted at 19:36:41 on May 23, 2016 ยท (Permalink)
Turn on line numbers you barbarian.
AdeonWriter ยท 18 points ยท Posted at 11:31:25 on May 23, 2016 ยท (Permalink)
friend class Enemy;
CoderBrother ยท 2 points ยท Posted at 22:24:43 on May 24, 2016 ยท (Permalink)
FTFY ;-)
LordZikarno ยท 23 points ยท Posted at 09:53:47 on May 23, 2016 ยท (Permalink)
Ha! Nice one OP.
fredthomsen ยท 1 points ยท Posted at 12:43:57 on May 23, 2016 ยท (Permalink)
Made my morning.
Rhed0x ยท 33 points ยท Posted at 11:33:35 on May 23, 2016 ยท (Permalink)
Public fields O_O
EquationTAKEN ยท 74 points ยท Posted at 12:19:32 on May 23, 2016 ยท (Permalink)
Fuck yo gettas and settas, bitch.
SadDragon00 ยท 20 points ยท Posted at 15:31:46 on May 23, 2016 ยท (Permalink)
Getters and setters? Public properties is where it's at.
#justcsharpthings
ragingRobot ยท 29 points ยท Posted at 13:02:58 on May 23, 2016 ยท (Permalink)
Actually in Unity if you make it public it allows you to edit the value from inside of the unity interface. That way you can assign a value to it by dragging a game object in a menu. It makes things easier if you are working with someone else who doesn't know how to code.
FanoTheNoob ยท 13 points ยท Posted at 14:19:02 on May 23, 2016 ยท (Permalink)
You can also declare the fields as private and add the [SerializeField] attribute to those that you wish to expose to the inspector, then create properties for the ones you need to expose to your other classes.
This is really helpful when you have a lot of variables that are set in the inspector but shouldn't be changed anywhere else in your code.
cloudywater ยท 3 points ยท Posted at 18:16:32 on May 23, 2016 ยท (Permalink)
hey thanks, I didn't know that.
nami474 ยท 2 points ยท Posted at 20:35:55 on May 23, 2016 ยท (Permalink)
Thank you Thank you! Now I can stop feeling dirty making so many public fields! Private + SerializeField. Thank you kind sir.
Rhed0x ยท 8 points ยท Posted at 13:52:30 on May 23, 2016 ยท (Permalink)
Why can't you just use properties (and/or attributes)? WPF uses properties to expose it to the editor and so does every other piece of software that is using C#. Shitty Unity.
fistacorpse ยท 16 points ยท Posted at 14:14:11 on May 23, 2016 ยท (Permalink)
Unity's usage of C# is an abortion which uses an old version of Mono, before auto-properties existed. It is an archaic system which uses reflection at runtime in the designer UI to determine user editable properties, and doesn't include properties.
Hopefully now that the .NET framework is open source they'll work on fixing issues that were introduced by using Mono (which was needed for cross platform compilation), but it'll either take a long time or a semi / total rewrite. The only way I see it happening anytime soon is if Microsoft buys Unity (like they did with Xaramin) and decided to properly integrate it into .NET and Visual Studio.
oyok2112 ยท 7 points ยท Posted at 16:11:57 on May 23, 2016 ยท (Permalink)
Amen to that. I "love" how Unity overrides properties if you've touched them in the inspector, unless you set them in the "Start" method, causing confusing messes like "why the hell is my movement speed still 10 when I'm initializing it to be 50" and pretty soon you have no idea where any values are coming from at all.
Rhed0x ยท 2 points ยท Posted at 14:19:29 on May 23, 2016 ยท (Permalink)
Aren't they trying to get away from Mono with IL2CPP?
CoderHawk ยท 3 points ยท Posted at 18:36:43 on May 23, 2016 ยท (Permalink)
Now that's some horror.
doubl3h3lix ยท 18 points ยท Posted at 12:15:21 on May 23, 2016 ยท (Permalink)
It's not java.
Rhed0x ยท 21 points ยท Posted at 13:02:54 on May 23, 2016 ยท (Permalink)
C# has properties for these cases. Microsoft advises against public fields (except in structs maybe)
doubl3h3lix ยท 7 points ยท Posted at 13:08:23 on May 23, 2016 ยท (Permalink)
Good call, just gave that stuff a read.
MemoryLapse ยท 3 points ยท Posted at 14:37:01 on May 23, 2016 ยท (Permalink)
Unity can be a somewhat special case of C#, although I'm pretty sure it still supports properties. Their implementation of JavaScript is... Interesting, to say the least.
00yoshi ยท 2 points ยท Posted at 18:21:15 on May 23, 2016 ยท (Permalink)
It's called UnityScript for a reason.
[deleted] ยท 2 points ยท Posted at 15:00:30 on May 23, 2016 ยท (Permalink)
Link please, I wonder why that is.
Rhed0x ยท 3 points ยท Posted at 15:04:47 on May 23, 2016 ยท (Permalink)
https://msdn.microsoft.com/en-us/library/ms173118.aspx
https://msdn.microsoft.com/en-us/library/ta31s3bc(v=vs.71).aspx
[deleted] ยท 2 points ยท Posted at 16:44:00 on May 23, 2016 ยท (Permalink)
Oh, okay, thanks! I'll definitely be using properties from now on.
dnew ยท 2 points ยท Posted at 16:33:49 on May 23, 2016 ยท (Permalink)
Because if you make it a property, then compiled code calls the stub to get the value. The JIT will generally optimize out that call, so it's just as efficient.
If you make it a public field, code compiled against it by others will access the public field directly, and you'd actually need to compile that code again if you wanted to change the public field to a property.
In other words, it's important if the person writing the class doesn't have control over the compilation of the clients.
[deleted] ยท -9 points ยท Posted at 12:09:44 on May 23, 2016 ยท (Permalink)
Making a new line for the opening curly brackets
Dragon_Slayer_Hunter ยท 18 points ยท Posted at 12:34:04 on May 23, 2016 ยท (Permalink)
That's default with ReSharper and C#
xDatBear ยท -9 points ยท Posted at 13:09:04 on May 23, 2016 ยท (Permalink)
And it's the first thing I change when installing ReSharper
Schmittfried ยท 11 points ยท Posted at 14:34:22 on May 23, 2016 ยท (Permalink)
Which is kinda stupid, since it's the general convention with C#.
afdsadf ยท 1 points ยท Posted at 15:38:14 on May 23, 2016 ยท (Permalink)
Two words: Kernighan, Ritchie
xDatBear ยท 2 points ยท Posted at 15:47:55 on May 23, 2016 ยท (Permalink)
One True Brace
Rhed0x ยท 14 points ยท Posted at 13:04:30 on May 23, 2016 ยท (Permalink)
That's standard in C#.
It's part of the official Microsoft guidelines and basically part of every other C# coding style as well. (Except for maybe Unity cause Unity is weird)
IlanRegal ยท 7 points ยท Posted at 12:40:03 on May 23, 2016 ยท (Permalink)
What are you, some kind of savage?
Dragon_Slayer_Hunter ยท 7 points ยท Posted at 13:41:30 on May 23, 2016 ยท (Permalink)
In some other languages, like JavaScript, it's standard to have it on the same line. It just depends what language you're in and the style guides you're working with, but if a developer is used to one language then they might be thrown off when they see another and it's different from how they expect.
nitiger ยท 6 points ยท Posted at 14:06:42 on May 23, 2016 ยท (Permalink)
That's why it's best to follow the style that the document already is in when working with team mates.
JereTheJuggler ยท 17 points ยท Posted at 11:21:59 on May 23, 2016 ยท (Permalink)
Was a bit confused at first about what subreddit this was from. Thought it was /r/Megadeth
Zalani ยท 3 points ยท Posted at 13:30:01 on May 23, 2016 ยท (Permalink)
Glad to see i wasn't the only one. I thought this was from /r/Metal for a second.
Blackstab1337 ยท 1 points ยท Posted at 03:45:09 on May 24, 2016 ยท (Permalink)
The one album im missing in my collection! :(
parenthesis-bot ยท 2 points ยท Posted at 03:49:30 on May 24, 2016 ยท (Permalink)
:)
This is an autogenerated response. source | /u/HugoNikanor
Blackstab1337 ยท 1 points ยท Posted at 03:55:53 on May 24, 2016 ยท (Permalink)
:(
parenthesis-bot ยท 2 points ยท Posted at 03:59:32 on May 24, 2016 ยท (Permalink)
:)
This is an autogenerated response. source | /u/HugoNikanor
Blackstab1337 ยท 1 points ยท Posted at 04:04:19 on May 24, 2016 ยท (Permalink)
:(
parenthesis-bot ยท 2 points ยท Posted at 04:04:33 on May 24, 2016 ยท (Permalink)
:)
This is an autogenerated response. source | /u/HugoNikanor
pablossjui ยท 1 points ยท Posted at 07:21:51 on May 24, 2016 ยท (Permalink)
:( (( ::(( ()::):)
parenthesis-bot ยท 1 points ยท Posted at 07:24:57 on May 24, 2016 ยท (Permalink)
: :)))
This is an autogenerated response. source | /u/HugoNikanor
[deleted] ยท 3 points ยท Posted at 10:50:39 on May 23, 2016 ยท (Permalink)
https://www.youtube.com/watch?v=V6dUAaftfzw
BarqsDew ยท 3 points ยท Posted at 11:59:00 on May 23, 2016 ยท (Permalink)
I am not your enemy!
AlthDClaw ยท 3 points ยท Posted at 12:50:02 on May 23, 2016 ยท (Permalink)
Understand.
sli908 ยท 3 points ยท Posted at 16:47:58 on May 23, 2016 ยท (Permalink)
I'm TNT
AlthDClaw ยท 2 points ยท Posted at 16:53:45 on May 23, 2016 ยท (Permalink)
I'm dynamite
waghwagh6 ยท 2 points ยท Posted at 17:18:13 on May 23, 2016 ยท (Permalink)
TNT
AlthDClaw ยท 3 points ยท Posted at 18:09:58 on May 23, 2016 ยท (Permalink)
and I'll win the fight
the_real_gorrik ยท 1 points ยท Posted at 17:57:09 on May 23, 2016 ยท (Permalink)
Im dynamite
00yoshi ยท 1 points ยท Posted at 18:27:56 on May 23, 2016 ยท (Permalink)
Trinitrotoulene?
NutSlapper69 ยท 3 points ยท Posted at 14:25:02 on May 23, 2016 ยท (Permalink)
Understand
I_AM_AN_AEROPLANE ยท 3 points ยท Posted at 20:50:53 on May 23, 2016 ยท (Permalink)
There is so much bad practice in these comments it terrifies me. I hope most of you do NOT work as a professional (game) programmer.
jfb112697 ยท 2 points ยท Posted at 13:07:35 on May 23, 2016 ยท (Permalink)
Wonder who private enemy numberOne is...
MurlockHolmes ยท 3 points ยท Posted at 13:45:22 on May 23, 2016 ยท (Permalink)
The compiler would've made him behind the scenes if OPs friend used a getter and a setter
WoodTrophy ยท 2 points ยท Posted at 13:49:22 on May 23, 2016 ยท (Permalink)
I feel dumb because I don't get it.
BarqsDew ยท 3 points ยท Posted at 14:20:52 on May 23, 2016 ยท (Permalink)
https://en.wikipedia.org/wiki/Public_Enemy_No._1
WoodTrophy ยท 1 points ยท Posted at 14:23:07 on May 23, 2016 ยท (Permalink)
Thanks!
myrrlyn ยท 1 points ยท Posted at 15:00:13 on May 23, 2016 ยท (Permalink)
The phrase 'public enemy number one is used to refer to notorious, wanted criminals
[deleted] ยท 1 points ยท Posted at 15:24:26 on May 23, 2016 ยท (Permalink)
bass
salmonmoose ยท 2 points ยท Posted at 23:31:25 on May 23, 2016 ยท (Permalink)
Are you defining levels in individual classes?
I'm sure you're not defining levels in individual classes.
kaiken1987 ยท 2 points ยท Posted at 01:34:58 on May 24, 2016 ยท (Permalink)
Still nothing makes me giggle like
ypoora1 ยท 2 points ยท Posted at 07:22:41 on May 24, 2016 ยท (Permalink)
Should have called it numberFive.
Who's Johnny, she said...
[deleted] ยท 2 points ยท Posted at 19:53:27 on May 23, 2016 ยท (Permalink)
You seriously couldn't take a screenshot and you're a programmer?
penguinade ยท 1 points ยท Posted at 12:37:04 on May 23, 2016 ยท (Permalink)
Here's my contribution!
Sometimes my fantasies just overpowered my logical mind.
wootiown ยท 1 points ยท Posted at 13:25:58 on May 23, 2016 ยท (Permalink)
This enemy is obviously Smitty werbenjengermanjenson
AdrianoRoss ยท 1 points ยท Posted at 16:02:54 on May 23, 2016 ยท (Permalink)
Terminator.exe
[deleted] ยท 1 points ยท Posted at 16:09:31 on May 23, 2016 ยท (Permalink)
I am a bit of a programming noob, but why is it necessary to have two classes specifically for movement? Would it not have made more sense for the Enemy/Block classes to both be abstract with an abstract function called "movement"?
makeswordcloudsagain ยท 1 points ยท Posted at 16:11:48 on May 23, 2016 ยท (Permalink)
Here is a word cloud of every comment in this thread, as of this time: http://i.imgur.com/3Q7gPku.png
[source code] [contact developer] [request word cloud]
BurningPenguin ยท 0 points ยท Posted at 19:14:30 on May 23, 2016 ยท (Permalink)
That feeling when a programmer takes a photo of his screen with a damn smartphone.
You could at least have programmed your own screenshot tool.
Sinidir ยท -1 points ยท Posted at 16:12:28 on May 23, 2016 ยท (Permalink)
Wow that is really funny, because the visibility qualifier, the type and the name of the variable form the popular phrase "public enemy number one" together.
[deleted] ยท 1 points ยท Posted at 18:10:36 on May 23, 2016 ยท (Permalink)
Thanks.
[deleted] ยท -27 points ยท Posted at 11:06:30 on May 23, 2016 ยท (Permalink)
[deleted]
VoxUmbra ยท 2 points ยท Posted at 14:41:26 on May 23, 2016 ยท (Permalink)
Ew, an ellipsis where the number of periods isn't 3!
Solero93 ยท -8 points ยท Posted at 11:12:37 on May 23, 2016 ยท (Permalink)
Eeew eeew eeewwwnity!
EquationTAKEN ยท 9 points ยท Posted at 12:20:22 on May 23, 2016 ยท (Permalink)
EHRMAGERD YERNERTER!
Insomn ยท 15 points ยท Posted at 12:33:21 on May 23, 2016 ยท (Permalink)
So this is where you Unreal Engine guys are hanging out.
EquationTAKEN ยท 3 points ยท Posted at 12:51:27 on May 23, 2016 ยท (Permalink)
Haha yeah, bottom of the comment section!
Nah, I'm a Unity guy myself. Liked it, although I suspect there are better alternatives.