• Ever wanted an RSS feed of all your favorite gaming news sites? Go check out our new Gaming Headlines feed! Read more about it here.
  • We have made minor adjustments to how the search bar works on ResetEra. You can read about the changes here.

PorcoLighto

Member
Oct 25, 2017
765
Starting a new job in a month and I'll be working on a Python web backend that uses Flask. My current experience (first job) since 1,5 years is with C# and ASP.NET MVC. Any ideas of how much different it will be and how much time I should spend getting up to speed before starting?
It has been years since I last used ASP.NET MVC but in general, it is more complicated to work with it than Python based frameworks. I am currently using Django, which is a more complicated framework than Flask, and it took me less than a week to get going with it. You have a month, it is more than enough to get comfortable with it I would say.
 

Subutai

Metal Face DOOM
Member
Oct 25, 2017
937
Python 3 is absolutely the best place to start. There's no value to trying to learn logic first, as it is way easier to learn logic from doing programming rather than the other way round.

A lot of learning resources for Python are aimed at people who have already programmed in something else. The two main ones for absolute beginners are the Crash Course and the Hard Way.
Of these, the Hard Way is aimed at people who have no idea what a computer can do and starts out with the very basics like typing repetitive stuff in - it's kind of like teaching writing by telling you what shape the letters are. My guess is that, since you're posting on a gaming forum, this would be far too simplistic a start for you, so you're probably better off starting with the Crash Course. If you find that too difficult, then take a step back and do it the Hard Way. (There is one called Python 3 for Absolute Beginners, but it doesn't get into the nitty-gritty very quickly, and there's probably a "for Dummies" book somewhere, which is may be OK if you can stand the style).

(There are lots of online things that claim to be suitable for absolute beginners, but I've had a quick poke around and really, there's none that I can see that will get you over that first difficult hump of learning basic programming to start with.)

Different books suggest different software for starting with: the Hard Way pushes using a basic text editor, while the Crash Course pushed something called PyCharm. Ignore both of these, as they just add extra complication when you're starting. When you install Python, it comes bundled with it's own editor/environment thing called IDLE, and that is perfectly fine to use. You don't need to install anything else at all. So just install Python, click on IDLE and you are good to go.

Whatever book you use, type in and experiment with all the examples that the book goes through (Hard Way forces this, Crash Course doesn't but it is a good idea anyway). That's because learning programming is a bit like learning music, you need the practice as well as the theory.

If you can, find someone else to learn with - a friend, sibling, parent, whatever. Even if it's only for the first month or so, this is super helpful. You are bound to get stuck on something trivial early on, but it isn't likely you will both get stuck on the same thing, so you can help each other out. It's possible to find help on the internet of course, but people on the internet can't always pitch their answers a way that you'll understand as a raw beginner. (If you do get stuck, though, this thread is as good a place as any to ask, since we know you and understand where you are coming from!).

Good luck! Go for it and let us know how you get on.

(One more thing. Save a copy of whatever programs you write while you are learning. It is super helpful on the odd occasion when you are finding things hard to look back at some of your previous stuff and realise how much you learned already.)

I really appreciate the long detailed post! Thank you.

From messing around with other things and checking out other tutorials a while ago, I have Anaconda installed and I've messed with Visual Studio Code for a bit, would those still be alright to keep using? I think I'm somewhat comfortable with them but if there's a better way to go I would rather do that.
 

phisheep

Quis Custodiet Ipsos Custodes
Member
Oct 26, 2017
4,762
I really appreciate the long detailed post! Thank you.

From messing around with other things and checking out other tutorials a while ago, I have Anaconda installed and I've messed with Visual Studio Code for a bit, would those still be alright to keep using? I think I'm somewhat comfortable with them but if there's a better way to go I would rather do that.

Definitely stick with what you have got!

After starting out with Python out of the box I fiddled around for *ages* with different IDEs/environments before settling down with PyCharm and Anaconda, but the actual difference between any of these things is marginal and down to personal preference, and the personal preference is entirely geared by what you are familiar with. The only actual reason for using one rather than another is if you have a job that requires you to - since you don't, stick with what you have got and don't (like I did) clutter up your machine with a load of half-chewed things!

Let us know how you get on. It'll be interesting to see how this all looks to a raw beginner (which for me was in 1978 and is kind of hard to remember!). If you want any more long detailed posts about stuff, happy to oblige.
 

Skade

Member
Oct 28, 2017
8,862
I've never posted here but i need to vent so, sorry in advance :

Sitecore is a huge steaming pile of shit that should never have existed. It's unstable, overly complicated for no reason, crash all the time, it's a piece of shit.

I don't understand how so many big projects are being made on this. It doesn't make any sense. Even wordpress would be better. Hell ! Even Joomla is better !
 

ArnoldJRimmer

Banned
Aug 22, 2018
1,322
Agh don't get me started with wordpress. I've had to brush up on it lately. It's relatively easy for me to land small to medium sized Angular/Vue/Node etc front end or backend projects, but I like to supplement my income with smaller projects that might only take a few hours of work, and the vast majority of such small projects are on wordpress sites. Bloated, slow, incredibly brittle wordpress sites. Blegh.
 

Morzak

Member
Oct 27, 2017
319
Man sometimes I don't understand why certain decisions where taken from Framework creators.
Currently using nightwatch.js to automate E2E / UI and why they decided that POM selectores should be accessed by a String and not directly as constant I don't know, but that whole thing kill autocompletion, which is just stupid. Outside of that I actually like it well enough, even if i now use another library on top to use cucumber as the testrunner.
 

Skade

Member
Oct 28, 2017
8,862
Agh don't get me started with wordpress. I've had to brush up on it lately. It's relatively easy for me to land small to medium sized Angular/Vue/Node etc front end or backend projects, but I like to supplement my income with smaller projects that might only take a few hours of work, and the vast majority of such small projects are on wordpress sites. Bloated, slow, incredibly brittle wordpress sites. Blegh.

Well, i know Wordpress is bad. But Sitecore... God damn...

AEM feels like paradise compared to this shit... Never thought i'd say that but i think i want to go back to an AEM project.
 

Deleted member 51957

User requested account closure
Banned
Jan 14, 2019
810
Hello, does anyone have a great reference sheet for Spring & SpringBoot? I am at this odd juncture where I use spring-boot-starter for many of my projects in order to quickly leverage external APIs, set up my own RestController, use jdbcTemplates, source on-the-fly env configs, etc etc etc.

At this point, I just look at springboot as a collection of useful libraries, but I would really like to understand it at a more functional level i.e. the meaning of spring beans/components, autowiring dependencies, the 'Environment' and context, all that stuff I read about but don't really know what it means. I tried perusing the official docs but they went over my head a bit.

I guess I'm looking for a beginner's guide to Spring from the perspective of someone who already understands Java fairly well.
 

Vanillalite

Banned
Oct 25, 2017
7,709
Is there a way in Visual Studio if you set text mode to date to set the default value to today's date on page load?

I thought it would be

C#:
txtBox.Text = Convert.ToString(DateTime.Now);

but fuck if that works for me.
 

Zoe

Member
Oct 25, 2017
14,262
I always use DateTime.Now.ToShortDateString()

But it's hard to help without knowing what's actually happening.
 

laminated

Member
Oct 28, 2017
1,283
Web development is so foreign to me that it has taken me many hours to commit the django workflow to memory. After several hours repeating the Django tutorial presented in Python Crash Course, I can now start a project from scratch, create a webapp that reads from and writes to a sqlite database, and displays forms for users to add data to the database. And for each step I can explain in detail why I'm calling each method, and what each method does. Feeling pretty good about these baby steps.
 

Zevenberge

Member
Oct 27, 2017
570
It's always encouraging to see status code 500s in the wild. Especially when they state "Please contact the server administrator at root@localhost".
 

Zevenberge

Member
Oct 27, 2017
570

MotiD

Member
Oct 26, 2017
1,560
What's a good Java IDE for Windows and MacOS (doesn't have to be the same one)? I know about Visual Studio and Xcode, wondering if there's any good alternative
 

MotiD

Member
Oct 26, 2017
1,560
i like idea's intellij IDE community edition. great built in refactoring tools.
Started using it and it seems quite good! Thanks.
I'm trying to prepare for a Java course I'm about to begin in a few weeks. I've been using this and the video tutorial on Cave of Programming.
Getting user input in Java seems weirdly complicated for some reason
 

Jokab

Banned
Oct 28, 2017
875
Started using it and it seems quite good! Thanks.
I'm trying to prepare for a Java course I'm about to begin in a few weeks. I've been using this and the video tutorial on Cave of Programming.
Getting user input in Java seems weirdly complicated for some reason
It's one of the biggest reasons for why people dislike Java: many things in Java is so damn complicated when other languages have implemented a much simpler way of doing it.
 

EJS

The Fallen
The Fallen
Oct 31, 2017
9,190
Started using it and it seems quite good! Thanks.
I'm trying to prepare for a Java course I'm about to begin in a few weeks. I've been using this and the video tutorial on Cave of Programming.
Getting user input in Java seems weirdly complicated for some reason
Yeah, it is annoying to get user input in Java. It is not intuitive to use a Scanner. Unless you scope documentation, it is not intuitive.
 

shnurgleton

Member
Oct 27, 2017
15,864
Boston
Any Typescript devs in here? Been using it for the last few months in conjunction with node and I really love it

Also I've been trying to learn Rust during downtime at work. Anybody have good learning resources or fun repos to contribute to? Also, what is a good environment to use for rust dev? I've got a debugger set up in VS Code which is pretty nice for now
 

ArnoldJRimmer

Banned
Aug 22, 2018
1,322
I heart typescript. If I'm in a project or environment I can use it over vanilla js I will. Tooling around it for node angular and react is great.
 

Deleted member 21186

User requested account closure
Banned
Oct 28, 2017
55
Hello Programming ERA!

I have a WPF application which uses a FileSystemWatcher to check when a file has been changed.

I am trying to get back to the UI thread from the thread used in the filesystemwatcher. The problem is that BeginInvoke() not calling my UpdateGraph function at all, it is just skipping over it. I will post my code below. Any help would be appreciated!

Code:
        private void fileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
        {
            var d = System.Windows.Application.Current.Dispatcher;

            if(d.CheckAccess())
            {
                UpdateGraph();
            }
            else
            {
                d.BeginInvoke((System.Action)UpdateGraph);
            }
        }

        public void UpdateGraph()
        {
            FeedNextRecord(true, true);
        }

Edit: So it looks like my UI thread is being blocked by something as my application is freezing.
 
Last edited:

MotiD

Member
Oct 26, 2017
1,560
It's one of the biggest reasons for why people dislike Java: many things in Java is so damn complicated when other languages have implemented a much simpler way of doing it.
Yeah, it is annoying to get user input in Java. It is not intuitive to use a Scanner. Unless you scope documentation, it is not intuitive.
Alright, as someone who is learning Java and is kind of new to OOP, what are the conventions when it comes to main? Should I use it strictly for object creation and method calling?
As far as classes go, should I try to keep them clean as well? For example, if I want to ask for simple user input (choose a row and column for a 2d array, for example) assuming there are no conditions and the input is going to be 100% correct, is it reasonable to ask for the input inside the class with no use of a method? If the input requires checking for conditions for example, I'm assuming you'd want one method that asks for the user input as well check for conditions and so on
 

EJS

The Fallen
The Fallen
Oct 31, 2017
9,190
Alright, as someone who is learning Java and is kind of new to OOP, what are the conventions when it comes to main? Should I use it strictly for object creation and method calling?
As far as classes go, should I try to keep them clean as well? For example, if I want to ask for simple user input (choose a row and column for a 2d array, for example) assuming there are no conditions and the input is going to be 100% correct, is it reasonable to ask for the input inside the class with no use of a method? If the input requires checking for conditions for example, I'm assuming you'd want one method that asks for the user input as well check for conditions and so on
So, your main should be a point of entry and that's really it. It should be as lean as possible. There are exceptions but the best practice is to make the main function just a starting point.

Methods should do one thing and one thing only. If you find yourself doing more than one thing - getting user input, iterating through a collection, you should break it into its own function. It makes your code much more readable and digestible.

In your example, if I am assuming correctly, you just want to ask for user input to navigate to an array? Yeah, you could do that in main and that's probably fine for this example but I would probably make an ArrayHelper class that does this functionality and then instantiate the class in your main and call your method. You could declare an array variable in your main.

I could be misunderstanding your question.

I would recommend the book Clean Code. It's pretty great for code structure and practices and I believe, from what I remember, the code examples are in Java.
 

MotiD

Member
Oct 26, 2017
1,560
So, your main should be a point of entry and that's really it. It should be as lean as possible. There are exceptions but the best practice is to make the main function just a starting point.

Methods should do one thing and one thing only. If you find yourself doing more than one thing - getting user input, iterating through a collection, you should break it into its own function. It makes your code much more readable and digestible.

In your example, if I am assuming correctly, you just want to ask for user input to navigate to an array? Yeah, you could do that in main and that's probably fine for this example but I would probably make an ArrayHelper class that does this functionality and then instantiate the class in your main and call your method. You could declare an array variable in your main.

I could be misunderstanding your question.

I would recommend the book Clean Code. It's pretty great for code structure and practices and I believe, from what I remember, the code examples are in Java.
Thank you.
As far as my question goes, I am actually starting a Java course in 2 weeks and want to solve exercises from previous semesters. I generalized the questions but my goal is to create a program with a 8x8 array (chess board) and receive coordinates for a Knight's position on the board, and print all the possible coordinates to which the Knight can move to when performing a single move.

I will look into the book you recommended. I feel like this is a pretty important topic and after having a bad experience with C, and feeling like I had a lot of bad habits writing in C, it feels like starting over in Java and developing good habits is more important than rushing to write the code right now.
 

EJS

The Fallen
The Fallen
Oct 31, 2017
9,190
Thank you.
As far as my question goes, I am actually starting a Java course in 2 weeks and want to solve exercises from previous semesters. I generalized the questions but my goal is to create a program with a 8x8 array (chess board) and receive coordinates for a Knight's position on the board, and print all the possible coordinates to which the Knight can move to when performing a single move.

I will look into the book you recommended. I feel like this is a pretty important topic and after having a bad experience with C, and feeling like I had a lot of bad habits writing in C, it feels like starting over in Java and developing good habits is more important than rushing to write the code right now.
I don't know chess much but it sounds like you're going to be constantly asking for user input? Seems pretty complex; are you training the computer to play chess or are you just playing yourself?

But yeah, most developers go right to coding. It's not ideal lol. How far along are you in OOP? Have you done Data Structures besides arrays? Do you know what your course will teach you?
 

MotiD

Member
Oct 26, 2017
1,560
I don't know chess much but it sounds like you're going to be constantly asking for user input? Seems pretty complex; are you training the computer to play chess or are you just playing yourself?

But yeah, most developers go right to coding. It's not ideal lol. How far along are you in OOP? Have you done Data Structures besides arrays? Do you know what your course will teach you?
I might have made this sound more complicated than it actually is.
The user inputs a row and column number as the Knight's position, and the program needs to print all the possible landing coordinates (8 being the highest possible outcome, according to the exercise) for the Knight when performing a single move, which in the Knight's case is moving two squares horizontally and one square vertically, or the other way around.
After printing, the program ends.

For example, if the user inputs 5(r), 7(c)
The program should print

3 8
3 6
4 5
6 5
7 6
7 8

and does nothing more

I'm sure when I actually sit down to write it, it won't be as easy as I'm imagining, but the toughest part I can think of right now is not going outside the boundaries of the array when checking for possible outcomes

As for how far I'm in OOP, I'm mostly using this video tutorial for now from caveofprogramming and I've reached 'String Builder and String Formatting', but since this is only the second exercise I'm pretty sure it should be doable, unless I'm oversimplifying this in my mind
The description for the course (It was written in Hebrew but Google Translate did a pretty good job with a few corrections):

Topics of the course
Part a

  • Introduction and basics of Java language
  • Object Oriented Programming: Using given classes and writing classes
  • Flow control (conditional sentences and loops)
  • Arrays
Part II

  • OOP expansion - inheritance, variables and static methods, overloading, packages, polymorphism and interfaces
  • Complexity of algorithms, algorithms for sorting and searching
  • Recursion
  • Linked lists
  • Stacks and queues, trees and binary trees
  • Computability in a nutshell

The course is roughly 3 months long and this seems pretty extensive, so I've decided to start early
 
Last edited:

phisheep

Quis Custodiet Ipsos Custodes
Member
Oct 26, 2017
4,762
I'm sure when I actually sit down to write it, it won't be as easy as I'm imagining, but the toughest part I can think of right now is not going outside the boundaries of the array when checking for possible outcomes

Give a bit of thought to how you represent the board (or google "chess board representations" if you want to explode your brain with how many different ways there are!).

One simple way - dating back to the 1960s I think - is to store the board as 12x12 rather than 8x8, and put some recognizable value meaning "you can't go here" in the two outside borders. Then you can just calculate your moves all the same way and just not report the ones that land on squares that are out of bounds. Of course, you'll have to translate the input and output a bit, bit that's easier than checking boundaries all the time.
 

EJS

The Fallen
The Fallen
Oct 31, 2017
9,190
I might have made this sound more complicated than it actually is.
The user inputs a row and column number as the Knight's position, and the program needs to print all the possible landing coordinates (8 being the highest possible outcome, according to the exercise) for the Knight when performing a single move, which in the Knight's case is moving two squares horizontally and one square vertically, or the other way around.
After printing, the program ends.

For example, if the user inputs 5(r), 7(c)
The program should print

3 8
3 6
4 5
6 5
7 6
7 8

and does nothing more

I'm sure when I actually sit down to write it, it won't be as easy as I'm imagining, but the toughest part I can think of right now is not going outside the boundaries of the array when checking for possible outcomes

As for how far I'm in OOP, I'm mostly using this video tutorial for now from caveofprogramming and I've reached 'String Builder and String Formatting', but since this is only the second exercise I'm pretty sure it should be doable, unless I'm oversimplifying this in my mind
The description for the course (It was written in Hebrew but Google Translate did a pretty good job with a few corrections):

Topics of the course
Part a

  • Introduction and basics of Java language
  • Object Oriented Programming: Using given classes and writing classes
  • Flow control (conditional sentences and loops)
  • Arrays
Part II

  • OOP expansion - inheritance, variables and static methods, overloading, packages, polymorphism and interfaces
  • Complexity of algorithms, algorithms for sorting and searching
  • Recursion
  • Linked lists
  • Stacks and queues, trees and binary trees
  • Computability in a nutshell

The course is roughly 3 months long and this seems pretty extensive, so I've decided to start early
I think you'll be good for the first part, you seem ahead of the curve already. Part 2 can be tough but just grind it out - it gets easier once you use those concepts regularly.

Hint: for most Data Structures (Lists, Maps, Stacks, Queues, etc), there are built in libraries but you're going to have to implement your own for these courses. It's tedious and difficult at times but it helps you understand what they actually do.

You'll be fine. When I took my first class, I had to stay after class to get the computer to print a String.
 

MotiD

Member
Oct 26, 2017
1,560
Give a bit of thought to how you represent the board (or google "chess board representations" if you want to explode your brain with how many different ways there are!).

One simple way - dating back to the 1960s I think - is to store the board as 12x12 rather than 8x8, and put some recognizable value meaning "you can't go here" in the two outside borders. Then you can just calculate your moves all the same way and just not report the ones that land on squares that are out of bounds. Of course, you'll have to translate the input and output a bit, bit that's easier than checking boundaries all the time.

This is the sort of stuff that makes you think 'I wonder if I could ever come up with this idea on my own'
Thanks for the tip
I think you'll be good for the first part, you seem ahead of the curve already. Part 2 can be tough but just grind it out - it gets easier once you use those concepts regularly.

Hint: for most Data Structures (Lists, Maps, Stacks, Queues, etc), there are built in libraries but you're going to have to implement your own for these courses. It's tedious and difficult at times but it helps you understand what they actually do.

You'll be fine. When I took my first class, I had to stay after class to get the computer to print a String.

Yeah, I'm pretty confident about the first part. It's the second part that made me realize it's a good idea to start now.
From my time with C, I'm sure most exercises will consist of writing your own code for solutions that are already implemented into Java.

You'll be fine. When I took my first class, I had to stay after class to get the computer to print a String.

Hard work and determination do pay off :)
 

EJS

The Fallen
The Fallen
Oct 31, 2017
9,190
This is the sort of stuff that makes you think 'I wonder if I could ever come up with this idea on my own'
Thanks for the tip


Yeah, I'm pretty confident about the first part. It's the second part that made me realize it's a good idea to start now.
From my time with C, I'm sure most exercises will consist of writing your own code for solutions that are already implemented into Java.



Hard work and determination do pay off :)
It's a grind. I am not even a great programmer. I am not a very smart person in general, so I have to work really hard at times.
 

rock

Banned
Oct 29, 2017
128
My team has hired some new programmers who come from a more functional style of programming, or at the least are super enthusiastic about it. My team is an OOP shop and a lot of our stack is C#.

They're really pushing arrow functions without curly braces for all of the functions we are writing. one of the new guys is saying this is the new preferred style and i don't buy it. They're also removing variables (which means data is unnamed and imo harder to understand) and inlining lots of function calls, and nesting function calls. it looks gross to me in C#. it might make more sense in Clojure or something, idk.

Is anyone else seeing this style "take off" in the C# field? It's really annoying me because I admittedly don't keep up with modern C# styles and don't want to just tell them this style is bad.
 
Oct 25, 2017
3,789
My team has hired some new programmers who come from a more functional style of programming, or at the least are super enthusiastic about it. My team is an OOP shop and a lot of our stack is C#.

They're really pushing arrow functions without curly braces for all of the functions we are writing. one of the new guys is saying this is the new preferred style and i don't buy it. They're also removing variables (which means data is unnamed and imo harder to understand) and inlining lots of function calls, and nesting function calls. it looks gross to me in C#. it might make more sense in Clojure or something, idk.

Is anyone else seeing this style "take off" in the C# field? It's really annoying me because I admittedly don't keep up with modern C# styles and don't want to just tell them this style is bad.

It's not bad style, certainly we did a lot of this at my C# job. C# (especially modern C#) has a lot of syntax that borrows from functional languages so it's not strange to utilize it. Some benefits:

- You remove a lot of shared state bugs, an arrow function with no curly almost always means that the function produces no side-effects.
- Code is easier to test if it doesn't rely on shared state changes.
- Code can be written at a higher level, if you are a heavy c# dev you probably don't write loops and use LINQ for most things, this is functional style.
- You don't need to label intermediate date because it's usually unimportant, all that really matters is the transformation.
- It's easier to understand expressions that consistently return values and aren't doing other things (ternary vs if)

I suspect as you use it more you'll get more comfortable but it takes some getting used to. Just wait until they start introducing Option and Result types to the code (I'm a huge fan of doing this but I've gotten a lot of push back). Of course you can always suggest writing it in F#. It is possible to go too far wedging a square peg in a round hole but C# is fairly flexible, unlike say, Java. I'd try to get get your own comfort up (maybe pick up a functional language) and then you'll be more able to understand tasteful tradeoffs.
 

rock

Banned
Oct 29, 2017
128
It's not bad style, certainly we did a lot of this at my C# job. C# (especially modern C#) has a lot of syntax that borrows from functional languages so it's not strange to utilize it. Some benefits:

- You remove a lot of shared state bugs, an arrow function with no curly almost always means that the function produces no side-effects.
- Code is easier to test if it doesn't rely on shared state changes.
- Code can be written at a higher level, if you are a heavy c# dev you probably don't write loops and use LINQ for most things, this is functional style.
- You don't need to label intermediate date because it's usually unimportant, all that really matters is the transformation.
- It's easier to understand expressions that consistently return values and aren't doing other things (ternary vs if)

I suspect as you use it more you'll get more comfortable but it takes some getting used to. Just wait until they start introducing Option and Result types to the code (I'm a huge fan of doing this but I've gotten a lot of push back). Of course you can always suggest writing it in F#. It is possible to go too far wedging a square peg in a round hole but C# is fairly flexible, unlike say, Java. I'd try to get get your own comfort up (maybe pick up a functional language) and then you'll be more able to understand tasteful tradeoffs.

Yea, i'm trying to get more comfortable. sometimes i think they're breaking SOLID, particularly single responsibility principle, and that bugs me a bit too. they're refactoring out classes that added structure because they don't like having many files.
 

Zoe

Member
Oct 25, 2017
14,262
Whatever y'all do, sounds like your style guidelines need to either be updated or enforced fast cause things are gonna get messy if you're not all on the same page.
 

MotiD

Member
Oct 26, 2017
1,560
It's a grind. I am not even a great programmer. I am not a very smart person in general, so I have to work really hard at times.
I feel ya.
I didn't even graduate scool properly and never dealt with math proper until 2017.
I finished a pre-college program for people who never gradugated school but screwed up during college and had to leave and now I'm trying my luck again, and hopefully be smarter about it this time.
If I don't finish this course succssfully I'l probably have to drop the B.s in computer science and have to pursue something else because I'm already 27 and I'm not getting any younger.

Also, I just realized I can't use System.out.println in a class outside of a method after screwing around with Intellij and reinstalling it and then switch to Eclipse lol
 

CrankyJay

Banned
Oct 25, 2017
11,318
My team has hired some new programmers who come from a more functional style of programming, or at the least are super enthusiastic about it. My team is an OOP shop and a lot of our stack is C#.

They're really pushing arrow functions without curly braces for all of the functions we are writing. one of the new guys is saying this is the new preferred style and i don't buy it. They're also removing variables (which means data is unnamed and imo harder to understand) and inlining lots of function calls, and nesting function calls. it looks gross to me in C#. it might make more sense in Clojure or something, idk.

Is anyone else seeing this style "take off" in the C# field? It's really annoying me because I admittedly don't keep up with modern C# styles and don't want to just tell them this style is bad.

No way, all that does it make the code a nightmare to debug.

I hate SLOC-jockies.
 

MotiD

Member
Oct 26, 2017
1,560
Alright, finished my first ever Java (and OOP) program and I would like to get some feedback/tips and tricks on what I could do better (sorry if this is boring for more experienced programmers)
The goal is to get user input for a Knight's position on a chess board (8x8) and print all the possible coordinates he can move to (a Knight can move 2 squares horizontally and 1 vertically or vice versa)

This is an exercise from a previous semester of a Java course I'm about to begin in 10 days and I originally thought this was all about using arrays, but after reading it again I realized there's no mention of them and looking at the attached solution, it seems this was from very early on when they only had basic knowledge about variables/methods/conditional statements and creating an object.

I ended up not using an array and instead kept the logic relatively simple but worked with other concepts that are new to me.
Looking at all the if statements now, I should have probably used a method to handle all of that instead.

Main:

Java:
import java.util.Scanner;

public class Application {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Type the intial values for the Knight's position");
        int row = input.nextInt();
        int column = input.nextInt();
        if ((row < 1 || row > 8) || (column < 1 || column > 8)) {
            System.out.println("The values must be between 1 and 8");
            System.exit(0);
        }
        input.close();
        Knight board1 = new Knight();
        board1.setCoordinates(row, column);
        board1.horizontalPlus();
        board1.horizontalMinus();
        board1.verticalPlus();
        board1.verticalMinus();
    }
}

Knight class:

Java:
//import java.util.Scanner;

public class Knight {
    private int cordx;
    private int cordy;

    public void setCoordinates(int cordx, int cordy) {
        this.cordx = cordx;
        this.cordy = cordy;
    }

    public void horizontalPlus() {
        if (cordx + 2 <= 8 && cordy + 1 <= 8) {
            printCoordinates(cordx + 2, cordy + 1);
        }
        if (cordx + 2 <= 8 && cordy - 1 >= 1) {
            printCoordinates(cordx + 2, cordy - 1);
        }
    }

    public void horizontalMinus() {
        if (cordx - 2 >= 1 && cordy + 1 <= 8) {
            printCoordinates(cordx - 2, cordy + 1);
        }
        if (cordx - 2 >= 1 && cordy - 1 <= 8) {
            printCoordinates(cordx - 2, cordy - 1);
        }
    }

    public void verticalPlus() {
        if (cordx + 1 <= 8 && cordy + 2 <= 8) {
            printCoordinates(cordx + 1, cordy + 2);
        }
        if (cordx - 1 >= 1 && cordy + 2 <= 8) {
            printCoordinates(cordx - 1, cordy + 2);
        }
    }

    public void verticalMinus() {
        if(cordx + 1 <= 8 && cordy - 2 >= 1)
        {
            printCoordinates(cordx + 1, cordy - 2);

        }
        if(cordx - 1 >= 1 && cordy - 2 >= 1)
        {
            printCoordinates(cordx - 1, cordy - 2);

        }
    }

    public void printCoordinates(int cordx, int cordy) {
        System.out.println(cordx + " " + cordy);
    }
}
 

ArnoldJRimmer

Banned
Aug 22, 2018
1,322
Looks good! Some suggestions:

I would separate my input validation logic into a separste function or class. Then pass the input to it.

I would only expose a single public method from knight "getValidMoves()" or the like and keep the rest of the logic internal to the class.

As the porgram becomes more complex:

I would make sure to avoid magic numbers or strings. Whenever you fi d yourself checking values against constants like 8 or 2 you should consider making them consta ts in the class. This way they are easier to change in the future if changes to requirements happen.

Maybe use an observable for input so the program can keep going.

Good work though!
 

sleepnaught

Banned
Oct 26, 2017
4,538
Sorry, I know this has been asked a thousand times, but....

Is there a really good(but cheap) online course or book for Python(Should I really learn Python first?)? I'm considering changing my career and giving serious thought to programming. Something with a lot of "follow along tutorials" that builds a program from scratch, if that makes any sense.