• Introducing Image Options for ResetEra 2.0! Check the left side navigation bar to show or hide images, avatars, covers, and embedded media. More details at the link.

Programming |OT| Functional, Imperative, OOP, Cargo-Cult,... all are welcome!

Oct 25, 2017
661
#1
Discord
Quote the post linked here to reveal the link to the Discord.

What is programming?
Computer programming (often shortened to programming) is a process that leads from an original formulation of a computing problem to executable computer programs. Programming involves activities such as analysis, developing understanding, generating algorithms, verification of requirements of algorithms including their correctness and resources consumption, and implementation (commonly referred to as coding) of algorithms in a target programming language.
From Wikipedia.

Basically:

Write instructions for a computer. Computer then follows those instructions
Where do I start?
Here is a good place! Feel free to ask any questions, and we will gladly give advice.

It honestly depends what you are interested in, and what you intend to use the programming for. Programming as a skill is essentially the ability to use a wide range of tools adepts at completely different tasks - the skills are transferable, but the trains of thought can sometimes be completely different.

Python is great language to start with, and what I personally learnt first.

What is a 'Programming Paradigm'
Thanks to the work of Turing, Church and others in the early 1900s, it was discovered that loads of different semantics (ways of doing things) for expressing algorithms ultimately could be used to express exactly the same set of computable programs - what we know call Turing completeness.

However, these different semantics have different tradeoffs in terms of how easy it is to express what you want, how is it is to maintain the code that you have written, and how fast that code runs on your actual machine. All depending on context as well.

Essentially, different paradigms are different styles of programming, which are better suited to different tasks (and also different people). A programming language will typically support one or more of these paradigms. The lines between them can get quite blurred as well.

To give you a better idea of what they are, here are some example paradigms:

Imperative
One of the easiest to understand. Literally a sequence of instructions which do things. Most languages support this in some form - the most well known being C.

OOP (Object Oriented Programming)
Maintaining code written in imperative languages can be hard. So the idea behind OOP languages is to provide the ability to represent programming data structures using something known as 'encapsulation' - the ability to hide the inner workings of something in order to expose a clean interface that can be used very easily. This, in theory, makes maintaining the code easier, as you can change the implementation of certain parts of your code base, without affecting other parts of your code base.

Functional Programming
The idea behind functional languages is that functions are pure, that is, they cannot have any side-effects. Therefore, when you use a function, it doesn't have any effect except the computation it performs to calculate the value it returns - a function in a functional program won't suddenly start doing things you don't expect!

While this makes performance potentially worse than in imperative programs, and can be quite labourus to write, functional languages can also be very easy to read and made to run in parallel across many-core processors.

TODO: add more examples and better explanations to this list!

What languages are there? What are they good for? How do I learn them?
C
C is one of the oldest but most widely used languages out there. It's incredibly powerful and blindingly fast. Unfortunately, it can also be unwieldy, due to both being incredibly low-level, and having design that's decades old.

The Linux Kernel is written in C.

C++
C++ is essentially C, but with loads of 'modern' (it started development in 1979) language features. It was originally designed to be compatible with C, but no longer strictly is.

Unfortunately, it suffers from a lot of the same problems that C does, design with, with a fair few problems of its own. But it's low level expressiveness, the power it provides, alongside the weird and wonderful/horrible template metaprogramming paradigm have made it the systems and applications programming language of choice for many people.

Oh, and most game engines are written in C++.

JavaScript
Originally written in 10 days as a 'glue' language that would be used to connect 'serious' languages (like Java, and Flash) together, JavaScript has since become the back-bone of a lot of the internet (in NodeJS), and the front-bone of even more!

It's an incredibly rapidly evolving language - to such an extend the 'new' stuff you could be learning in one year could be out of date the next!

Java/C#
These two languages have been lumped together as they are very similar. They are both Object Oriented languages that have been designed to be similar to C++ is an appearance. They steal some ideas from C++, but due to garbage collection, are much easier to use.

However, this also makes them slower.

Haskell
Haskell is the functional language that Computer Scientists like to rave about. It takes the functional programming paradigm and owns it.

PHP
This is a language that powers a lot of the web (including ResetEra!). It isn't going away anytime soon, but it has fallen by the wayside in favour of languages such as JavaScript.

Python
A really cool language that can do pretty much everything you can think of, and quickly. A really good language for machine learning and writing quick scripts - it's a great place to start learning.

Rust
Rust is a low level language like C, but designed to not have a lot of the problems C in terms of legacy design and lack of safety. The primary goal of Rust is to be safe, by making sure the programmer doesn't have raw access to memory.

Swift
Apple had a go at making a language for people to use when writing for their machines after they got bored of Objective-C. This is what they came up with.

Development Environments (IDE)
An IDE (Short for "Integrated Development Environment") are tools that can be used to help you program. Beyond providing the basic text-editing features you need to edit source code, they can provide other tools to help you auto-complete, debug, inspect and otherwise play around with your code in manners which (ideally) improve your productivity.

Visual Studio
Use this to program in .NET, C, C++, F#, and so on. A powerful IDE, that can get a bit overwhelming at times. Let us take a moment to mourn the loss of project.json †

Rider
A newcomer in the .NET sphere. Haven't tried this yet, but it's made by Jetbrains, who's other IDE IntelliJ IDEA, is one of the best Java IDE's. If anyone has tried it or is using it, be sure to post about it!

Visual Studio Code, Atom
These are 'IDEs' that are based on extension. Starts out as a text editor with highlighting and some basic development features, but can be extended with plugins that enable you to program for all your favorite languages.

Sublime Text
Along the lines of VS Code and Atom, but even more basic. Don't think you can debug in here, but I just wanted to add it because it's just so fast, snappy, and extensible, making it perfect for scripting.

Further Resources
This needs to be fleshed out, as I don't know what is good and what isn't!

Any recommendations would be really appreciated!

Improving this post
There is a GitHub Repo which contains this OP, please feel free to make any pull requests containing improvements to this!

Also feel free to create any issues for things you would like to see added to the OP!

Special Thanks
To:

  • phisheep for the Haskell and Python learning resources!

  • emesve for the IDE section!
Note
I will try to listen to any feedback to this OT, and add anything you feel is worthwhile! Especially with resources for learning programming languages, I really don't know what the best ones are!

CURRENTLY ACCEPTING THREAD TITLE SUGGESTIONS
 
Last edited:
OP
OP
Moosichu
Oct 25, 2017
661
#3
OP in progress, I posted it early as I wanted an OT for programming up ASAP so discussion can get started. Will add all the other language descriptions now!
 
Oct 25, 2017
52
#5
Good to see this here. Was considering starting it myself but was busy the past couple of days. Was going to suggest Software DevelopERA |OT|
 
OP
OP
Moosichu
Oct 25, 2017
661
#6
Good to see this here. Was considering starting it myself but was busy the past couple of days. Was going to suggest Software DevelopERA |OT|
Oooooh, that's good. I'm going to PM a mod about that. (Actually, I will hold off on that until more people have found this thread - as in order to make sure it didn't exist, I searched thread titles for "Programming". I have made an issue on the repository so I remember to request the change when more people have found this though!)

In other news, I have created a GitHub repository which contains this OP. Feel free to make pull requests with additions and improvements to it! I'm currently still writing it, so maybe hold off until it's a bit more stable. But I thought this would be a fun experiment to try.

CURRENTLY ACCEPTING THREAD TITLE SUGGESTIONS FOR THE FUTURE:

https://github.com/moosichu/resetera_programming_ot/issues/1
 
Last edited:
Oct 26, 2017
640
#9
Oooooh, that's good. I'm going to PM a mod about that. (Actually, I will hold off on that until more people have found this thread - as in order to make sure it didn't exist, I searched thread titles for "Programming". I have made an issue on the repository so I remember to request the change when more people have found this though!)
I'd stick with "Programming" really - like many other amateurs I probably wouldn't consider posting in a software developer thread - sounds a bit intimidating and professional.

(But being as I found it now I won't let that stop me if you do change it!)

So glad you made this, as I'm trying to track my son's progress through his college course, so accidentally picking up on Haskell as well as everything else.
 
Oct 25, 2017
610
#10
I'd stick with "Programming" really - like many other amateurs I probably wouldn't consider posting in a software developer thread - sounds a bit intimidating and professional.

(But being as I found it now I won't let that stop me if you do change it!)

So glad you made this, as I'm trying to track my son's progress through his college course, so accidentally picking up on Haskell as well as everything else.
I agree with sticking with programming. There's a lot of people doing programming that aren't software developers. I quite liked posting in the old thread, but I'm not a software developer. It's also definitely not the most welcoming of titles, and considering a large number of people posting in the old thread were beginners looking for advice, I feel like that makes it a rather poor choice.
 
OP
OP
Moosichu
Oct 25, 2017
661
#11
I'd stick with "Programming" really - like many other amateurs I probably wouldn't consider posting in a software developer thread - sounds a bit intimidating and professional.

(But being as I found it now I won't let that stop me if you do change it!)

So glad you made this, as I'm trying to track my son's progress through his college course, so accidentally picking up on Haskell as well as everything else.
I agree with sticking with programming. There's a lot of people doing programming that aren't software developers. I quite liked posting in the old thread, but I'm not a software developer. It's also definitely not the most welcoming of titles, and considering a large number of people posting in the old thread were beginners looking for advice, I feel like that makes it a rather poor choice.
Those are some really good points! The end game is to make the OP (and the associated Repo) an incredibly valuable resource for beginners, with this thread being an incredibly friendly place to get help regardless of skill level. I'm someone who found it incredibly hard to get over 'the wall' of understanding how to program, and I really enjoy helping people learn as well.

Unfortunately my course was learning ML, the lesser known, and not even entirely pure, fuctional programming language. I really want to try Haskell someday, I find monads really cool and doing an actual project in a functional language sounds really appealing!

Does anyone know of any good resources for the languages listed? Are there any other languages people feel that I should list as well? I only picked some out of the air that I'm most familiar with.
 
Last edited:
Oct 26, 2017
640
#12
Does anyone know of any good resources for the languages listed?
For Python I really recommend python-course.eu. It is very thorough, quite concise and covers a great deal of ground. I tried and discarded a lot of other things (I didn't get along with "The Hard Way" at all), in the end this course and the library reference were all I needed.

For Haskell, Learn You a Haskell for Great Good is a good place to start. It makes a bit of a meal of a few things which are better explained in textbooks, but it is available free online.
 
OP
OP
Moosichu
Oct 25, 2017
661
#13
For Python I really recommend python-course.eu. It is very thorough, quite concise and covers a great deal of ground. I tried and discarded a lot of other things (I didn't get along with "The Hard Way" at all), in the end this course and the library reference were all I needed.

For Haskell, Learn You a Haskell for Great Good is a good place to start. It makes a bit of a meal of a few things which are better explained in textbooks, but it is available free online.
Added to the OP :) Thank you!

I wasn't particularly keen on LPTHW, it's just the only one that I knew of.
 
Oct 25, 2017
610
#14
Does anyone know of any good resources for the languages listed? Are there any other languages people feel that I should list as well? I only picked some out of the air that I'm most familiar with.
If you want to list more languages, some choices would be:
  • PHP since it's still incredibly popular (though I wouldn't actually recommend anyone to use it, so maybe that's an argument for leaving it out).
  • A functional programming language. It's in the title and mentioned in the thread, but not in the language list. Haskell, List and Scheme would be the most well known choices, but maybe something that's easier to learn (like Racket) or something that's more modern and not completely functional (like Scala) would work.
  • Ruby, just for Ruby on Rails. It's not as hip as it used to be, but I feel like it's a great choice for learning web programming - it's easy to set up and you can get things running pretty quickly.
  • An assembler for a reduced instruction set computer (RISC) architecture. Mostly because it's a much easier start for learning assembly than trying x86 with its hundreds of opcodes a lot of specific registers. Something like MIPS maybe, although someone with more knowledge could chime in on this.
 
OP
OP
Moosichu
Oct 25, 2017
661
#15
If you want to list more languages, some choices would be:
  • PHP since it's still incredibly popular (though I wouldn't actually recommend anyone to use it, so maybe that's an argument for leaving it out).
  • A functional programming language. It's in the title and mentioned in the thread, but not in the language list. Haskell, List and Scheme would be the most well known choices, but maybe something that's easier to learn (like Racket) or something that's more modern and not completely functional (like Scala) would work.
  • Ruby, just for Ruby on Rails. It's not as hip as it used to be, but I feel like it's a great choice for learning web programming - it's easy to set up and you can get things running pretty quickly.
  • An assembler for a reduced instruction set computer (RISC) architecture. Mostly because it's a much easier start for learning assembly than trying x86 with its hundreds of opcodes a lot of specific registers. Something like MIPS maybe, although someone with more knowledge could chime in on this.
These are some good shouts. I wouldn't hate on PHP too much, because after-all, that is what this forum is written in ;) . I will update the OP with some of these tomorrow, currently have a lot to do tonight!

The assembly stuff is a really good idea though. I will have a think. OpenRISC is a really cool project as well, I will see if there are some good learning resources for that.
 
Oct 25, 2017
610
#16
I don't mean to hate on PHP too much either. I just that I think there is a wide variety of better choices for learning web development, so that could be an argument for leaving it off the language list, since it's presumably aimed at people getting into programming.
 
Oct 26, 2017
162
#17
If you want to list more languages, some choices would be:
  • PHP since it's still incredibly popular (though I wouldn't actually recommend anyone to use it, so maybe that's an argument for leaving it out).
  • A functional programming language. It's in the title and mentioned in the thread, but not in the language list. Haskell, List and Scheme would be the most well known choices, but maybe something that's easier to learn (like Racket) or something that's more modern and not completely functional (like Scala) would work.
  • Ruby, just for Ruby on Rails. It's not as hip as it used to be, but I feel like it's a great choice for learning web programming - it's easy to set up and you can get things running pretty quickly.
  • An assembler for a reduced instruction set computer (RISC) architecture. Mostly because it's a much easier start for learning assembly than trying x86 with its hundreds of opcodes a lot of specific registers. Something like MIPS maybe, although someone with more knowledge could chime in on this.
Getting someone to learn PHP in 2017 is just plain cruel! I would much rather like to see something like Go.

Also, I would suggest adding https://learnpythonthehardway.org to the resources.
 
Oct 25, 2017
610
#19
Getting someone to learn PHP in 2017 is just plain cruel! I would much rather like to see something like Go.

Also, I would suggest adding https://learnpythonthehardway.org to the resources.
Yeah, this is why I said it's a good argument for keeping it off the list.

As for LPTHW, I've never used it, but it seems to have lot of issues, like the completely irrational hatefor Python 3 and some weird decisions that make it hard to recommend imo. A lot of people who are way more knowledgable in Python than me seem to hate it.
 

Wollan

Mostly Positive
Member
Oct 25, 2017
2,912
Norway but living in France
#20
Great to see this thread.
I co-recommend two of the books mentioned in the OP in "Learn you a Haskell" (aka LYAH) as well as "Game Engine Architecture" by Jason Gregory, lead programmer at Naughty Dog (I believe edition 3 is coming summer 2018), should you be interested in those two fronts. If I was to ever recommend one book it would be "The Pragmatic Programmer".
 
Oct 25, 2017
52
#21
As for LPTHW, I've never used it, but it seems to have lot of issues, like the completely irrational hatefor Python 3 and some weird decisions that make it hard to recommend imo. A lot of people who are way more knowledgable in Python than me seem to hate it.
I am self-taught and LPTHW was the first learning resource I used (I think I picked it up almost 5 years ago to this day). I thought it was good until the OOP chapters (which is near the end of it). The author does a poor job of presenting it. In fairness, the only environment introduced in LPTHW is the terminal/CLI, and I think OOP is easier for beginners to grok when dealing with things that more intuitively map to real-ish objects, like buttons on a GUI.
 
Oct 25, 2017
1,768
Seattle
#22
node.js is the superior scripted web language these days. Consistent in what it wants to be, and let's you cross-pollinate. A lot easier to be a full-stack dev in node than PHP.
 
Oct 25, 2017
1,085
#24
I had my midterm today. Somehow got 100% on the quiz part (20% of the midterm grade) and feel good about the program part (80% of the midterm grade). Not going to get 100% on it because I’m so used to using if-else statements between C++ and Python that I haven’t really learned how to use switch statements but it should only have a small effect on my grade.
 
Oct 25, 2017
1,933
#26
Nice to see someone set it up. cpp_is_king (or at least I assumed given the username) messaged me at Slaent with well wishes for all those who were in the NeoGaf programming OT and that C++ is the best language. I don't know if it was cpp's intention to join ResetEra or not but if not you can find him over there.
 
Oct 25, 2017
4,903
#27
Can someone tell me why this no longer works for me? I used to have a bookmarklet that when I clicked it would open all unread threads in new tabs. This worked prior to iOS 11 and Safari 11 on my Mac. I tested it in Chrome and it also fails there. The problem is when I run it now, it just opens the first link and then stops. Did something happen to how javascript is handled so window.open no longer works in for loops?

Basically, what I want to do is click that in a bookmarklet and have all unread threads open. Everything seems to work, the array is the correct length, but that for loop where it opens the URLs just opens the first one and then stops.

Code:
javascript:
var SITE = location.host;
if(SITE=="www.resetera.com"){
    var arr = [], l = document.links;
    for(var i=0; i<l.length; i++) {
        if(l[i].href.indexOf("/unread") !== -1)
            arr.push(l[i].href);
    }
  
  
    for ( var i = 0; i < arr.length; i++) {
        window.open(arr[i]);
     }
  
}
 
Last edited:
Oct 25, 2017
1,513
#28
Can someone tell me why this no longer works for me? I used to have a bookmarklet that when I clicked it would open all unread threads in new tabs. This worked prior to iOS 11 and Safari 11 on my Mac. I tested it in Chrome and it also fails there. The problem is when I run it now, it just opens the first link and then stops. Did something happen to how javascript is handled so window.open no longer works in for loops?

Basically, what I want to do is click that in a bookmarklet and have all unread threads open. Everything seems to work, the array is the correct length, but that for loop where it opens the URLs just opens the first one and then stops.

Code:
javascript:
var SITE = location.host;
if(SITE=="www.resetera.com"){
    var arr = [], l = document.links;
    for(var i=0; i<l.length; i++) {
        if(l[i].href.indexOf("/unread") !== -1)
            arr.push(l[i].href);
    }
 
 
    for ( var i = 0; i < arr.length; i++) {
        window.open(arr[i]);
     }
 
}
window.open() actually has a second argument which (at least according to MDN) isn't optional. It specifies the name of the window, and calls specifying the same name go to the same window. Might be worth making sure the argument is distinct for each call.
 
Oct 25, 2017
4,903
#29
window.open() actually has a second argument which (at least according to MDN) isn't optional. It specifies the name of the window, and calls specifying the same name go to the same window. Might be worth making sure the argument is distinct for each call.
I didn’t know that. Of the things I poked around with online with JavaScript, the window.open () suggest that can be done just with a url, or you can attribute it a _blank. Either way, I still can’t get it to work if I do a _blank or if I specify something more. And I guess I don’t know why it would work once and not other times if that is the problem. I would think it would fail all the time if that was the problem. Also, I am trying to get this to work in Safari so I don’t know if Mozilla or Firefox handles JavaScript differently. And it used to work prior to iOS 11 and Safari 11.
 
Oct 26, 2017
11
#30
Hi all. I'm a scientific computing person (computational biochemistry), and more broadly I've been coding for about 15 years, so I figured this would be a good thread to say hello in!

My background is in C, but day-to-day I mostly just hack stuff together in Python and Bash.

Looking to give Julia a try soon for some machine learning pet projects, any native speakers here? I've been kind of inspired by the JuliaCon deep learning talk (it's a good watch if you have a couple of hours to burn, and also has some amusing jetlagged-academic-speaker moments -- my fave is the first speaker wandering off with the mic...).
 
Oct 26, 2017
112
#31
Hello! Glad to see this thread is up. My first time ever posting in this thread.

I'm hoping to get into systems programming in the Bay Area after a weird, short stint in law school (I majored in comp sci in undergrad). I've been reading The Linux Programming Interface by Michael Kerrisk, this 1300 page tome on the Linux API. Slowly, yet surely, getting through it. It feels really good to be back in the quantitative world.
 
Oct 25, 2017
38
#33
I'm glad to see this thread up, as someone learning web development and am currently going through a mix of the Odin Project and Free Code Camp, it's great to have another resource that I can look to if I become stuck on something. Going through a jQuery course at the moment before starting an 'Etch-a-Sketch' project which should be fun.
 
Oct 25, 2017
610
#34
Any Lisp fans here? Looks like neither Racket nor Common Lisp are trendy enough to be mentioned in the OP post. :P Lately I was reading this interesting programming language compiler course, which is using Racket as the implementation language: https://jeapostrophe.github.io/courses/2017/spring/406/notes/book.pdf
I took a functional programming language course that used Racket. It was pretty fun, and seemed like a much gentler start to functional programming than something like Haskell, but I just can't see myself using it for anything I'd want to do with programming. I really like the recent trend of non functional languages adopting some features from functional programming though, since a lot of them are really nice.
 

Wollan

Mostly Positive
Member
Oct 25, 2017
2,912
Norway but living in France
#35
Any Lisp fans here? Looks like neither Racket nor Common Lisp are trendy enough to be mentioned in the OP post. :P Lately I was reading this interesting programming language compiler course, which is using Racket as the implementation language: https://jeapostrophe.github.io/courses/2017/spring/406/notes/book.pdf
I read through the book Realm of Racket which covered a surprisingly lot of uses despite being a "beginner's book" (though I think it's likely rare anyone comes into functional programming being totally fresh). I recommend it.
Naughty Dog have used Racket for scripting since Uncharted 1/2 era (before that they used their own functional language GOALpreceded by GOOL).
John Carmack used Racket for VR scripting and was teaching his son how to program games in it.

I've yet to write anything worthwhile using a functional language, just read a couple of books out of curiosity and done the included examples.

I concur with Eridani in that I like the uptake of functional programming features in modern imperative languages. If I was to really dig into a new language today it would be Rust.
 
Last edited:
Oct 25, 2017
80
Vienna
#36
Nice to see this thread show up here as well ("close to the edge" on the old forum). Repping Rust, for hobby/side projects I pretty much use it exclusively (Typescript for web frontend stuff and Python for messing around with scikit.learn)
 
Last edited:
Oct 25, 2017
4,903
#38
Can someone tell me why this no longer works for me? I used to have a bookmarklet that when I clicked it would open all unread threads in new tabs. This worked prior to iOS 11 and Safari 11 on my Mac. I tested it in Chrome and it also fails there. The problem is when I run it now, it just opens the first link and then stops. Did something happen to how javascript is handled so window.open no longer works in for loops?

Basically, what I want to do is click that in a bookmarklet and have all unread threads open. Everything seems to work, the array is the correct length, but that for loop where it opens the URLs just opens the first one and then stops.

Code:
javascript:
var SITE = location.host;
if(SITE=="www.resetera.com"){
    var arr = [], l = document.links;
    for(var i=0; i<l.length; i++) {
        if(l[i].href.indexOf("/unread") !== -1)
            arr.push(l[i].href);
    }
 
 
    for ( var i = 0; i < arr.length; i++) {
        window.open(arr[i]);
     }
 
}
Got this working in AppleScript quite easily, so at least on the Mac using FastScripts I can easily open all unread watched threads with a keystroke. Still, wish I could figure out why it doesn't work like it used to in Javascript so I can have the bookmarklet on my iPad.
 

kristoffer

Banned
Member
Oct 23, 2017
2,048
#39
Cpp King sends his regards to everyone at programming GAF. Says it's been fun and that C++ is the best language. You can find him on Slaent.
NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!!!!!
 
Oct 25, 2017
2,043
#42
Here are some of my favorite Java books in my collection. I've read them and highly recommend these:

Thinking in Java - https://www.amazon.com/dp/0131002872/?tag=era0f0-20
OCA: Oracle Certified Associate Java SE 8 Programmer I Study Guide: https://www.amazon.com/dp/1118957407/?tag=era0f0-20
OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide: https://www.amazon.com/dp/1119067901/?tag=era0f0-20

I've been reading a little about Java 9 on the web but later I'll probably go through a Java 9 book as well (after more become available to choose from).
 
Oct 25, 2017
3,365
#44
I've got a project in python that I'm working on but I've been feeling so lazy that I don't keep improving it when I promise myself to. I think it might just be because of how much extra work I've been doing before I do vacation later on that I'm not feeling up to it. Maybe deep into my vacation I will work on it.
 
Oct 25, 2017
294
#47
Having a bit of a discussion going on about providing a default implementation from an abstract class. Given that you know only one default implementation is going to be needed what would be your arguments for / against this pattern:

Code:
public abstract class BaseClass
{
   public ExtendsClass DefaultBaseClass = new ExtendsClass();
 
   public abstract void DoSomething();
}
public class ExtendsClass : BaseClass
{
   override public void DoSomething()
   {
       Console.WriteLine("Hello") ;
   }
}
You could put it in a Factory I guess, but if you want to have just one default implementation, it feels clean to me to constrain it to the abstract base class for some reason.
 
Oct 25, 2017
373
#48
Hey guys. Me and emesve set up a discord for the programming community and hope you'll consider adding a mention to the op, and a link when the "quote to reveal" thing works. Until then, anyone can get a hold of either of us and we'll get you a link.

We think it could be an invaluable resource for direct talk about coding, help and feedback.
 
Oct 27, 2017
5,299
#49
Hey all, I'm trying to make a random number guessing game program but I need to random number to stay the same until the user has guessed correctly. How would go about keeping the random number the same, I've tried taking it out of the while loop but it doesn't seem to have worked.

Code:
  public static void main(String[] args){
    int userNum = 0;
    int counter = 0;
    double randNum = (int)(Math.random()*10);
    while(userNum != randNum){
      Scanner input = new Scanner(System.in);
      System.out.println("Ready? Enter a guess: ");
      randNum = (int)(Math.random()*10);
      userNum = input.nextInt();
      System.out.println("You chose " + userNum + "." + "The number I was thinking of was " + randNum);
      counter++;
    }
    System.out.println("Congrats you won. It took you " + counter + " guesses.");
 }
}
edit: Nevermind, I never removed the rand line from with the code after copy and pasting:P
 
Last edited:
Oct 25, 2017
3,365
#50
The Last Wizard
At a glance,
Code:
randNum = (int)(Math.random()*10);
should not be in the while loop. You keep setting it to a new number instead of leaving it be.

Set the number before your while loop and then just have the user keep guessing. You shouldn't have to set randNum more than once