Slightly off-topic; if there ever was a excellent example of what it means when a C# program is being written by a java developer, this would certainly qualify.
Was this ported from a java project?
Slightly off-topic; if there ever was a excellent example of what it means when a C# program is being written by a java developer, this would certainly qualify.
Was this ported from a java project?
Here's what I've noticed so far:
- Uses camelCase instead of PascalCase
- Uses setter and getter methods instead of C# properties.
- Uses reverse DNS namespace com.mc2k.SimCityReader instead of e.g. JGosar.MineCity2000.SimCityReader.
- Lack of LINQ (It is such a big part of C#, that not using it at all is strange).*
- Lac of using generics e.g. List<string> instead of string[].*
- Excessive use of arrays (you'd typically use a simple IEnumerable<T> or List<T>).
- Lack of `var`.*
- Casting integer literals to short, byte, etc -- these all have equivalent literal notation.*
- Lack of extension methods.*
- Lack of maps (pattern matching).*
There could be more, but those are what I noticed.
EDIT: * Given that the original code was done with VS 2010 and .NET Framework 4, its fair to say that a few of the points above do not apply, but the code is nevertheless very java-esque (just from the first two points).
My understanding with array performance is that if you need to frequently read and write to a large, fixed-length enumerable (or if you can rework your problem as such), then an array of structs is often much faster. It's certainly on my mental list of things to try when dealing with large sets of data in hot loops.
The intuitive expectation about performance difference between array and a generic collection is that it's about method call overhead, because in practice, unless "no duplicate entries" set semantics are required what you call "enumerable" will be an object wrapping an underlying array almost ten out of ten times. But that's something JIT optimization excels at dealing with. The real advantage of arrays is memory proximity and in absence of project valhalla future VM features, that advantage only exists for arrays of primitives like int, float, double. Everything else will be a reference to some arbitrary heap address anyways, even if it's reference in a bare array (instead of references in an array wrapped by an object).
What you can do is rework your data into a form where multiples of something have the primitives of their logical fields in shared arrays, but that's not array of structs but struct of arrays. And I've never seen code like that in the wild, not outside a hobby project that I never even got to the point where I could verify the approach by profiling. I do believe that the pattern must exist, I some codebases, but I can't even think of a name people would recognize.
But generally I think it's just older than the git history indicates. The sln file mentions Visual Studio 2010!
The original README mentions .NET Framework 4, so C# has progressed a fair amount since.
[0] https://github.com/jgosar/mine-city-2000/commit/f1cbe98601c4...
I figure you noticed the drastic increase in repo activity and stars. What's your own opinion on java-ness of the code? Do you feel it is an accurate assessment?
I hope you didn't take it personal, I've most certainly done similar things when I learned C# after doing java for the initial university courses.
If anything, the code style is reminding me more about classic game code, where they use arrays instead of List and are more concerned about data types and memory usage. Maybe this person is coming from a background of game programming and/or C(++)?