Hacker News new | ask | show | jobs
by Systemic33 1301 days ago
Very cool idea and execution.

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?

4 comments

When did we get C# devs flexing on Java devs? Isn't like that like a paint by numbers expert flexing on a paint by letters kinda person?
Oh this is so mean ;)
Could you give examples of what you mean? I've had a look through and there are certainly stylistic things I'd do differently, such as using "var" and LINQ more, and capitalising method names. But it's easy enough to understand despite that.
Don't get me wrong, it's not "bad" code (from a brief glance) but it's just clearly written as if it was Java code, and probably not in a usual IDE like Visual Studio, Rider or VSCode /w C# plugin (as that would typically scaffold a more C#-esque style).

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).

https://github.com/jgosar/mine-city-2000/blob/master/MineCit... contains "private byte[][][][][][][] _blockDatas;" which made my eye twitch.

But generally I think it's just older than the git history indicates. The sln file mentions Visual Studio 2010!

Hi, I'm the author of this project. I actually coded most of it in 2014, i just did some refactoring and uploaded it to GitHub in 2019 after I mentioned it in a job interview and the guy asked if the code is uploaded anywhere so he could look at it.
Hi jgosar, and thanks for joining into the discussion :D

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.

Yes, I mostly worked on Java and C# projects at the time, so it's understandable:)
Ye this commit [0] imports a "local repository" with Visual Studio 2010 .sln file.

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...

Excessive use of arrays can be a sign of many things, but not of being a java developer. Perhaps a sign of having been a java developer at some point in time before 2004 but not having touched the language ever since.
An array can be much more performant than a list in many circumstances, but I agree it's a little strange to completely avoid lists.
True, and "circumstances" basically means "if and only if we are taking about arrays of primitives". Outside of specific niches like http clients, I'd go so far as considering code written to deliberately tap those performance benefits as "written by people who ceased to be java developers" ;)
I will take your word about java, having never actually worked with it myself!

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.

I looked at the code from a Java developer point of view, and besides the first 2 points, I don't see anything that was Java-specific.

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(++)?

I'm saving this as it's an excellent guide for taking my dated pre-LINQ C# skills and polishing them up as need be
We were working on a mix of Java and C# projects at work at the time I started writing this, so that's probably why the code looks like a mix between the two.
It's typical how this particular project / codebase attracts so many armchair code reviewers (in multiple threads); I've not seen anything like that on HN for ages. Is C# / Java some kind of trigger for it?