• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Please help port C# Linq code to Java 8 Streams  RSS feed

 
Ranch Hand
Posts: 54
IntelliJ IDE Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There is a video of a guy refactoring a complex c# method  (The game Sudoku).
https://www.youtube.com/watch?v=3-QrwizdHkg
(The Serbian video has English subtitles, so turn captions on)

And here is the code:
https://github.com/zoran-horvat/sudoku-kata/blob/master/SudokuKata/SudokuKata/Program.cs

I want to do something similar in Java, so I aim to port this code to Java,
and trying to keep it as close to the original as possible - the good thing here is
that it consists of one method and one class only, so you can go from top to bottom through the code,
without having to click back and forth, which makes it a good fit for a live refactoring, I think.

I have ported most of the code, just the tough Linq bits are missing.
Lines 300-360 and 494-677  are specifically hard to port to Java.
Any help is greatly appreciated
 
Marshal
Posts: 63795
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Marcus Biel wrote:. . . the good thing here is that it consists of one method and one class only . . .

That isn't something good about any code. Even in procedural languages like C a 400+ line function is a nightmare.

What does the Linq code do? Is it an analogue of JDBC?
 
Marcus Biel
Ranch Hand
Posts: 54
IntelliJ IDE Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you misunderstood me. Such a long method indeed is a nightmare - but it is perfect to demonstrate how to refactor it into nicely readable, object oriented code.
 
Campbell Ritchie
Marshal
Posts: 63795
209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Marcus Biel wrote:I think you misunderstood me. . . .

Yes, I did misunderstand you. Sorry.
 
Marshal
Posts: 6634
443
BSD Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@OP

What is missing in that video, that tests don't play any role in the refactoring process. You might wrote them and demonstrated how much confidence they add to refactoring?
 
Liutauras Vilda
Marshal
Posts: 6634
443
BSD Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was solving sudoku about 4 years ago, but I'm afraid I too got very convoluted code, which I didn't refactor yet. Luckily I've got tests written back in the time.
 
Marcus Biel
Ranch Hand
Posts: 54
IntelliJ IDE Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Liutauras Vilda wrote:
What is missing in that video, that tests don't play any role in the refactoring process. You might wrote them and demonstrated how much confidence they add to refactoring?



Yes, I am planning to show/use tests... but, that is not really helping me at this point. First, I need a basis to start the refactoring from. I still think Sudoku could be a good use case - but
maybe the given C# code is too far away from Java, to hard to port. So now I am thinking about developing my own nasty procedural version of Sudoku.

 
And inside of my fortune cookie was this tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!