|
only use Goto if you like spaghetti code
|
|
|
|
|
i use gotos for generated state machine code so the code will look exactly like the graphs generated by graphviz. it makes the code more understandable.
like this snippet, implementing q1 of the graph:
q1:
if((pc.Current>='0'&& pc.Current<='9')||
(pc.Current>='A'&& pc.Current<='Z')||
(pc.Current=='_')||
(pc.Current>='a'&& pc.Current<='z')) {
sb.Append((char)pc.Current);
pc.Advance();
goto q1;
}
return new System.Collections.Generic.KeyValuePair<System.String,string>("id",sb.ToString());
from (A Regular Expression Engine in C#[^])
there's supposed to be a picture at the link but it's no longer showing up for me. maybe it will for you.
in any case, there's a time and a place for everything.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
If you can keep it that ordered then that is good. The problem with the convenience of goto is that it tends to end up being over-used and that is what leads to problems.
|
|
|
|
|
yeah, i use gotos pretty much in generated code. in this case, it just happened to make the code clearer, but state machines are kind of their own animal. It's really hard to implement one using "proper" looping techniques. At best you have a while(true) loop with a giant switch case in it. =(
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Define purist?
Because using C the way it was designed to be used in more pure.
|
|
|
|
|
I know it, but it still strikes me as unreadable.
It's like a frankenstein of a language that wants to be C# but is like 1/3 c++/stl in how its interfaces look.
plus source level templates - cool sort of, but another cppism.
I find it actually easier to read and port between C# and c++ despite them being so different, because they're at least consistent about their differences. To the point where you can often do editor find replace (-> to . for example) to do a lot of the work for you. The point is, it's a lot more regular. All size() becomes Count. The iterators are pointers, they don't have a bunch of weird methods on them in C++.
It's just straightforward. Reading, writing, porting and thinking in java is creaky or clunky, IMO.
I can't even put my finger on all of it. I just don't like it.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Java should have been originally named Jawavawavaa.Jawaavaava().
For the kind of verboseness it carries within.
|
|
|
|
|
i think that's a big part of what i don't like about it.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Actually Java was first and C# tried to be Java (which it luckily isn't)
Of course C# only fixed the multi-platform stuff with .NET Core, about 15 years later.
I don't like Java either though.
|
|
|
|
|
i know it was first. what i mean is Java tried to be C# and missed. Microsoft was the one who delivered on managed code.
Microsoft may have waited 15 years, but open sourcers didn't. See Mono and others. .NET has been running on linux systems for quite awhile - since the .NET 1.x days.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Second runner up advantage. Microsoft has turned it into a sport of sorts.
Problem was just that in phones they were third. That's not good enough.
|
|
|
|
|
#trueFacts
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
|
he'd probably fite me (ง'̀-'́)ง
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
I dislike java and c#. I see no redeeming features in either of them.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
i like C#. it's good at what it's designed to do, unlike java.
and programming with full metadata/type-info available is really nice.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
I only use Java for Minecraft modding. Otherwise I use either C# or Python 3.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
python is a cool language but I will never forgive it for using both significant and insignificant whitespace.
You need context-sensitivity in a parser to make that parse.
It's ridiculous.
I almost want to organize a general strike against python. I would if I didn't otherwise like it so much.
But that... GRRRR.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
honey the codewitch wrote: It's like a frankenstein of a language that wants to be C#
C# is Microsofts version of Java.
Remember when they got fined by the courts for messing around with Java?
Well they came up with .Net (an interpreter) and C# in revenge. (Ever wondered why J++ byte code can run direct on .Net?)
And then pretty much took over, Java is now almost dead except for a few specific applications. J2EE comes to mind.
|
|
|
|
|
yeah, i know.
i didn't mean that C# came first. I meant that Java aimed to be something like C# and missed.
and yes i remember that lawsuit. i was working at microsoft at the time.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Microsoft improved Java, so Sun sued them. The end result is that Microsoft, who already had .NET, simply changed J# to C# and made a better language.
Sun went out of business. Too much spent on lawyers and being anti-MS instead of innovating and working together. Same with Netscape.
MS has had no effect on how Java evolved, except that Sun, and now Oracle, started copying C# and trying to catch up.
MS had .NET and VB.NET in development before the lawsuits. Since in .NET, languages are syntactic sugar over the MSIL, adding languages like C# was not a tough stretch.
|
|
|
|
|
Inspired by witch the codehoney asking about our ugliest code I looked up some of my earliest code.
I was just getting started and wanted to experiment a bit with inheritance.
So I decided to make a (turn based) Final Fantasy like battle game
It's VB so you're warned... (awesome pictures at the bottom)
Somehow I thought BaseMonster was a good idea (especially notice how I check if the type of Me (this) is not of a specific derived type).
The BackgroundWorker is also pretty neat!
Namespace BaseCharacters
Public MustInherit Class BaseMonster
Inherits BaseDefence
Private m_Name As String
Private m_Level As Integer
Private m_HP As Integer
Private m_CurrentHP As Integer
Private m_MP As Integer
Private m_CurrentMP As Integer
Private m_Strength As Integer
Private m_CurrentStrength As Integer
Private m_Defence As Integer
Private m_CurrentDefence As Integer
Private m_Magic As Integer
Private m_CurrentMagic As Integer
Private m_MagicDef As Integer
Private m_CurrentMagicDef As Integer
Private m_Speed As Integer
Private m_CurrentSpeed As Integer
Private m_Image As Bitmap
Public Event Charging(ByVal sender As BaseCharacters.BaseMonster, ByVal e As System.ComponentModel.ProgressChangedEventArgs)
Public Event TurnStarted(ByVal sender As BaseCharacters.BaseMonster, ByVal e As System.EventArgs)
Public Event TurnEnded(ByVal sender As BaseCharacters.BaseMonster, ByVal e As System.EventArgs)
Public Event Killed(ByVal sender As BaseCharacters.BaseMonster, ByVal e As System.EventArgs)
Private WithEvents m_Bgw As System.ComponentModel.BackgroundWorker
Public Sub New()
InitializeBgw()
SetMonsterProperties()
If Not TypeOf Me Is BaseHumanoid Then
SetCurrentStatus()
End If
End Sub
MustOverride Sub SetMonsterProperties()
Public Sub SetCurrentStatus()
Me.CurrentHP = Me.HP
Me.CurrentMP = Me.MP
Me.CurrentStrength = Me.Strength
Me.CurrentDefense = Me.Defense
Me.CurrentMagic = Me.Magic
Me.CurrentMagicDef = Me.MagicDef
Me.CurrentSpeed = Me.Speed
m_Bgw.RunWorkerAsync()
End Sub
Public Sub Me_TurnEnded(ByVal sender As BaseCharacters.BaseMonster, ByVal e As System.EventArgs) Handles Me.TurnEnded
m_Bgw.RunWorkerAsync()
End Sub
The BaseDefence is just a bunch of properties that indicate elemental defence.
Public MustInherit Class BaseDefence
#Region "Magic Defense"
Private m_AstralDef As DefenceDefinition.DefenceEnum = DefenceDefinition.DefenceEnum.Normal
Private m_DarkDef As DefenceDefinition.DefenceEnum = DefenceDefinition.DefenceEnum.Normal
Private m_EarthDef As DefenceDefinition.DefenceEnum = DefenceDefinition.DefenceEnum.Normal
Private m_FireDef As DefenceDefinition.DefenceEnum = DefenceDefinition.DefenceEnum.Normal
Private m_GravityDef As DefenceDefinition.DefenceEnum = DefenceDefinition.DefenceEnum.Normal
Private m_HealingDef As DefenceDefinition.DefenceEnum = DefenceDefinition.DefenceEnum.FullAbsorb
Private m_HolyDef As DefenceDefinition.DefenceEnum = DefenceDefinition.DefenceEnum.Normal
Private m_IceDef As DefenceDefinition.DefenceEnum = DefenceDefinition.DefenceEnum.Normal
Private m_LightningDef As DefenceDefinition.DefenceEnum = DefenceDefinition.DefenceEnum.Normal
Private m_PoisonDef As DefenceDefinition.DefenceEnum = DefenceDefinition.DefenceEnum.Normal
Private m_WaterDef As DefenceDefinition.DefenceEnum = DefenceDefinition.DefenceEnum.Normal
Private m_WindDef As DefenceDefinition.DefenceEnum = DefenceDefinition.DefenceEnum.Normal
Public Property AstralDef() As DefenceDefinition.DefenceEnum
Get
Return m_AstralDef
End Get
Set(ByVal value As DefenceDefinition.DefenceEnum)
m_AstralDef = value
End Set
End Property
A BaseHumanoid is a monster of sorts and unless I'm Barrett from Final Fantasy VII I don't think my main hand is actually a weapon
Namespace BaseCharacters
Public MustInherit Class BaseHumanoid
Inherits BaseMonster
Private m_OffHand As IOffHand
Private m_MainHand As BaseWeapon
Private m_Magic As New List(Of BaseSpell)
Public Sub New()
MyBase.New()
SetHumanProperties()
SetCurrentStatus()
End Sub
Overrides Sub SetMonsterProperties()
End Sub
MustOverride Sub SetHumanProperties()
Public ReadOnly Property GetMagic() As List(Of BaseSpell)
Get
Return m_Magic
End Get
End Property
Time to define my Hero!
Public Class Hero
Inherits BaseCharacters.BaseHumanoid
Public Sub New(ByVal name As String)
MyBase.New()
Me.Name = name
End Sub
Public Overrides Sub SetHumanProperties()
Me.Level = 10
Me.Strength = 10
Me.HP = 100
Me.MP = 10
Me.Defense = 10
Me.Magic = 10
Me.MagicDef = 10
Me.Speed = 4
Me.Image = My.Resources.super_hero
Me.MainHand = New HealingStaff
Me.AddMagic = New IceWhisper
End Sub
End Class And of course an actual monster:
Public Class Imp
Inherits BaseCharacters.BaseMonster
Public Sub New()
MyBase.New()
End Sub
Public Overrides Sub SetMonsterProperties()
Me.Name = "Imp"
Me.Level = 3
Me.Strength = 6
Me.Defense = 3
Me.HP = 50
Me.MP = 5
Me.Speed = 3
Me.Image = My.Resources.images
End Sub
End Class I also need a landscape to fight in:
Public Class Forest
Implements ILandscape
Public Function GetMonster() As BaseCharacters.BaseMonster Implements ILandscape.GetMonster
Dim random As New Random
Dim i As Integer = random.Next(0, 2)
Select Case i
Case 0
Return New Imp
Case 1
Return New Harpy
Case Else
Return New Imp
End Select
End Function
Public ReadOnly Property BackGround() As System.Drawing.Bitmap Implements ILandscape.BackGround
Get
Return My.Resources.forest_wallpaper987
End Get
End Property
End Class And now your wondering what this all looked like?
It looked awesome! The imp never stood a chance![^]
And by simply changing the area from New Forest to New Dungeon I changed the entire battlefield!
So who's going to give me a job in game development?[^]
The images are just random google images for forest, dungeon, imp, skeleton and hero, and I cannot give credit because I don't know the source.
So I admit, my graphical skills have not increased since then.
But oh boy, just look at that code
|
|
|
|
|
Oh it's not that bad. It's like a little puppy. Maybe it makes a mess of things but it's cute.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
|
Sander Rossel wrote: ... some of my earliest code ...
(Posts VB.NET code)
Damn kids! Get of my lawn!
My earliest code would be more like:
10 PRINT "HELLO "
20 GOTO 10
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|