Opened 11 years ago

Closed 11 years ago

Last modified 10 years ago

#47 closed task (released)

Remove magic numbers

Reported by: ibboard Owned by: ibboard
Priority: major Milestone: WarFoundry 0.1
Component: General/Unknown Version:
Keywords: Cc:
Blocked By: Blocking:

Description

Some parts of WarFoundry have started to use "magic numbers" (numbers that have a special meaning but are just used inline). These should be replaced by named constants so that the meaning of the number is more obvious.

Change History (12)

comment:1 Changed 11 years ago by ibboard

(In r73) Fixes #34 - Remove "Choices" and "Base/Increment" from Category

  • Remove Choices and Base/Increment from code

Re #47: Remove magic numbers

  • Replace "-1" magic number with WarFoundryCore.INFINITY
  • Use INFINITY instead of -1 in code
  • Use INF in schemas instead of -1
  • Handle and parse INF as a special value in XML Factory

comment:2 Changed 11 years ago by ibboard

(In r74) Re #47: Remove magic numbers

  • Replace "-1" magic number with WarFoundryCore.INFINITY
  • Use INFINITY instead of -1 in code
  • Handle and parse INF as a special value in XML Factory

comment:3 Changed 11 years ago by ibboard

Schemas changes seem to be having problems that don't give enough detail to be useful:

WARN  [20:03:13]: LogNotifierHandler.Warn() - Line: 48 - WarFoundryLoader: XmlSchema error: The Attribute's default value is invalid with its type definition.
System.Xml.Schema.XmlSchemaException: XmlSchema error: The Attribute's default value is invalid with its type definition. ---> System.FormatException: Invalid character at position 0
  at System.Decimal.ThrowAtPos (Int32 pos) [0x00000] in /usr/src/packages/BUILD/mono-2.2/mcs/class/corlib/System/Decimal.cs:726 
  at System.Decimal.stripStyles (System.String s, NumberStyles style, System.Globalization.NumberFormatInfo nfi, System.Int32& decPos, System.Boolean& isNegative, System.Boolean& expFlag, System.Int32& exp, Boolean throwex) [0x00277] in /usr/src/packages/BUILD/mono-2.2/mcs/class/corlib/System/Decimal.cs:827 
  at System.Decimal.PerformParse (System.String s, NumberStyles style, IFormatProvider provider, System.Decimal& res, Boolean throwex) [0x00007] in /usr/src/packages/BUILD/mono-2.2/mcs/class/corlib/System/Decimal.cs:1036 
  at System.Decimal.Parse (System.String s, NumberStyles style, IFormatProvider provider) [0x0002d] in /usr/src/packages/BUILD/mono-2.2/mcs/class/corlib/System/Decimal.cs:1005 
  at System.Decimal.Parse (System.String s, IFormatProvider provider) [0x00000] in /usr/src/packages/BUILD/mono-2.2/mcs/class/corlib/System/Decimal.cs:721 
  at System.Xml.XmlConvert.ToDecimal (System.String s) [0x00000] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.XPath/Parser.cs:1 
  at Mono.Xml.Schema.XsdPositiveInteger.ParseValueType (System.String s, System.Xml.XmlNameTable nameTable, IXmlNamespaceResolver nsmgr) [0x00000] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.XPath/Parser.cs:1 
  at Mono.Xml.Schema.XsdPositiveInteger.ParseValue (System.String s, System.Xml.XmlNameTable nameTable, IXmlNamespaceResolver nsmgr) [0x00000] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/BuiltInDatatype.cs:1176 
  at System.Xml.Schema.XmlSchemaAttribute.Validate (System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x0026a] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/XmlSchemaAttribute.cs:432 
  --- End of inner exception stack trace ---
  at System.Xml.Schema.ValidationHandler.RaiseValidationEvent (System.Xml.Schema.ValidationEventHandler handle, System.Exception innerException, System.String message, System.Xml.Schema.XmlSchemaObject xsobj, System.Object sender, System.String sourceUri, XmlSeverityType severity) [0x0003d] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/ValidationHandler.cs:56 
  at System.Xml.Schema.XmlSchemaObject.error (System.Xml.Schema.ValidationEventHandler handle, System.String message, System.Exception innerException, System.Xml.Schema.XmlSchemaObject xsobj, System.Object sender) [0x00000] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/XmlSchemaObject.cs:140 
  at System.Xml.Schema.XmlSchemaObject.error (System.Xml.Schema.ValidationEventHandler handle, System.String message, System.Exception innerException) [0x00000] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.XPath/Parser.cs:1 
  at System.Xml.Schema.XmlSchemaAttribute.Validate (System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x0027e] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/XmlSchemaAttribute.cs:434 
  at System.Xml.Schema.XmlSchemaUtil.ValidateAttributesResolved (System.Xml.Schema.XmlSchemaObjectTable attributesResolved, System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema, System.Xml.Schema.XmlSchemaObjectCollection attributes, System.Xml.Schema.XmlSchemaAnyAttribute anyAttribute, System.Xml.Schema.XmlSchemaAnyAttribute& anyAttributeUse, System.Xml.Schema.XmlSchemaAttributeGroup redefined, Boolean skipEquivalent) [0x00217] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/XmlSchemaUtil.cs:552 
  at System.Xml.Schema.XmlSchemaComplexType.ValidateImmediateAttributes (System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x0000b] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/XmlSchemaComplexType.cs:646 
  at System.Xml.Schema.XmlSchemaComplexType.Validate (System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x00054] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/XmlSchemaComplexType.cs:601 
  at System.Xml.Schema.XmlSchemaElement.Validate (System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x000a1] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/XmlSchemaElement.cs:661 
  at System.Xml.Schema.XmlSchemaSequence.Validate (System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x00040] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/XmlSchemaSequence.cs:140 
  at System.Xml.Schema.XmlSchemaComplexType.ValidateContentFirstPass (System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x0005a] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/XmlSchemaComplexType.cs:658 
  at System.Xml.Schema.XmlSchemaComplexType.Validate (System.Xml.Schema.ValidationEventHandler h, System.Xml.Schema.XmlSchema schema) [0x0002c] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/XmlSchemaComplexType.cs:588 
  at System.Xml.Schema.XmlSchema.Validate (System.Xml.Schema.ValidationEventHandler handler) [0x0012d] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs:666 
  at System.Xml.Schema.XmlSchemaSet.Compile () [0x000a6] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/XmlSchemaSet.cs:207 
  at System.Xml.Schema.XmlSchemaValidator.Initialize () [0x00022] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs:291 
  at Mono.Xml.Schema.XmlSchemaValidatingReader..ctor (System.Xml.XmlReader reader, System.Xml.XmlReaderSettings settings) [0x00169] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/Mono.Xml.Schema/XmlSchemaValidatingReader.cs:153 
  at System.Xml.XmlReader.CreateValidatingXmlReader (System.Xml.XmlReader reader, System.Xml.XmlReaderSettings settings) [0x00043] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml/XmlReader.cs:433 
  at System.Xml.XmlReader.CreateFilteredXmlReader (System.Xml.XmlReader reader, System.Xml.XmlReaderSettings settings) [0x00080] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml/XmlReader.cs:405 
  at System.Xml.XmlReader.CreateCustomizedTextReader (System.Xml.XmlTextReader reader, System.Xml.XmlReaderSettings settings) [0x0007f] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml/XmlReader.cs:386 
  at System.Xml.XmlReader.Create (System.IO.Stream stream, System.Xml.XmlReaderSettings settings, System.Xml.XmlParserContext context) [0x0001b] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml/XmlReader.cs:341 
  at System.Xml.XmlReader.Create (System.IO.Stream stream, System.Xml.XmlReaderSettings settings, System.String baseUri) [0x00008] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml/XmlReader.cs:301 
  at System.Xml.XmlReader.Create (System.IO.Stream stream, System.Xml.XmlReaderSettings settings) [0x00000] in /usr/src/packages/BUILD/mono-2.2/mcs/class/System.XML/System.Xml/XmlReader.cs:282 
  at IBBoard.WarFoundry.API.Factories.Xml.WarFoundryXmlFactory.CreateXmlDocumentFromStream (System.IO.Stream stream) [0x00006] in /home/ibboard/eclipse/IBBoard.WarFoundry.API/api/Factories/Xml/WarFoundryXmlFactory.cs:296 
  at IBBoard.WarFoundry.API.Factories.Xml.WarFoundryXmlFactory.GetRootElementFromStream (System.IO.Stream stream, IBBoard.WarFoundry.API.Factories.Xml.WarFoundryXmlElementName elementName) [0x00000] in /home/ibboard/eclipse/IBBoard.WarFoundry.API/api/Factories/Xml/WarFoundryXmlFactory.cs:66 

comment:4 Changed 11 years ago by ibboard

Resolution: fixed
Status: newclosed

(In r75) Fixes #47 - remove magic numbers

  • Create "infinity" in core types
  • Redefine special core types without trying to use non-existant INF for Integers
  • Use new types in Cats and Race
  • Remove special handling of INF when parsing an integer attribute

Closes #46 - Resolve problems using custom restrictions of decimal and double

  • New schemas seem to work without exceptioning

comment:5 Changed 11 years ago by ibboard

Resolution: fixed
Status: closedreopened

Re-open to remove "magic numbers" in WinForms

comment:6 Changed 11 years ago by ibboard

Status: reopenedaccepted

comment:7 Changed 11 years ago by ibboard

Resolution: fixed
Status: acceptedclosed

Magic numbers all seem to be removed.

comment:8 Changed 11 years ago by ibboard

Resolution: fixed
Status: closedreopened

Re-open again because WinForms changes weren't actually committed.

comment:9 Changed 11 years ago by ibboard

Resolution: fixed
Status: reopenedclosed

(In r124) Closes #47 - Remove magic numbers

  • Replace "magic number" -1s in WinForms with WarFoundryCore.INFINITY

Also:

  • Code cleanup to remove warnings
  • Code cleanup to replace space indentation with tabs

comment:10 Changed 10 years ago by ibboard

released: 1

Mark released changes as released

comment:11 Changed 10 years ago by ibboard

released: 1yes

Mark released fixes as released using radio values

comment:12 Changed 10 years ago by ibboard

Resolution: fixedreleased

Mark fix as released under a previous version

Note: See TracTickets for help on using tickets.