PDA

View Full Version : Coding Programmers in the Playground



Solse
2015-05-25, 10:59 AM
From what I've seen on this forum, lots of us are programmers, so I figured there should be a thread for us all to hang out and talk programming. Want to brag about what you're working on? Want to ask for help as your program crashes and burns for some inexplicable, probably mystical reason? Then you've come to the right place.

Sermil
2015-05-25, 04:54 PM
Well, everyone knows that one of programmers' favorite pastimes is complaining about other programmers' code, so here's my favorite "What were they thinking?" story:

At one point, I was working on the audio system for a video game. The audio for the game was a whole bunch of WAV files on disk, which the engine would load as needed (there was way too much audio for everything to be in memory at once). To avoid constantly hitting disk, the audio engine I inherited had a caching system. But, I eventually realized the cache didn't work very well because -- drum roll please -- the replacement algorithm was alphabetical based on file name. That is, if the cache needed more room, first it would kick out aaaaa.wav, then ab.wav, then b.wav, etc. That's right, if some sound file named zbutton.wav was played just once when the main menu loaded, it would sit in memory for the rest of the game, but if some constant weapon sound was named alasershot.wav, it would be reloaded on every play.

So, you've heard of FIFO caches and LIFO stacks? This is the first time I'd encountered a LEFO -- LExical First-Out :smallwink:

Elena_NightWish
2015-05-25, 09:00 PM
thinking of programming. Is there an app for gitp? If not is there anyone working on one?

I've been fighting with learning Java which sucks. I have HTML, CSS, VB, SQL server, Linux, DOS... I have all of those pretty solid. But Java is kicking my ass. Any suggestions?

BannedInSchool
2015-05-25, 10:26 PM
I've been fighting with learning Java which sucks. I have HTML, CSS, VB, SQL server, Linux, DOS... I have all of those pretty solid. But Java is kicking my ass. Any suggestions?
There was a thread somewhere around here about learning programming. Erm, regarding Java there, it looks like that's your first real programming language. Maybe the trick there is realizing that there's data (objects) and instructions (functions), both of which are referred to indirectly by name in the code, and you don't necessarily know which instructions will do what to which data until the program is running. :smallsmile:

Elena_NightWish
2015-05-25, 10:53 PM
Erm, regarding Java there, it looks like that's your first real programming language. Maybe the trick there is realizing that there's data (objects) and instructions (functions), both of which are referred to indirectly by name in the code, and you don't necessarily know which instructions will do what to which data until the program is running. :smallsmile:

I'm curious how kernal languages aren't "real programming languages"? It's not object oriented; I do know that much. So Basically what you're saying BannedInSchool is that in object oriented programming its unpredictable until you have your program running?

Douglas
2015-05-25, 11:30 PM
I'm curious how kernal languages aren't "real programming languages"?
Depends on what you mean by "kernel languages". If you mean things like just using the command line, then no I would not consider that a "real programming language" in the sense usually intended by that term. If you mean the language(s) that the operating system kernel itself is written in, then that's a very different thing.


It's not object oriented; I do know that much. So Basically what you're saying BannedInSchool is that in object oriented programming its unpredictable until you have your program running?[/B][/I]
No, object oriented programming is just as predictable as any other type unless you screw things up. I think he was trying to describe that the basic concepts involved are very substantially different from those for the rest of your list. And really, they are.

HTML and CSS are all about defining what the user sees. Linux and DOS command line use, if that's what you meant by listing them, are only very slightly above the level of "basic computer proficiency" with regard to programming expertise. SQL Server is an extremely specialized thing, all about storing, organizing, and retrieving the data, which while it is a very commonly used and important thing is also only a very small portion of programming in general. VB... VB has a strong reputation among professional programmers for being really really easy to learn just enough of it to do something meaningful, without doing a good job at leading new programmers into learning more sophisticated concepts.

Java, on the other hand, is all about the enormously general idea of how a program does its work behind the scenes, is far from as forgiving of mistakes and ignorance as VB, and has a lot of concepts built in to help simplify some very complex things. This is a pretty drastic shift, so it's not very surprising that the jump is giving you trouble.

What have you learned about Java so far, and what's giving you trouble about it? That will help me know what kind of advice would help most.

Xuincherguixe
2015-05-26, 01:30 AM
There was a time I tried to make a general text based game server in Java.

The idea would be that you would supply annotations on certain methods. These would then be dynamically loaded, and parsing functions would be generated from them. (I was using JavaCC for my parser generation). It was getting close to finished, but I kind of gave up at some point because I didn't really have much of a use of it. Was something I was doing largely for the challenge.

This also means that in a round about way I was making a language and compiler.

I'm currently struggling with the Shadowrun Returns editor. It's... been pretty painful.

I've been meaning to dig into Common Lisp and Scala, though I recently discovered pony (which I started a thread for a bit below). Which in addition to seeming to make concurrency easier manages to be C++ but sane.

Xuincherguixe
2015-05-26, 01:37 AM
I actually like Java. Which I'm pretty sure is heresy. It's one of those languages that's popular to trash. Which in fairness isn't entirely unjustified.

I was thinking about getting into some of the philosophy and history, but that might just end up leaving you more confused. So I'll just give two thoughts.

If your issue is with command lines, I'd recommend an IDE (Integrated Development Environment). I like Netbeans. Technically Notepad++ isn't really an IDE, but I figure it's "close enough". Some people prefer advanced text editors to full on IDEs too. Basically you have some program handle all the minutia of compiling and running files so you don't have to deal with a command line. There's other features too, but you can worry about that stuff after you've figured out the basics.

If you're getting a lot of compiler errors? I find that it helps to think of it this way. That's the machine giving you help. If you keep up with it you'll be able to figure out the patterns and what you're supposed to do to fix them. Expect that the first time you try to compile you'll get a few errors. IDEs help with this too because different things are colored differently. If things aren't the right colors? You get a good visual cue that you wrote something badly. And you can generally pick up where that was pretty quick.

Java gives you a few more sorts of errors than perhaps it needs to, people who have studied this stuff have found sometimes it's best to not let you do something because that kind of thing has caused problems.


... Yeah. Even in trying to keep it short I tend to ramble.

These tutorials (http://https://docs.oracle.com/javase/tutorial/) might serve you well too.

factotum
2015-05-26, 02:29 AM
VB... VB has a strong reputation among professional programmers for being really really easy to learn just enough of it to do something meaningful, without doing a good job at leading new programmers into learning more sophisticated concepts.


I think that's far less true of VB.NET than it was of VB6--VB.NET is far more structured, and having access to the entire .NET framework gives you a good grounding for moving on to other .NET languages. The main issue with it is that it encourages people to code directly to the user interface rather than, as is right and proper, having the main program engine separate from the UI code.

(Although even VB6 had the concept of functions and data, so I think BannedInSchool was being unnecessarily harsh in his comment).

BannedInSchool
2015-05-26, 09:38 AM
No, object oriented programming is just as predictable as any other type unless you screw things up. I think he was trying to describe that the basic concepts involved are very substantially different from those for the rest of your list. And really, they are.
Yeah, trying to capture the essence of OOP in one sentence. :smallsmile: But for programming in general, it kind of reminds me of the progression (simplified) through mathematics of arithmetic -> algebra -> calculus -> differential equations.

To explain more, let's go through "Hello, World." So you start with a program that just prints "Hello, World". From there you can have one that prints a string from a local variable. You don't necessarily know exactly what the contents of the string are at compile time, but you know exactly where it is. After that you can be printing a string that you don't even know exactly where it is in memory from looking at the code; it's passed in from somewhere, but it's not fixed at compile time. And then after that you can not even know exactly what print function is going to be called come runtime. So OOP is doing things you don't know what to data you don't know where at compile time. :smallsmile:

Tyndmyr
2015-05-26, 12:21 PM
I actually like Java. Which I'm pretty sure is heresy. It's one of those languages that's popular to trash. Which in fairness isn't entirely unjustified.

*waves* I also like Java. For most things anyway. I don't much enjoy doing client-side GUI stuff in Java or the like, as Swing is frigging terrible, but on the whole, it's a very useful language.

I also like the .Net Languages. VB and C# are both easy to code in. Most languages have at least a niche within which they're quite good. And at least a few areas where they're really quite terrible. I view using different languages as having a well stocked toolbox.

Xuincherguixe
2015-05-26, 12:24 PM
*waves* I also like Java. For most things anyway. I don't much enjoy doing client-side GUI stuff in Java or the like, as Swing is frigging terrible, but on the whole, it's a very useful language.

I also like the .Net Languages. VB and C# are both easy to code in. Most languages have at least a niche within which they're quite good. And at least a few areas where they're really quite terrible. I view using different languages as having a well stocked toolbox.

Oddly enough Swing is one of the things I like the most. But NetBeans comes with a GUI editor which helps a lot.

Errata
2015-05-26, 12:38 PM
I'm curious how kernal languages aren't "real programming languages"?

DOS and Linux are not examples of programming languages. The operating systems are written in programming languages, but you are not exposed to their source code when simply typing in the command prompt. Linux is mostly written in C/C++, with some assembly. No idea about DOS/Windows, since it's proprietary source, but probably some mix of C/C++/C# and assembly. VB is a programming language, but your inclusion of it in that list without distinguishing it from the rest suggests you may not have mastered it to its full potential.

Your first programming language is always the hardest, because you're not really learning a language, you're learning to program. The hard part is not the syntax, it's the programming concepts that the syntax represents. Once you master one full programming language like that, you'll find switching to another much easier. And the more different types you learn, the easier it will get, since you'll pick up concepts that you may have missed in one language.

For example, once you master Java, it should be pretty easy to go to C/C++/C# or other similar languages. Though when you go to C, some of the pointers and memory management may be tricky since Java tries to hide that complexity from you. Still, much easier than learning C/C++ from scratch without that prior programming experience.

Jasdoif
2015-05-26, 12:43 PM
I think that's far less true of VB.NET than it was of VB6--VB.NET is far more structured, and having access to the entire .NET framework gives you a good grounding for moving on to other .NET languages. The main issue with it is that it encourages people to code directly to the user interface rather than, as is right and proper, having the main program engine separate from the UI code.VB.NET is far better than VB6 or VBA ever dreamed of being, and is perfectly good at doing its job. It compiles to CLR like every .NET language does, after all; your choice of language for .NET apps is principally about what syntax/semantics you're most comfortable with.

VB already had the reputation from older versions firmly entrenched, though....And in my experience, Visual Studio is more responsible for encouraging binding logic code with the UI than the language itself is.

Grinner
2015-05-26, 02:17 PM
DOS and Linux are not examples of programming languages. The operating systems are written in programming languages, but you are not exposed to their source code when simply typing in the command prompt. Linux is mostly written in C/C++, with some assembly. No idea about DOS/Windows, since it's proprietary source, but probably some mix of C/C++/C# and assembly. VB is a programming language, but your inclusion of it in that list without distinguishing it from the rest suggests you may not have mastered it to its full potential.

I figure he meant the scripting tools available in those operating systems (i.e. Bash scripting, batchfiles, etc.).

Errata
2015-05-26, 03:55 PM
I figure he meant the scripting tools available in those operating systems (i.e. Bash scripting, batchfiles, etc.).

Quite possible, but without a robust scripting language like Python/Perl/etc, it's still not really programming. And someone who is fluent in Python would call it Python, not Linux.

Chronos
2015-05-26, 04:19 PM
For me, the criterion is simple: If you can do conditionals and loops, you're a real programming language. If you can't, you're not. HTML can't do those things (or if it can, it's a portion of HTML that almost nobody ever touches-- I'm not certain about that point). Shell scripts can, but most shell scripts don't. VB, of any version, can. It might not be the best programming language to know, but it is a real programming language.

Tyndmyr
2015-05-26, 05:15 PM
DOS and Linux are not examples of programming languages. The operating systems are written in programming languages, but you are not exposed to their source code when simply typing in the command prompt. Linux is mostly written in C/C++, with some assembly. No idea about DOS/Windows, since it's proprietary source, but probably some mix of C/C++/C# and assembly. VB is a programming language, but your inclusion of it in that list without distinguishing it from the rest suggests you may not have mastered it to its full potential.



While Linux is, of course, an OS, not a language, it's very much a programmer's OS. It's very design is to make interfacing with the OS from code extremely easy, with a great deal boiling down to commands via a line of text.


For me, the criterion is simple: If you can do conditionals and loops, you're a real programming language. If you can't, you're not. HTML can't do those things (or if it can, it's a portion of HTML that almost nobody ever touches-- I'm not certain about that point). Shell scripts can, but most shell scripts don't. VB, of any version, can. It might not be the best programming language to know, but it is a real programming language.


Javascript certainly can, and while it's not HTML exactly, it's going to be integrated with it, and it's going to be accepted by essentially any browser. Between SVG and Javascript, web programming rapidly enters "real programming" territory as you get into more modern web site design. I agree, though, that VB makes a vastly better starting point, as you get to skip over some conceptual hurdles that are best addressed after you've gotten those basics down.

Conditionals and looping are the basis of so, so many things.

I think the key is to stick to very incremental projects. When I teach java, I start out setting up the dev environment and making a project(in eclipse). Then, we make hello world. From there, we progress to slightly more advanced versions of that, and eventually to a basic guessing game. Make one change, compile, test. If it goes wrong, you know exactly where.

Flickerdart
2015-05-26, 05:23 PM
If OP is already familiar with HTML and CSS, I would actually suggest learning Javascript first. The syntax is mostly the same, working with "Notepad" and a webpage is a lot simpler than wrangling with Eclipse, and it's more forgiving of beginner mistakes. A quick crash course should help you get the basics down and then you can move on to big, scary Java.

Tyndmyr
2015-05-26, 05:37 PM
Yeah, javascript ain't bad. I only hestitate to start people there because the error checking is usually kind of...opaque. Even with firebug or something installed, it's pretty easy to get into "what the hell" territory.

Douglas
2015-05-26, 06:05 PM
Yeah, javascript ain't bad. I only hestitate to start people there because the error checking is usually kind of...opaque. Even with firebug or something installed, it's pretty easy to get into "what the hell" territory.
I would not recommend JavaScript as anyone's first computer language unless their goals are very limited and focused. There are a lot of things JS allows that encourage sloppiness and other bad habits, and that's not the kind of thing you want someone in the initial learning phase using.

NichG
2015-05-26, 06:48 PM
I think sloppiness is fine if it gets you past the 'how do I make something that actually does something?' phase. For someone learning, the biggest hurdle to get over is to get a feeling for how to make something do 'what they want it to do' in their head. Things like clear code organization can come later when someone has a good idea of what a completed program is going to look like and has enough experience to be able to complete parts of that picture in their head before putting code down for it.

It also has the big upside of having one of the lowest barriers of entry to getting GUI and graphical stuff going out of any language I'm aware of. Being able to on-the-fly associate arbitrary code with document elements and to interleave that with existing HTML is very nice.

valadil
2015-05-26, 10:00 PM
Quite possible, but without a robust scripting language like Python/Perl/etc, it's still not really programming. And someone who is fluent in Python would call it Python, not Linux.

You can do robust scripting in bash. It's not advisable, but it can be done. Someone out there wrote an IRC client in it. No libraries, just writing into /dev/tcp. I'd argue that that's really programming.


I would not recommend JavaScript as anyone's first computer language unless their goals are very limited and focused. There are a lot of things JS allows that encourage sloppiness and other bad habits, and that's not the kind of thing you want someone in the initial learning phase using.

JavaScript has one big advantage. It's already installed. You don't need any additional tools, just a browser and a text editor. I've been programming since I was ten and it can still take me hours to set up the environment for new languages. Not so with JavaScript.

factotum
2015-05-27, 02:31 AM
I think sloppiness is fine if it gets you past the 'how do I make something that actually does something?' phase. For someone learning, the biggest hurdle to get over is to get a feeling for how to make something do 'what they want it to do' in their head.

The problem is, a bad habit, once learned, is very hard to *unlearn*. I mean, it would make the driving test much easier to pass for a learner driver if they didn't include all that gnarly stuff like "watching for other traffic" and "learning how to stop in an emergency", but I'm not sure the resulting drivers would be ones we'd want on the roads! Sloppy programming may not have the same potential of death (unless you're employing the guy to write the control system for your nuclear reactor, of course), but it can still cause lots of problems.

Tev
2015-05-27, 02:55 AM
Actually whatever language is your first, it will take quite some time to learn how to write clean code.

And while web apps are getting more complex they still do differ from programs in "classic languages", so it also matters what you want to learn to do. If you want to make some kickass games ignore JS. If you want to make new and better facebook someday then JS is great first language.

Xuincherguixe
2015-05-27, 03:08 AM
The thought occurred that this interactive lisp (http://art2.ph-freiburg.de/Lisp-Course) tutorial might be of interest or relevance to some people. Word of caution though. I suspect the password field is basically useless and sends it as plain text. So don't use one there that you would for anything else.

Lisp is a pretty interesting language with a combination of features. I started looking into it because a lot of work about artificial intelligence was done in it. (I've also learned that's a terrible name and gives people all sorts of terrible ideas about what it is).

These are the main features
-Really simple syntax
(+ (1 2)) will give you 3.
It's a little weird at first but you'll get used to it.
-Functions can be treated as data.
You can pass a function to another function to make a new function
-You can create new language constructs.
Lisp does not go obsolete. Because whenever good ideas come along someone can put them
together in Lisp. Wasn't originally object oriented for instance. But if you want to do object oriented
programming someone has done an implementation (quite different from the way C++/Java do them.
But Object Orientated programming came from a language more like Lisp than C to begin with!)


If there's interest I can pull up additional links.

Xuincherguixe
2015-05-27, 03:21 AM
Actually whatever language is your first, it will take quite some time to learn how to write clean code.

And while web apps are getting more complex they still do differ from programs in "classic languages", so it also matters what you want to learn to do. If you want to make some kickass games ignore JS. If you want to make new and better facebook someday then JS is great first language.

Yeah. Basically my thought is don't worry too much about writing good code when you're starting. It's something to keep aware of as you go on. But it's a distraction as you're learning a language.

Most of the time you'll find a style guide for your particular language. Read it after you've played around a bit but don't worry too much. Then come back as you have a better understanding.


As far as games go? You're better off finding a good game engine and learning whatever languages it supports. I did some stuff with Unity (https://unity3d.com/). Which meant .Net. So C#. But I already knew Java so it was easy to get into it.



... Actually on that note? If you want to learn to program Unity isn't a bad way to start either. It's kind of an IDE itself. The downside is that you're using .NET (mono technically) and I don't much care for Microsoft. But I was really impressed with some of the stuff that was going on.

NichG
2015-05-27, 05:47 AM
The problem is, a bad habit, once learned, is very hard to *unlearn*. I mean, it would make the driving test much easier to pass for a learner driver if they didn't include all that gnarly stuff like "watching for other traffic" and "learning how to stop in an emergency", but I'm not sure the resulting drivers would be ones we'd want on the roads! Sloppy programming may not have the same potential of death (unless you're employing the guy to write the control system for your nuclear reactor, of course), but it can still cause lots of problems.

When you first learn to drive, usually its in a parking lot with parent supervision - no traffic, no emergencies, nothing complicated. Just the bare bones to get a feel for how much acceleration the gas pedal gives, how quickly you can brake, etc. By the time you get your license, you've long since learned the basics of operating the vehicle by using it in a safe environment and under supervision, because it'd be impossible for anyone to learn if they had to be perfect at it from the get go. So instead, you create a safe situation where no one will be hurt by your mistakes. For someone learning programming, that means working on projects that will never see the light of day outside of your own messing around. And realistically for most people that will be 100% of what they ever code.

Programming is a very hard skill for many people to pick up - much harder than driving. Many people get frustrated and give up. To me, its more important that they get over that barrier to entry and 'get it' than it is that they code cleanly or in a way that would be at home in a major software project. That can come later, if their career path takes them in that direction, and even if its hard to lose habits its a lot harder to get started in the first place, and far fewer people will be in a position where they ever need to lose those habits (e.g. writing code for general consumption) than people who will need to have some familiarity with programming (setting up a professional website for yourself, doing data analysis - you can do much more if you can use something like R or Matlab than if you're stuck with Excel, grabbing information from databases such as SQL or Mongo, automating repetitive tasks associated with your job, understanding someone else's code or interfacing with programs that don't have a very user friendly front-end, even for less quantitative jobs like when using advanced features of artistic software - Python scripting in Blender, for example).


Actually whatever language is your first, it will take quite some time to learn how to write clean code.

And while web apps are getting more complex they still do differ from programs in "classic languages", so it also matters what you want to learn to do. If you want to make some kickass games ignore JS. If you want to make new and better facebook someday then JS is great first language.

For games, Unity is pretty much standard these days, and that gives you the choice of C#, JS, or UnityScript.

Chronos
2015-05-27, 06:22 AM
So, when we're talking about learned bad habits... That doesn't include the program's primary form of input being editing the source code, does it? That's totally a good habit, right? :smallwink:

And if the source code gets too complicated, then you write another program that edits the source code for you.

Xuincherguixe
2015-05-27, 06:51 AM
So, when we're talking about learned bad habits... That doesn't include the program's primary form of input being editing the source code, does it? That's totally a good habit, right? :smallwink:

And if the source code gets too complicated, then you write another program that edits the source code for you.

Nah. Pretty sure that's doing it exactly right.

Tyndmyr
2015-05-27, 08:15 AM
Meh, I wouldn't worry overly much about writing good code initially. Nobody writes good code but me anyway*.

*Every programmer ever, when looking at other people's source.

pendell
2015-05-27, 09:42 AM
One possible answer to learning programming is : Learn to program procedurally before learning object-oriented program.

For small tasks , procedural is more than good enough. Object-orientation really starts to come into its own when a project starts growing beyond a certain size; at which, the ability to mate code with data in an object becomes a godsend to managing program complexity. But if you can't write a procedure, you're not ready to deal with objects.

I do most of my work in Java. Since I predate object-orientation and started my programming in BASIC back in the 1970s, I consider Java a godsend, especially since my first encounter with Object-Orientation was in Objective C, still in use on iphones.

Javascript I would consider more of a macro language than a programming language. While it permits a certain degree of branching and looping, its function set is sharply limited compared to a full programming language.

First programming language -- Well, I wouldn't recommend Java, but the languages *I* started in (BASIC, Pascal) aren't really usable for anything interesting like, say, small games. I've heard good things about Python but have never used it. But Perl, now, Perl is fun. The only weakness with it is that it is perhaps too forgiving of sloppiness, and a new programmer needs to learn good habits. That was the thinking that made Pascal, a bondage-and-discipline language if there ever was one, my CS101 language.

Respectfully,

Brian P.

factotum
2015-05-27, 10:01 AM
First programming language -- Well, I wouldn't recommend Java, but the languages *I* started in (BASIC, Pascal) aren't really usable for anything interesting like, say, small games.

I disagree. What makes a language useful for something is usually the run-time environment you use with it, not the language itself. I remember the White Lightning game development toolkit, released for the Commodore 64 and the Spectrum a very long time ago, was actually based on Forth; and I doubt many people would have thought of Java as a gaming programming language before Minecraft came along.

Admittedly, I'm not sure anyone has ever released a game development environment that used either BASIC or Pascal, but I don't think there's any reason you *couldn't* do it.

Xuincherguixe
2015-05-27, 10:34 AM
I doubt many people would have thought of Java as a gaming programming language before Minecraft came along.

And fewer after.

ChristianSt
2015-05-27, 11:00 AM
Javascript I would consider more of a macro language than a programming language. While it permits a certain degree of branching and looping, its function set is sharply limited compared to a full programming language.

Could you elaborate on this? I work as a web developer and I fail to see any reason not to treat JavaScript as a full programming language. The only "problem" I see that it might be harder (or even impossible) to manipulate the underlying system, but that is in no way needed to program something.

The only reason I see to start with JS is the availability. Just open a browser and you have the bare basics you need. But imo that doesn't outweigh the drawbacks. JavaSripts "type safety" (and other features) imo can make it much harder to grasp what is going on compared to orher languages.

pendell
2015-05-27, 11:31 AM
Could you elaborate on this? I work as a web developer and I fail to see any reason not to treat JavaScript as a full programming language. The only "problem" I see that it might be harder (or even impossible) to manipulate the underlying system, but that is in no way needed to program something.

The only reason I see to start with JS is the availability. Just open a browser and you have the bare basics you need. But imo that doesn't outweigh the drawbacks. JavaSripts "type safety" (and other features) imo can make it much harder to grasp what is going on compared to orher languages.

Okay.

First, let's define the difference between a "Scripting language" and a "programming language".

link 1 (http://stackoverflow.com/questions/101055/when-is-a-language-considered-a-scripting-language)

Link 2 (http://programmers.stackexchange.com/questions/241104/programming-language-vs-markup-language-vs-scripting-language)

Link 3 (http://stackoverflow.com/questions/17253545/scripting-language-vs-programming-language)

Scripting languages are gaining more and more features, so the cleanest difference between them is intent. A scripting language is intended to be used on top of an existing application, to speed processing by automating common keystrokes, or to simplify the operation of a GUI.

A programming language, by contrast, is intended to create a full application. In the old days, you could demarcate it by the fact that programming languages created .exe or binary files . That is no longer the case. But it remains true that programming languages tend to offer an array of features and abilities out of the box that you have to write for yourself in a scripting language.

Case in point.

I am writing a program which is intended to deliver -- let's call it mail -- to a set of addresses. I want a timer to check these messages, and to resend them if they didn't go through.

So what I want is a dictionary lookup of the different rooms, and a stack or queue of objects for each of those rooms.

Java gives me these out of the box quite quickly. First I define my message object as a class. Then I need a Linked List (https://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html) to store all the different objects for a room. Finally, I need Hashmap (http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html) for my dictionary lookup, where the string will be the room name, and the linked list will be the collection of messages being stored for each.

What if I find that I want to sort the linked list by time stamp? Well, that's what Collections.sort (http://tutorials.jenkov.com/java-collections/sorting.html) is for. That's not a bubble sort, either, but a pretty fast one, I suspect a quicksort.

Want to add a database driver? Can pull down mysql and drop it into my class library quite quickly.

Want to rewrite the program as a windows-based service? There are a couple third-party add-ons that make that quick.

By contrast -- some of this stuff can be done with Javascript, just as you can use a bicycle to move your furniture (eventually), but it takes longer and there's a fair amount of it I would have to build myself ; that has the disadvantage of being nonstandard.

I use Javascript quite frequently in web pages to do things like load data, transform data into a legible form, and package up a form to be sent via HTTP POST. It is very good for what it is intended for ; elementary operations to make web pages faster and more efficient. But once you start pushing beyond that to doing serious programming , you quickly start finding the limitations of the system.

Javascript might be very useful for simple, elementary programming and might do well as a starter. I'm concerned, however, that it is so free form that it may encourage a novice to develop sloppy habits which are a pain to unlearn.

Respectfully,

Brian P.

Tyndmyr
2015-05-27, 12:09 PM
First programming language -- Well, I wouldn't recommend Java, but the languages *I* started in (BASIC, Pascal) aren't really usable for anything interesting like, say, small games. I've heard good things about Python but have never used it. But Perl, now, Perl is fun. The only weakness with it is that it is perhaps too forgiving of sloppiness, and a new programmer needs to learn good habits. That was the thinking that made Pascal, a bondage-and-discipline language if there ever was one, my CS101 language.

Respectfully,

Brian P.

I started in FORTRAN. While this dovetails nicely with your procedural point, which is valid, I don't really suggest it for users. It's just...kinda dated.

Python is the exact opposite of perl, philosophically speaking. The whitespace enforcement drives me batty. I don't use it much.

As for BASIC, the early apple computers had QBASIC on them, which was quite a lot of fun, and which was at least partially responsible for my early exposure to the concept. Ideal? Nah. But already on the box, in an era when compilers and IDEs were fairly arcane, and not necessarily free.

IDE installation isn't that big a deal nowadays. Oh sure, worthy of a short guide, but most popular languages have a fairly straightforward setup, and users are generally at least vaguely familiar with installing apps. Oh sure, they won't know what all the buttons do, but they should be able to at least get the sucker running. So, I definitely wouldn't count that as a big point for javascript, especially as you'll need to work with browser plugins, libraries, etc anyway.

NichG
2015-05-27, 12:45 PM
Don't underestimate what you can do in Javascript. For example, this (http://games.urbanhermitgames.com/onewitheverything/) is entirely a mixture of Javascript and GLSL (WebGL required). It's not even using Unity.

In terms of language features, Javascript is sort of comparable to Python without the whitespace fixation. In a lot of ways, that makes it more sophisticated than something like C++ for certain kinds of programming structures. For example, it has hashing as a core concept (JSON objects), whereas that has been a bit slow to make it into C++ (in the sense that I still need a special compiler flag on gcc to be able to use the STL library that provides it). It also has some other nice ways to get yourself into trouble in pursuit of zany programmatic gymastics, such as the ability to do inline anonymous functions, treat those functions themselves as classes, dynamically assign them new variable fields, and have all of that stick. You can even use eval or DOM shenanigans to generate code dynamically from within the program and then execute that dynamically generated code, or have the program convert its own sourcecode into a string, store it in a variable, and send it to a (node-based) server for execution or vice versa. That said, something simple like reading text out of a file is insanely more difficult than it would be in C thanks to all the (different and mutually inconsistent) browser security layers and things like that. If you like OOP, people have written frameworks that handle class inheritance and things like that on top of Javascript without adding much boilerplate (a few extra parentheses mostly). Its actually very flexible as a language.

What it isn't, is organized. Understanding what is and isn't a reference is non-trivial. Equality is more complicated than in other languages, with possible special values of null, undefined, and nan that all behave differently. There's no strong typing, so its not obvious what type a given variable is (and it can change over the variable's usage). There are no explicit namespaces, so you can easily get collision with globals or, more confusingly, when inline anonymous functions that you pass outside of the place you create them can retain references in the namespace of their point of origin.

ChristianSt
2015-05-27, 01:46 PM
First, let's define the difference between a "Scripting language" and a "programming language".

In my eyes "scripting languages" is just a subset of "programming languages". Namely the subset of languages which do not compile to byte code, but are interpreted on the fly. Unless you want to say that languages like Perl or Python aren't programming languages, "scripting" alone is no argument.

And saying that JavaScript isn't a full programming language because its library is bad (which mostly depends on what you want to do) doesn't seem like a useful argument either.

For example I could say Java or C++ are bad languages because it would be pretty painful to program web-app frontends with them. Programming languages are just tools. Some are better for task X, others are best at Y and some fail at Z. If I pick a hammer and say it isn't a real tool because it is pretty bad at drilling holes, my definition of "tool" is just wrong.



Javascript might be very useful for simple, elementary programming and might do well as a starter. I'm concerned, however, that it is so free form that it may encourage a novice to develop sloppy habits which are a pain to unlearn.

Heck I never said that someone should start learning programming with JavaScript as first language. It is probably better to not use JavaScript at all - at least if I had a choice I certainly would use another language. (I hope I have time in the future to test TypeScript which should eliminate much of the problems JavaScript has.)

But all that doesn't change the fact that JavaScript is a full/regular programming language.

Xuincherguixe
2015-05-27, 03:26 PM
And hey while we're at it, JavaScript I think is used instead of SQL for MongoDB. So it has a lot of uses.

But I'm of the camp that prefers strong typing too really.

Elena_NightWish
2015-05-27, 03:27 PM
Wow i didnt expect my space casyness would result in this big of a debate.i was at work typing between calls so i wasnt paying much attention to how i was wording things. Sorry.

I feel like i should elaborate. I went to school specializig in computer networking a technology. I learned the bash scripting for linux both redhat and debian as well as CentOS; windoes command line {which i realized i mistakenly called it DOS}; VB and vb.net; SQL server which if i remember correctly is mySQL. As well as html and html5.
I then switched schools and majored in Computer Science and the first computer class i was taking was asan online intro to Java.

In my free time ive been playing with unity and game salad because what im wanting to do is game programming as well as productivity app development. Whats throwing me off for java is the syntax. I was reading other forums where it was suggested to learn java before ruby or perl. Ivealso been wanting to play with rails.

I "gave up" due to family issues and im currently refinding my passion for it. So while i have the other tools in my tool box im basically starting over fresh.

I dont know if that makes things better or easier.

Xuincherguixe
2015-05-27, 03:32 PM
Wow i didnt expect my space casyness would result in this big of a debate.i was at work typing between calls so i wasnt paying much attention to how i was wording things. Sorry.

I wouldn't worry too much about it really. This is stuff that a lot of people have invested a lot of time in, and come up with many different answers. There are literally tens of thousands of programming languages. And about thirty of any real significance. No small number of which were designed with the idea of being "easy to learn and use". How true that is is debatable.

Douglas
2015-05-27, 04:03 PM
There are literally tens of thousands of programming languages.
Many of which were designed for a joke or to make some kind of point rather than to be used seriously. To name a few offhand, there's LOLCAT, Brain****, and Whitespace.


Whats throwing me off for java is the syntax.
That's a pretty broad category. What about the syntax? Maybe give an example?

pendell
2015-05-27, 04:06 PM
And about thirty of any real significance. No small number of which were designed with the idea of being "easy to learn and use". How true that is is debatable.


Hah. The first language designed with ease of use in mind? Cobol

Here's a sample (http://www.csis.ul.ie/cobol/examples/Accept/ACCEPT.htm)

The problem with "ease of use" is that English or any natural language is not the best method for expressing logic. For example

X+Y = 2Z

is much for economical and clear than

"The value of Z is equal to the sum of x and y divided by 2".

Programmers have a need to clearly and elegantly specify their instructions with minimum ambiguity and maximum brevity. Because of this, different languages are more suited to some tasks than others. To me, they are all tools in a toolbox, to be used as appropriate.

Having a good set of design patterns (http://en.wikipedia.org/wiki/Software_design_pattern) and a good working knowledge of the relevant anti patterns (http://en.wikipedia.org/wiki/Anti-pattern) is more useful than fluency in any particular language. If you can execute good programming practice in ANY language, it's fairly easy to write good code in a different language and metaphor than your starting set. By contrast, a lousy coder will write terrible code in any language. In a previous project we used Smalltalk, and had a large staff of former FORTRAN programmers. Their ingenuity in finding ways to write FORTRAN in Smalltalk still amazes me to this day.

Respectfully,

Brian P.

Xuincherguixe
2015-05-27, 04:22 PM
Hadn't quite absorbed everything when I wrote the first response.

I think most of what I suggested in the first place still applies. Basically, find a good IDE with syntax highlighting. Look at example code. Read online tutorials. sun/oracles are pretty good.

Getting kind of late for me, but I'm sure other people will have good advice. There's also oracles forums and I imagine there are IRC channels. Still I can help if you need a bit more in the next little while.


That's all assuming you decide to stick with Java. Which isn't a bad idea.

BannedInSchool
2015-05-27, 04:57 PM
Whats throwing me off for java is the syntax.
Just a guess at the problem based on your scripting experience, but Java, being a real programming language :smallbiggrin:, does a lot of defining data structures and functions to be used entirely somewhere else and don't actually do anything until you use them. Part of OOP is packaging the data and functions that operate on that data into "Objects", instances of which you then create, pass around, poke at, and destroy, starting execution at the entry point (which can be defined quite a ways from the start of the file) and skipping hither and yon, not just straight through the source code file start to finish. Other things which might be a little odd is that "lines" aren't really a thing. A line break (I so wanted to say CRLF) or other whitespace doesn't usually mean much and statements/expressions are defined with other punctuation. Also a lot of things evaluate to a value which is used in the enclosing statement/expression, which can often be nested one within another. Just throwing stuff out blind here, trying to cover possibilities not be insulting. :smallsmile:

Douglas
2015-05-27, 05:09 PM
and don't actually do anything until you use them.
Yes, now that mention it, that is a rather major difference from scripting languages.

In a normal Java program, there is precisely one method that gets executed without you explicitly calling it. That method is the "public static void main(String[] args)" method of whichever class you designate as the program's main class.

Certain types of Java programs, such as applets, specify other entry points to the program instead. Regardless of which type of Java program you're making, most Java code is designed to be a tool that you can invoke somewhere else, not something to just run on its own.

Grinner
2015-05-27, 05:22 PM
Until I took an actual class on Java, I had a similar experience with it. One of the important things to remember is that Java is designed to be used in programs of a much larger scale than those you have previous experience with (can't speak to VB, though). Consequently, a lot of the syntax that seems superfluous now is really just there to assist in designing larger projects. Really, that's what object-oriented programming is all about.

pendell
2015-05-27, 05:41 PM
Speaking as a person who has had to deal with his fair share of legacy VB and VB.net I advise: Don't. Visual Basic is really fine for small, one-off applications but IME it doesn't scale up well. The OO tools to manage complexity simply aren't there.

I would recommend stepping up to Visual C#. It uses the same .NET framework as VB does, but it handles object orientation and other things much more cleanly. It also works with Visual Studio just as VB does, and whatever bad things I have to say about Microsoft do NOT extend to their IDE.

Respectfully,

Brian P.

Douglas
2015-05-27, 06:25 PM
Speaking of IDEs, my IDE of choice for Java is IntelliJ. I tried Eclipse and found it slow and its autocomplete thoroughly lacking. With IntelliJ, when I start typing a variable or class name, it very quickly suggests the right one so I can just press enter to select it rather than typing the remaining 10-20 or more characters. And that's just one example of the many ways in which it's proven to be one of the most user friendly programming experiences I've ever had.

pendell
2015-05-28, 07:56 AM
Noted. I'll have to give it a try.

Respectfully,

Brian P.

Tyndmyr
2015-05-28, 08:25 AM
Speaking of IDEs, my IDE of choice for Java is IntelliJ. I tried Eclipse and found it slow and its autocomplete thoroughly lacking. With IntelliJ, when I start typing a variable or class name, it very quickly suggests the right one so I can just press enter to select it rather than typing the remaining 10-20 or more characters. And that's just one example of the many ways in which it's proven to be one of the most user friendly programming experiences I've ever had.

I've seen it in use a couple of times, but I'm mostly stuck with Eclipse due to network effects. Mostly working on teams that love to rely on various Eclipse plugins for this and that. I suppose with enough fiddling, I could probably make IntelliJ work, but it'd be a lot of additional hassle.

Judged on it's own merits though, it looks slick.

Flickerdart
2015-05-28, 08:49 AM
I use IntelliJ for some things but it lags a lot because it does a lot of writing to disc when it's running something. If I had an SSD in my work machine I'd be using it a lot more.

halfeye
2015-05-28, 09:01 AM
I use IntelliJ for some things but it lags a lot because it does a lot of writing to disc when it's running something. If I had an SSD in my work machine I'd be using it a lot more.
SSDs (at this point in time) are for your OS, not your data. Your OS will put its data there, and it will end up full :smallsigh:

Big SSDs will be the way to go, sometime, but for now, it's OS on the SSD, data on a big harddrive, unless you have a lot of cash to spend. *checks cash* (hm, that may be a good idea)

Flickerdart
2015-05-28, 09:10 AM
I have a 512GB SSD knocking around at home, and I'm only using about 100GB of my work computer's storage, so space isn't an issue. I just don't want to screw around with warranties (and with using my own stuff on a machine I don't own).

halfeye
2015-05-28, 09:24 AM
I have a 512GB SSD knocking around at home, and I'm only using about 100GB of my work computer's storage, so space isn't an issue. I just don't want to screw around with warranties (and with using my own stuff on a machine I don't own).
Yeah, I think it's past the tipping point, this machine is dead while running. 128GB SSD and full? it's a problem. I just bought a 1TB SSD, should be here by next week, then I'll build a new rig. Videos eat GBs, but not much else does. Ask your boss for an SSD, if you get a 128GB at least it will boot a bit faster.

factotum
2015-05-28, 10:24 AM
Yeah, I was about to say that the price of SSDs is surprisingly low now--120Gb costs about the same as 30Gb did three or four years ago, and really big ones (Tb range) aren't quite as eye-wateringly expensive as they once were.

halfeye
2015-05-28, 10:40 AM
Yeah, I was about to say that the price of SSDs is surprisingly low now--120Gb costs about the same as 30Gb did three or four years ago, and really big ones (Tb range) aren't quite as eye-wateringly expensive as they once were.
120/128 Gb is OS only territory, 64 gB is low for capacity for a boot only disk, for data and boot you need at least 512 Gb, and that's probably low. However 1TB SSDs exist, and if they're good enough, they're probably big enough for most jobs.

Flickerdart
2015-05-28, 03:30 PM
Yeah, I think it's past the tipping point, this machine is dead while running. 128GB SSD and full?
128GB what? It has a 1TB HDD. That's why IntelliJ is slow.

halfeye
2015-05-28, 03:58 PM
128GB what? It has a 1TB HDD. That's why IntelliJ is slow.
My machine has a 128 GB SSD, which after three or four years of Win 7, is now pretty much full. It has HDDs for data, with space on them, but the SSD is nearly full (or it was a couple of weeks or so ago, now it's nearly half empty, which is as it should be). I don't know what that was all about, but I could do with my data on a faster drive.

factotum
2015-05-28, 04:19 PM
I read an article once that said you shouldn't let your SSD get more than about 75% full. If you do, it starts to spend so long rearranging written data in order to keep the wear levelling algorithms happy that its performance tanks.

Oh, and 120Gb being "OS only" depends entirely on your needs. My old laptop is the one with that 30Gb drive I mentioned earlier in it--since I have Linux Mint on there, which only takes up about 5Gb, and the thing is mainly used for browsing the Web, that's entirely sufficient. I'm about to upgrade my desktop machine with a 120Gb SSD, and I plan to use that for OS and smaller documents, with stuff like installers, movies, and game installations staying on the 1Tb spinning rust.

Chronos
2015-05-28, 04:20 PM
Quoth pendell:

In a previous project we used Smalltalk, and had a large staff of former FORTRAN programmers. Their ingenuity in finding ways to write FORTRAN in Smalltalk still amazes me to this day.
Of course you know the old saying that Fortran programmers can write Fortran code in any language, and C programmers can write C code in any language. I never really believed it, though, until I saw a guy who was programming in the dinky little scripting language of an IRC client I used to use... and he was writing C++ code in that language.

And not only are there only about 30 languages of any major relevance, but once you've learned a half-dozen or so, you've basically learned them all. Well, except for INTERCAL.

Grinner
2015-05-28, 04:21 PM
And if the source code gets too complicated, then you write another program that edits the source code for you.

"There is no problem that cannot be solved by another layer of abstraction." - The Programmer's Maxim

pendell
2015-05-29, 07:35 AM
And not only are there only about 30 languages of any major relevance, but once you've learned a half-dozen or so, you've basically learned them all. Well, except for INTERCAL.

Or APL (http://en.wikipedia.org/wiki/APL_%28programming_language%29), the language that allows you to write the game of life in one line of code (http://catpad.net/michael/apl/).

A neat little toy for party tricks and for exploring what can and can't be done with languages; completely unsuitable for any real work because it is almost totally unmaintainable.

Respectfully,

Brian P.

Xuincherguixe
2015-05-29, 09:12 AM
Since the number has been quoted a few times I should probably say that when I said there were only thirty languages of any significance? That's entirely subjective and not backed by any real data. Thought I should clarify.

That number just sort of feels right.

Flickerdart
2015-05-29, 11:57 AM
In terms of stats, GitHub's language popularity (http://adambard.com/blog/top-github-languages-2014/) seems like a good metric. There's a serious dropoff after the first 7, and then after the 17 mark.

Xuincherguixe
2015-05-29, 02:26 PM
In terms of stats, GitHub's language popularity (http://adambard.com/blog/top-github-languages-2014/) seems like a good metric. There's a serious dropoff after the first 7, and then after the 17 mark.

And neither Scala nor Common Lisp are on that at all. Ouch.

Grinner
2015-05-29, 03:38 PM
In terms of stats, GitHub's language popularity (http://adambard.com/blog/top-github-languages-2014/) seems like a good metric. There's a serious dropoff after the first 7, and then after the 17 mark.

Of all the languages I would have expected to occupy the #1 slot, I did not expect JavaScript.

Xuincherguixe
2015-05-29, 07:06 PM
Of all the languages I would have expected to occupy the #1 slot, I did not expect JavaScript.

Yeah, wouldn't have expected that myself either. I knew that it's being used in a lot of different ways beyond just the web but...

Actually that's probably it. People are creating a lot of new ways to use Javascript.

Elena_NightWish
2015-05-29, 08:16 PM
So its sounding pretty consistent that since I'm strong in VB and VB.net to go to the C language. Is C# or C++ better?:smallbiggrin:
Thank you all for the help. It's awesome to read this thread at work; It unbreaks my brain

Xuincherguixe
2015-05-29, 09:02 PM
So its sounding pretty consistent that since I'm strong in VB and VB.net to go to the C language. Is C# or C++ better?:smallbiggrin:
Thank you all for the help. It's awesome to read this thread at work; It unbreaks my brain

Glad to hear. I thought we were really kind of all over the place and talking about things that were kind of esoteric.

If you're going too ask which C derived language you should learn? I'd still say Java frankly. C# is pretty much Java anyways but made a bit more like C++, and Java was C++ fixed. They're all really similar, to the point where if you learn one it wouldn't be hard to pick up the others. And Java is going to give you the least amount of problems I think.

Certainly that's been my experience.


Though if you're being told C? I'd assume people were talking about C. Which is different than C# and C++. Like I say, Java is still a C derivative.

Douglas
2015-05-29, 09:07 PM
So its sounding pretty consistent that since I'm strong in VB and VB.net to go to the C language. Is C# or C++ better?:smallbiggrin:
Thank you all for the help. It's awesome to read this thread at work; It unbreaks my brain
I'm having trouble thinking of any syntax difficulty you might have with Java that would not also be a problem (possibly even a worse problem) with C# and/or C++.

Really, what it sounds like to me is that there's a conceptual issue you're not understanding, and that conceptual issue is probably going to be a problem making the jump to any "real" programming language.

So, again, please give a specific example of what you're having trouble with, so that we can help explain it and resolve the problem rather than trying to dodge it.

Elena_NightWish
2015-05-29, 10:50 PM
Thank you again for all the clarity. :smallbiggrin:

As I mentioned in an earlier post the professor I had at SOU did not present the material in the "correct fashion". I believe it was both the syntax AND how the concepts were presented.

EX: using a pre-created container system to compile a program within the larger container and then breaking it down into the smaller containers.

Basically I am going to ignore that instructor and start fresh. I really have a passion for game design and I have a lot of concepts but finding the right language to start with is the difficult part. I was told Java is a good one for app building. I prefer a command line verses a GUI for programming, but I think that can be changed with practice.
thoughts on GUI vs Command Line programming?:smalltongue:

BannedInSchool
2015-05-30, 09:01 AM
As I mentioned in an earlier post the professor I had at SOU did not present the material in the "correct fashion". I believe it was both the syntax AND how the concepts were presented.

EX: using a pre-created container system to compile a program within the larger container and then breaking it down into the smaller containers.

Basically I am going to ignore that instructor and start fresh.
*blink* And this is why remote tech support sucks. I have no idea what you might mean by those "containers" in an intro to Java course. I suspect again you may be better served by forgetting even more. :smallsmile:


I really have a passion for game design and I have a lot of concepts but finding the right language to start with is the difficult part. I was told Java is a good one for app building.
Depending on what you mean by games it depends. It's not my area of expertise but I do know in some cases, gods no, not Java. But C++, Java, and C# are all pretty close to each other as far as programming languages go, so for learning programming I'd say they're pretty equivalent.

I prefer a command line verses a GUI for programming, but I think that can be changed with practice.
thoughts on GUI vs Command Line programming?:smalltongue:
Uh, with dozens if not hundreds of functions, classes, and files possible in a project, sure you could still make do with a text editor, a command line, and a makefile (a script for automating compiling), but an IDE (Integrated Development Environment) makes things a lot easier. (Oh, I'm hurting myself with that wordplay.) The actual programming is the same in either case. I wonder if that Java course was designed to be accessible to people without command line experience, and (no offense) you're getting the tools used confused with the actual Java programming.

I mean, here's the complete code of a Java application:

/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}

You can edit and compile that from command line or an IDE, but the IDE makes managing things a lot easier.

Xuincherguixe
2015-05-30, 10:05 AM
I wouldn't say "Oh gods no" when it comes to Java and Game Development. It sort of comes down to what it is your trying to do.

I've spent awhile at this post now and I realize I'm not sure where to start.

I suppose on the issue of Java for games it comes down to
-No. It's actually pretty viable. No really
-Like, people have made commercial games in Java
-Minecraft is terribly programmed so it doesn't count
-Not the language you'd use for making the next Call of Duty
-You're insane if you want to make the next Call of Duty. Stop before you hurt yourself.
-You could still make some well performing and nice looking games in Java (Borderlands level is likely viable)


As to in the broader sense?
There's a pretty thriving indie scene right now. Kind of saturated and hard to get noticed, but there are a lot of resources to help you get started. Java isn't terrible if you're building something simple from scratch.

But I feel like I should recommend going with a Game Engine really, and probably Unity. Which you already were. Either continue to use Javascript, or use C#. Which much as it pains me to suggest is probably your best choice.

BannedInSchool
2015-05-30, 06:58 PM
I wouldn't say "Oh gods no" when it comes to Java and Game Development. It sort of comes down to what it is your trying to do.
Yeah, did say depending, with priority on speed of execution end of the spectrum in mind. I guess it has been *mumble* years and processor generations since it was impressed on me how much slower Java was, and it might not be as bad these days. :smallsmile:


EX: using a pre-created container system to compile a program within the larger container and then breaking it down into the smaller containers.
Wait, you don't mean the AWT Container class, do you? If that rings a bell, that's just part of a toolkit that's included for making GUIs in Java, so that there's a basically platform-independent windowing system for your programs to use. I guess that'd be an okay way to teach object interaction, as GUIs are naturally a bunch of objects. I did crib that Hello, World! from the Official Java Tutorial (https://docs.oracle.com/javase/tutorial/index.html). It starts out all text, so maybe you'll enjoy that more, but I question if it's a good way to learn programming in general. *shrug*

Grinner
2015-05-30, 07:17 PM
Wait, you don't mean the AWT Container class, do you? If that rings a bell, that's just part of a toolkit that's included for making GUIs in Java, so that there's a basically platform-independent windowing system for your programs to use...

Is it common to teach an introductory programming class that way, though?

I'm thinking Elena_Nightwish is talking about classes in general. If you're coming from a procedural background, they're not exactly easy to pick up on.

Douglas
2015-05-30, 07:25 PM
As I mentioned in an earlier post the professor I had at SOU did not present the material in the "correct fashion". I believe it was both the syntax AND how the concepts were presented.

EX: using a pre-created container system to compile a program within the larger container and then breaking it down into the smaller containers.
That sounds either confusing or poorly explained, and both options indicate poor teaching.

Would it help if I took a small Java program and did a detailed breakdown of exactly what each part of it means and does?


Basically I am going to ignore that instructor and start fresh. I really have a passion for game design and I have a lot of concepts but finding the right language to start with is the difficult part. I was told Java is a good one for app building. I prefer a command line verses a GUI for programming, but I think that can be changed with practice.
thoughts on GUI vs Command Line programming?:smalltongue:
I'm not entirely sure what you mean by those terms here.

"GUI", taken literally, means "Graphical User Interface", and in this context would imply programming by using the mouse to create and arrange visual components on a screen. I remember doing something like that for Visual Basic, so I'm guessing that's what you're talking about. This technique is useful for designing the visual appearance of standard windows and such, and special programs exist for doing something similar in many different languages, but it has very little to do with most serious programming.

"Command Line", taken literally, means entering text commands to be executed immediately through a one-line-at-a-time text entry mechanism. Pretty much no one writes programs this way, so I'm guessing what you actually meant was editing source code in an ordinary text editor and using a command line tool to compile it.

The former technique is useful only for a specific and narrow aspect of programming, and even there has a lot of limitations. I rarely use it. The latter technique is very easy to make all sorts of mistakes with and doesn't tell you about those mistakes until long after you make them.

What I and the vast majority of professional programmers prefer is a third approach in between, called an Integrated Development Environment, or IDE for short. The central part of any IDE is a text editor, but unlike a normal text editor it will do all sorts of things just for programming. Language keywords get automatically shown in a different color, syntax errors get underlined in red the moment you type them, when you start writing a function call it pops up a tooltip telling you what arguments you need to pass, when you type an open curly brace it automatically generates the matching closing one and increases indent on the next line, you can control+click on a variable or function call to go to its definition, etc. The precise list of such features varies from one IDE to another, but in general they remove a lot of nuisance factors from programming and make it overall much easier.


Yeah, did say depending, with priority on speed of execution end of the spectrum in mind. I guess it has been *mumble* years and processor generations since it was impressed on me how much slower Java was, and it might not be as bad these days. :smallsmile:
JVM implementations have gone through a LOT of development since the early years, and a modern JVM is a very great deal faster than they used to be.

Xuincherguixe
2015-05-30, 08:18 PM
I'm thinking Elena_Nightwish is talking about classes in general. If you're coming from a procedural background, they're not exactly easy to pick up on.

The way I had it explained is that Object Oriented Programming? That comes from the Functional world. Smalltalk as it happens. A lot of the reason OO was created was for ease of use in making GUIs.

And if people coming in aren't aware of what functional programming (https://en.wikipedia.org/wiki/Functional_programming) is, the name comes from that you're working with functions.

Grinner
2015-05-30, 09:13 PM
The way I had it explained is that Object Oriented Programming? That comes from the Functional world. Smalltalk as it happens. A lot of the reason OO was created was for ease of use in making GUIs.

I don't really think about the taxonomy of programming languages that much. It's entirely possible that I'm conflating procedural and functional programming.

Personally, I've thought of classes as structs with their own personal functions.

Xuincherguixe
2015-05-30, 09:33 PM
I don't really think about the taxonomy of programming languages that much. It's entirely possible that I'm conflating procedural and functional programming.

Think that would be pretty hard. Functional languages are pretty different than Procedural ones.


Personally, I've thought of classes as structs with their own personal functions. Not the worst way to think about it.

NichG
2015-05-30, 10:04 PM
Its funny, but the programming language that made me really 'get' object oriented programming was actually a language for writing text adventures called TADS.

Not because objects were literally objects in the world, but because it had a really well-designed inheritance structure where you really could do a lot just by putting multiple parent classes onto something, each of which was designed to provide a certain type of functionality. There were hooks for that functionality that would basically do a sort of type checking and naturally latch in if the class provided the necessary function, but would otherwise return an indication that the class didn't support it (or would give a default behavior). So for example, if you wanted to make a verb that let the player 'smell' something, you could create a 'Smellable' mix-in class that just added the onSmell() method to existing classes, and define a default onSmell associated with the verb that would run when the classes didn't support that particular method.

There was also an explicit way of overriding functions so that you could walk back up the object hierarchy rather than just doing total replacement. You could always call a super() function to execute the parent class version of the function (I forget exactly how it worked with multiple inheritance, but I think there was a way to define an order of precedence).

After programming in TADS, C++ doesn't actually feel very OOP to me - more like it's giving lip service to the concept to tack it on top of C. The strong typing combined with the in-code lack of awareness of type makes it so you have to jump through a ton of hoops to do some of the things that were pretty trivial to set up in TADS.

Douglas
2015-05-30, 10:26 PM
After programming in TADS, C++ doesn't actually feel very OOP to me - more like it's giving lip service to the concept to tack it on top of C. The strong typing combined with the in-code lack of awareness of type makes it so you have to jump through a ton of hoops to do some of the things that were pretty trivial to set up in TADS.
That's pretty much accurate, as I understand it. C++ was one of the earliest object oriented languages, and "C plus this new idea" was the core principle of its original design. Java came later after a lot of experience and learning with the concepts, and its design is a lot closer to "object oriented from the ground up".

Elena_NightWish
2015-05-30, 10:28 PM
That sounds either confusing or poorly explained, and both options indicate poor teaching.

Would it help if I took a small Java program and did a detailed breakdown of exactly what each part of it means and does?


I'm not entirely sure what you mean by those terms here.

"GUI", taken literally, means "Graphical User Interface", and in this context would imply programming by using the mouse to create and arrange visual components on a screen. I remember doing something like that for Visual Basic, so I'm guessing that's what you're talking about. This technique is useful for designing the visual appearance of standard windows and such, and special programs exist for doing something similar in many different languages, but it has very little to do with most serious programming.

"Command Line", taken literally, means entering text commands to be executed immediately through a one-line-at-a-time text entry mechanism. Pretty much no one writes programs this way, so I'm guessing what you actually meant was editing source code in an ordinary text editor and using a command line tool to compile it.

The former technique is useful only for a specific and narrow aspect of programming, and even there has a lot of limitations. I rarely use it. The latter technique is very easy to make all sorts of mistakes with and doesn't tell you about those mistakes until long after you make them.

What I and the vast majority of professional programmers prefer is a third approach in between, called an Integrated Development Environment, or IDE for short. The central part of any IDE is a text editor, but unlike a normal text editor it will do all sorts of things just for programming. Language keywords get automatically shown in a different color, syntax errors get underlined in red the moment you type them, when you start writing a function call it pops up a tooltip telling you what arguments you need to pass, when you type an open curly brace it automatically generates the matching closing one and increases indent on the next line, you can control+click on a variable or function call to go to its definition, etc. The precise list of such features varies from one IDE to another, but in general they remove a lot of nuisance factors from programming and make it overall much easier.


JVM implementations have gone through a LOT of development since the early years, and a modern JVM is a very great deal faster than they used to be.

For someone that has read only my half-brained replies to decipher my actual meaning and make it more eloquent is amazing! I have played with IDE's once upon a time; I honestly had a massive brainfart. I kind of put everything technical on the back burner when my daughter was born.
That being said; Douglas I greatly appreciate your offer of outlining a specific java program. However I think I'm going to dive head first into it now that I have my wits back about me thanks to everyone.
If I have more issues I will certainly be asking for more help. :smallbiggrin:

I think y'all have given me great starting points and I can't thank you enough!

I have never even heard of TADS i'll have to check that out

BannedInSchool
2015-05-31, 08:35 AM
That's pretty much accurate, as I understand it. C++ was one of the earliest object oriented languages, and "C plus this new idea" was the core principle of its original design. Java came later after a lot of experience and learning with the concepts, and its design is a lot closer to "object oriented from the ground up".
Heck, C++'s first iterations were as a C preprocessor including ideas from Simula (from which Smalltalk also descended). But if you compare C++ to just having all your data in one big global mess and designing/defining your program as a bunch of functions and sub-functions that operate on that data then C++ is pretty OO just with its support for abstract data types, data hiding, and polymorphism/inheritance. Java removes the knives, clubs, and guns of direct memory access, which reminds me of faking OO in C with nesting structs and casting pointers. :smallsmile:

Xuincherguixe
2015-05-31, 11:38 AM
As far as learning Java goes, Greenfoot (http://www.greenfoot.org/door) might be a good place to start. I haven't looked at it extensively but I saw a video awhile back and it looked promising.

Was designed to teach college students how to program, but it ended up being pretty good even for people as young as Grade 6. Numerous people have made games with it too.

Highly interactive and visual.



Scala might also be of interest to some people. Deploys to the JVM, pretty compatible with Java, functional, more strongly Object Oriented.

But the compiler is indefensibly slow and the collections system is a big problem. The scaladoc is lying to you about it and it's largely unmaintainable. A guy quit over this even though it was a pretty good job.

Makes me think the language is only going to get worse over time.


I also don't think I'd recommend it for someone just starting out in programming.

BannedInSchool
2015-05-31, 02:54 PM
Heh, I think everyone learning programming should learn a little assembler, but I don't know if I'd go this far: The TOY Machine (http://introcs.cs.princeton.edu/java/52toy/). Fun though. :smallbiggrin: ETA: It's a switch-programmed computer simulator. Er, the computer simulated is switch-programmed, not the simulator. Heh.

halfeye
2015-05-31, 04:29 PM
As far as learning Java goes, Greenfoot (http://www.greenfoot.org/door) might be a good place to start.
There's a book:

http://www.amazon.co.uk/Introduction-Programming-Greenfoot-Object-Oriented-Simulations/dp/0134054296/ref=sr_1_1?s=books&ie=UTF8&qid=1433107506&sr=1-1&keywords=greenfoot

£65? that's way too much for a simple intro to programming IMHO.

Xuincherguixe
2015-05-31, 05:45 PM
There's a book:

http://www.amazon.co.uk/Introduction-Programming-Greenfoot-Object-Oriented-Simulations/dp/0134054296/ref=sr_1_1?s=books&ie=UTF8&qid=1433107506&sr=1-1&keywords=greenfoot

£65? that's way too much for a simple intro to programming IMHO.

It's been my experience that a lot of these books are pretty expensive. Paid more for some myself.


At the same time it's for things more obscure than Java and more involved than an introduction. That's pretty excessive.

Tyndmyr
2015-06-02, 02:49 PM
I wouldn't say "Oh gods no" when it comes to Java and Game Development. It sort of comes down to what it is your trying to do.

I've spent awhile at this post now and I realize I'm not sure where to start.

I suppose on the issue of Java for games it comes down to
-No. It's actually pretty viable. No really
-Like, people have made commercial games in Java
-Minecraft is terribly programmed so it doesn't count
-Not the language you'd use for making the next Call of Duty
-You're insane if you want to make the next Call of Duty. Stop before you hurt yourself.
-You could still make some well performing and nice looking games in Java (Borderlands level is likely viable)


As to in the broader sense?
There's a pretty thriving indie scene right now. Kind of saturated and hard to get noticed, but there are a lot of resources to help you get started. Java isn't terrible if you're building something simple from scratch.

But I feel like I should recommend going with a Game Engine really, and probably Unity. Which you already were. Either continue to use Javascript, or use C#. Which much as it pains me to suggest is probably your best choice.

It is viable, yes. You can code just about anything in any language if you *really* want to. But garbage collection tends to introduce delays, and thus, decently sized games/game engines tend not to be made in Java. There are exceptions, like Jmonkey, but they would not be my first recommendation for coding a game up. Or second, or third. And I *like* Java.

Unity as an engine, sure. Definitely top three, at minimum.

But for learning, your first apps are all gonna be toy apps, and given the simularity between Java and C base, probably not THAT big a deal for educational purposes. I made a shooter once in VB 6 because I was very bored, and it was the only IDE I had access to. Learning concepts is more important than language choice, fun as it is to discuss the differences.

factotum
2015-06-02, 04:24 PM
But garbage collection tends to introduce delays, and thus, decently sized games/game engines tend not to be made in Java. There are exceptions, like Jmonkey, but they would not be my first recommendation for coding a game up. Or second, or third. And I *like* Java.

What about using a game engine *not* written in Java but which has a Java interface, like the LWJGL used in Minecraft?

Errata
2015-06-02, 06:06 PM
The language you pick to start learning is not a permanent decision, since the hard part is learning to program, not learning that specific language. So don't fret over that, just do what works for you. Whatever you find easier to learn is probably fine. Some universities teach intro courses in obscure toy languages to help emphasize that it's not about the language itself. Java is a solid choice because it does shield you from certain low level details, and has plenty of libraries you can integrate to get a project going quickly.

The low level stuff is actually important, but it's not the best thing to start with, and it can overwhelm newcomers. Eventually, as you progress to more serious programming you will very likely want to familiarize yourself with some flavor of C/C++/C#. Most of what you learned will carry over, but you will need to learn some important additional concepts, mostly involving pointers, that Java intentionally glosses over. This slightly lower level stuff is very important for certain types of programming; a good understanding of what the computer is actually doing with memory enables you to write applications that will perform better. Too much abstraction and not enough low level understanding can lead to very bloated programs.

Along those lines, you will eventually want to branch out into some sort of assembly language(s). This forces you to understand how your code in a high level language is actually implemented by the machine, which is another key to writing good, efficient code. In certain types of programming, you may actually need to incorporate some assembly into your project, but even if you don't, you'll still end up writing better code just by understanding it. A lower level understanding can also sometimes help with debugging when you get something weird and unexpected happening.

Xuincherguixe
2015-06-02, 06:15 PM
What about using a game engine *not* written in Java but which has a Java interface, like the LWJGL used in Minecraft?

I'm pretty sure that's what we were getting at.

Physics and rendering? That's something you'd want that was particularly low level. What something becomes after you hit it with a spell? CPU cycles aren't so important there.

Max™
2015-06-02, 11:07 PM
Man, saw that github languages link and on the one hand I'm glad that Lua isn't totally off the radar, but I'm surprised that Ruby was so high. Been using lua mostly for DFhack scripts and ruby ones live in the same folder so I kinda think of them as cousins, is that crazy?

Solse
2015-06-03, 05:12 AM
I feel bad for not using Ruby. I've been doing all of my web development in PHP, which I keep hearing as a "horrible language", but it works for me. I *do* use XML and PHP's SimpleXML frontend instead of an SQL database. How bad is that, and how many problems will that cause down the line?

Tyndmyr
2015-06-03, 12:00 PM
What about using a game engine *not* written in Java but which has a Java interface, like the LWJGL used in Minecraft?

I generally dislike adding additional languages, but technically, yeah, there are a lot of ways to blend stuff.

Especially when you're talking about more complex client-server/etc stuff. Asking what language an MMO is written in is generally nearly meaningless, since there are so very many pieces.

But given my choice, I'd try to minimize number of languages used in any given project. It reduces headaches.


I feel bad for not using Ruby. I've been doing all of my web development in PHP, which I keep hearing as a "horrible language", but it works for me. I *do* use XML and PHP's SimpleXML frontend instead of an SQL database. How bad is that, and how many problems will that cause down the line?

I don't use Ruby either. Meh. For webapps, I prefer a java webapp model with the struts methodology. Sprinkle javascript, it's many associated libraries, etc around the front end to taste, and pick yer favorite SQL database for the backend. I'm partial to PostGres, but this is mostly because I'm cheap, and most SQL databases all do more or less the same thing for most purposes.

Relying on data stores other than SQL is fine for modest quantities of data, but they usually scale a LOT worse in performance. But, if you've kept your data access bits fairly distinct, ripping them out for a swap shouldn't be THAT bad. Some people like an intermediate data access system here, like Hibernate. Having used it, I have highly mixed feelings on Hibernate. The abstraction is nice, but you're pretty much guaranteed to have the framework shoot you in the foot at some point. So, when given the option, I pretty much just bake my own data layer.

Silverraptor
2015-06-03, 12:59 PM
Hey guys, for a project in school, we're trying to create a simple visual novel in javascript. Unfortunately we are receiving a weird error where obj (object) is undefined when its ran normally, but when we use the debugger and walk it through step by step, it goes "Oh, yeah obj is defined and I can work normally now." And then we refresh and its back to undefined. Its seriously frustrating for something so illogical such as obj being both undefined and defined.:smallyuk:

We did borrow the code from an open source example and modified it with some of our code and images. I would post the code, but its in the 1600+ line range and I don't know if it would fit in a forum post.

NichG
2015-06-03, 01:29 PM
I guess try explicitly defining obj at the top of the first script you include as an empty JSON object and see when the contents change? 'undefined' is sort of like nans in that it's infectious.

Douglas
2015-06-03, 01:41 PM
I would post the code, but its in the 1600+ line range and I don't know if it would fit in a forum post.
Put it in a spoiler block and I'll take a look.

Silverraptor
2015-06-03, 01:51 PM
Put it in a spoiler block and I'll take a look.

No need. After 3 hours we found the problem. My partner put in a "}" too high in the code.:smallsigh:

Douglas
2015-06-03, 02:28 PM
No need. After 3 hours we found the problem. My partner put in a "}" too high in the code.:smallsigh:
Ah. Yet another example of JavaScript trying valiantly to pretend there's nothing wrong for as long as possible, with the result of disguising where the actual problem is. It's one of the chronic problems with the language.

For an amusing example mostly focused around JS's excessively broad automatic type casting, see this short presentation (https://www.destroyallsoftware.com/talks/wat).

Xuincherguixe
2015-06-03, 02:34 PM
No need. After 3 hours we found the problem. My partner put in a "}" too high in the code.:smallsigh:

Ouch!

I feel like if it took you three hours to find you probably weren't using an IDE. And you probably weren't because your school decided not to use them. While you can write in a plain text editor? I wouldn't recommend it.

Tev
2015-06-03, 10:24 PM
Notepad++ seems fine for JavaScript, at least in this case it would be ok, beacuse it highlights brackets.

Flickerdart
2015-06-03, 11:40 PM
Notepad++ is excellent. Eclipse is good too (yes, for Javascript too, not just Java). If you can get your hands on it, IntelliJ IDEA is really nice.

Alent
2015-06-04, 12:41 AM
Notepad++ seems fine for JavaScript, at least in this case it would be ok, beacuse it highlights brackets.

In the same vein, Sublime Text is also very good.

Tyndmyr
2015-06-04, 10:52 AM
Hey guys, for a project in school, we're trying to create a simple visual novel in javascript. Unfortunately we are receiving a weird error where obj (object) is undefined when its ran normally, but when we use the debugger and walk it through step by step, it goes "Oh, yeah obj is defined and I can work normally now." And then we refresh and its back to undefined. Its seriously frustrating for something so illogical such as obj being both undefined and defined.:smallyuk:

We did borrow the code from an open source example and modified it with some of our code and images. I would post the code, but its in the 1600+ line range and I don't know if it would fit in a forum post.

You frequently get this with an accidentally created race condition. Sticking a pointless dialog box at the top of the code will make this work, because the delay created by responding to the dialog will give you enough time. It's a normal Javascript thing(and part of why I prefer other languages as first languages, since debugging this can be non-obviouis).

factotum
2015-06-04, 03:45 PM
You frequently get this with an accidentally created race condition.

Now there's an interesting way of putting it--you mean there's such a thing as a deliberately created race condition? :smallwink:

Tyndmyr
2015-06-04, 03:54 PM
Now there's an interesting way of putting it--you mean there's such a thing as a deliberately created race condition? :smallwink:

Given the horrible things I've seen coded intentionally, I'm not willing to rule it out. :smallsmile:

Xuincherguixe
2015-06-04, 04:19 PM
One obvious reason to create race conditions is to examine race conditions.

Flickerdart
2015-06-04, 05:17 PM
Now there's an interesting way of putting it--you mean there's such a thing as a deliberately created race condition? :smallwink:
Black magic?

pendell
2015-06-04, 05:24 PM
*Sigh* So I caught a developer trying to hard-code a cleartext password in his code. Shall I make him eat his own intestines, or simply stick his head on a spike as warning to others?

Ha ha only not totally kidding,

Brian P.

Silverraptor
2015-06-04, 06:15 PM
*Sigh* So I caught a developer trying to hard-code a cleartext password in his code. Shall I make him eat his own intestines, or simply stick his head on a spike as warning to others?

Ha ha only not totally kidding,

Brian P.

Could you provide a more thorough explanation for those still moderately new to programming?:smallsmile:

Alent
2015-06-04, 06:51 PM
Could you provide a more thorough explanation for those still moderately new to programming?:smallsmile:

The mistake is not one of programming, but of basic computer security. The average user equivalent is walking into a top secret military base and finding one of the guys wrote his password on a stickit note and taped it to his monitor.

Grinner
2015-06-04, 07:14 PM
Could you provide a more thorough explanation for those still moderately new to programming?:smallsmile:

I should let pendell answer this, but I really want to answer this...

In the event of a widescale security breach, it's best to have user passwords stored in a secure format. This most often means converting the passwords into what are called hashes, which would prevent the intruders from compromising user accounts right away. Cleartext is simple, unhashed text like "ThisIsMyPassword111", whereas the hashed form would look more like "40f240333903fd3cbddd14548dfcfc1b".

It's important to realize that hashing is not the same as encryption. Encrypted data can be converted back to unencrypted data. Hashing produces a sort-of digital "fingerprint", and the actual data is lost.

To give an example, when a user goes to login, he'll enter his password. The server will validate the inputted password by subjecting it to the same hashing algorithm used to create the password. It will then compare the new hash to the stored hash, and if they match, the user is successfully logged in. Otherwise, the password doesn't match the original one.

So when a user tries to recover his password, he has to create an entirely new one, because the server doesn't actually have his original password anymore.

Edit: It seems I misunderstood what transpired. Flickerdart's answer is good.

Flickerdart
2015-06-04, 07:14 PM
Could you provide a more thorough explanation for those still moderately new to programming?:smallsmile:
A non-encrypted (clear text) password means that anyone reading through the code could know what it is. Hit Ctrl+U to bring up a page's source code, and now you can read the code. It's harder for server-side things or compiled things like .exes but not impossible.

Silverraptor
2015-06-04, 08:29 PM
So the guy basically had his password stored within the code?! Please tell me he is mainly a janitor and his only privilege in accessing computers is cleaning out junk files like the recycle bin...


I should let pendell answer this, but I really want to answer this...

In the event of a widescale security breach, it's best to have user passwords stored in a secure format. This most often means converting the passwords into what are called hashes, which would prevent the intruders from compromising user accounts right away. Cleartext is simple, unhashed text like "ThisIsMyPassword111", whereas the hashed form would look more like "40f240333903fd3cbddd14548dfcfc1b".

It's important to realize that hashing is not the same as encryption. Encrypted data can be converted back to unencrypted data. Hashing produces a sort-of digital "fingerprint", and the actual data is lost.

To give an example, when a user goes to login, he'll enter his password. The server will validate the inputted password by subjecting it to the same hashing algorithm used to create the password. It will then compare the new hash to the stored hash, and if they match, the user is successfully logged in. Otherwise, the password doesn't match the original one.

So when a user tries to recover his password, he has to create an entirely new one, because the server doesn't actually have his original password anymore.

Edit: It seems I misunderstood what transpired. Flickerdart's answer is good.

I actually just learned about hashing in class yesterday. Its nice to pleasantly see a refresher on that lesson right here.:smallsmile:

But getting back to the real situation, if he doesn't even have a hasher in his code for password, oh... my...g-

Grinner
2015-06-04, 08:51 PM
So the guy basically had his password stored within the code?! Please tell me he is mainly a janitor and his only privilege in accessing computers is cleaning out junk files like the recycle bin...

I'm gonna go out on a limb and say it was a stop-gap measure while the rest of the code was being put into place. That said, it creates an issue in that if the project was shipped without that little bit of code being revised, yes, bad things could easily result.

It's also possible that it was a legitimate backdoor, but I wouldn't jump to that conclusion.

Solse
2015-06-04, 09:05 PM
*Sigh* So I caught a developer trying to hard-code a cleartext password in his code. Shall I make him eat his own intestines, or simply stick his head on a spike as warning to others?

Ha ha only not totally kidding,

Brian P.
That reminds me, I'm doing some webdev and I store passwords in the database (really just XML as I mentioned earlier) as a hash but I store the user's password in their cookies in plaintext. I should really get around to fixing that -- even though somebody who already has access to a user's browser also probably has access to their account, in the rare case that that isn't true, then my current system would cause the attacker to know the victim's password, which could possibly be used for the victim's accounts on other websites. Now that I think about it, I *really* need to change that.

Grinner
2015-06-04, 09:17 PM
That reminds me, I'm doing some webdev and I store passwords in the database (really just XML as I mentioned earlier) as a hash but I store the user's password in their cookies in plaintext. I should really get around to fixing that -- even though somebody who already has access to a user's browser also probably has access to their account, in the rare case that that isn't true, then my current system would cause the attacker to know the victim's password, which could possibly be used for the victim's accounts on other websites. Now that I think about it, I *really* need to change that.

Do you use SSL? It could also be snatched via packet sniffer on an unencrypted connection.

factotum
2015-06-05, 02:37 AM
To give an example, when a user goes to login, he'll enter his password. The server will validate the inputted password by subjecting it to the same hashing algorithm used to create the password. It will then compare the new hash to the stored hash, and if they match, the user is successfully logged in. Otherwise, the password doesn't match the original one.

You can make it even more secure. In challenge/response authentication, for instance, the password hash itself is never passed over the wire--when a client requests login, the server sends it a randomly-generated challenge. The client hashes that challenge using the password hash as a key then sends the hash-of-a-hash back to the server, which performs the same process to compare the two. Doing it this way means you can't get the password hash stolen by a man-in-the-middle attack.

Tyndmyr
2015-06-05, 01:57 PM
You can make it even more secure. In challenge/response authentication, for instance, the password hash itself is never passed over the wire--when a client requests login, the server sends it a randomly-generated challenge. The client hashes that challenge using the password hash as a key then sends the hash-of-a-hash back to the server, which performs the same process to compare the two. Doing it this way means you can't get the password hash stolen by a man-in-the-middle attack.

That just requires further steps to mitm it. *shrug* The whole point of mitm is that you're grabbing everything, and then passing it on. You don't need the password per se if you have access.

And that's leaving aside the possibility of determining the key from many hashes of known text, which should grow with reuse.

Xuincherguixe
2015-06-05, 03:22 PM
There's a reason I haven't gotten too deep into security. Mostly it's that I just haven't gotten around to it. But it is rather challenging.

Suppose since I'm here any recommendations on reading material and other resources?

Solse
2015-06-05, 03:34 PM
Do you use SSL? It could also be snatched via packet sniffer on an unencrypted connection.

Damn, good point. I suppose that I could store the actual hash of the password in the cookies, but then an attacker who packet sniffs as you pointed out would just be able to set the cookies on their machine to match up with the password hash that they got. Hopefully it would be better than simply storing the password in a plaintext cookie though.

Silverraptor
2015-06-05, 06:27 PM
Anyone here experience in programming in Unix in the language of Perl? I have a computer project that I have to put together in a week where the rest of my class gets 2 weeks because I have to leave for the final week of the term and have to get all my finals and projects done a week early. If someone here knows how to program in Perl that can help me along in finishing my project in time, that would be EXTREMEMLY helpful.:smallsmile:

factotum
2015-06-06, 01:26 AM
That just requires further steps to mitm it. *shrug* The whole point of mitm is that you're grabbing everything, and then passing it on. You don't need the password per se if you have access.

The point is, though, you can't just take the first password hash you intercept and use it to gain access to the system, because the second time a login is attempted a different challenge will be generated, requiring a different hash in reply. Yes, it might be possible to figure out the key from analysing logins, but if the hashes are cryptographically secure and the challenge is properly random then it will take a heck of a lot of them to do this--and since people don't usually log in more than a few times a day, you don't have a lot of data to work with. It could take months or even years to figure out the password via your MITM attack, and 99% of hackers don't have the time or the inclination to spend that long trying to crack a single system.

Xuincherguixe
2015-06-07, 05:04 PM
Anyone here experience in programming in Unix in the language of Perl? I have a computer project that I have to put together in a week where the rest of my class gets 2 weeks because I have to leave for the final week of the term and have to get all my finals and projects done a week early. If someone here knows how to program in Perl that can help me along in finishing my project in time, that would be EXTREMEMLY helpful.:smallsmile:

I think that the number of people reading this thread is fairly small. I'd suggest you keep looking. Ideally what you're looking for is something along the lines of a perl IRC. As you look for communities, read assorted tutorials and documentation. You'll want to skip the stuff you already know since there's a time constraint and all.

I'm not all that great when it comes to learning languages as I tend to go all out. Read things like crazy when the more important thing to do is sit down and start writing code.

caden_varn
2015-06-09, 12:14 PM
Anyone here experience in programming in Unix in the language of Perl? I have a computer project that I have to put together in a week where the rest of my class gets 2 weeks because I have to leave for the final week of the term and have to get all my finals and projects done a week early. If someone here knows how to program in Perl that can help me along in finishing my project in time, that would be EXTREMEMLY helpful.:smallsmile:

What are you after exactly? I am a Unix Perl coder - I may be able to answer a few questions depending on the sort of thing you want to do, but that would be about the limit of it...

kyoryu
2015-06-09, 02:55 PM
I did a ton of perl, about 15 years ago :) I may or may not have useful advice.

shawnhcorey
2015-06-09, 03:07 PM
Anyone here experience in programming in Unix in the language of Perl? I have a computer project that I have to put together in a week where the rest of my class gets 2 weeks because I have to leave for the final week of the term and have to get all my finals and projects done a week early. If someone here knows how to program in Perl that can help me along in finishing my project in time, that would be EXTREMEMLY helpful.:smallsmile:

Yes, I know Perl. But I suggest to take your questions to a Perl site where you may get answers faster.

Some useful Perl links:

Official site (http://www.perl.org/)
Beginners' help (http://learn.perl.org/faq/beginners.html)
Advance help (http://perlmonks.org/)
News (http://perlsphere.net/)
Documentation (http://perldoc.perl.org/)
Online Books (http://www.perl.org/books/library.html)
Real World Books (http://learn.perl.org/books/)
Repository (http://metacpan.org/)
Blog (http://blogs.perl.org/)
Regional groups (http://www.pm.org/)
Videos (http://perltv.org/)

Silverraptor
2015-06-09, 06:16 PM
Don't worry, it should be very basic perl, so it shouldn't be difficult for experienced users. I just dislike unix coding and so its proved troublesome to remember all and to design the code properly. Basically, here are the assignment rules:

-It needs to display some "info" from a flat file,
-It needs to have multi-subroutines.
-It needs to have:
--loops,
--decision processes,
--arithmetic
--comparison
--output


That's all the constraints and rules it needs. The idea I want to have is make a NPC generator. Basically I'd have a few different monsters on a separate file for it to access, be it orc, gnome, troll, etc. Then the user can determine how many of that type of monster to generate, give it a few weapon choices and design a numbered stats attributed to each of the different monsters. Would you guys be able to help me out in the process of designing this and helping it to get it to work?

shawnhcorey
2015-06-09, 06:33 PM
-It needs to display some "info" from a flat file,


OK, start with that. What is the format of the file? Perhaps you want a CSV (Comma-Separated Values) (https://en.wikipedia.org/wiki/Comma-separated_values) or an INI file (https://en.wikipedia.org/wiki/INI_file).

Silverraptor
2015-06-09, 07:26 PM
OK, start with that. What is the format of the file? Perhaps you want a CSV (Comma-Separated Values) (https://en.wikipedia.org/wiki/Comma-separated_values) or an INI file (https://en.wikipedia.org/wiki/INI_file).

I'm trying to fill the file as a separate races with number stats and weapons to choose from. How would I go about listing that?

shawnhcorey
2015-06-09, 07:51 PM
I'm trying to fill the file as a separate races with number stats and weapons to choose from. How would I go about listing that?

You could put them in a CSV:

-race,-level,-hp
orc,1,8
goblin,1,6
ogre,3,24

-weapon,-damage
spear,2d6
long sword,1d8
short sword,1d6
dagger,1d4

Silverraptor
2015-06-09, 08:29 PM
You could put them in a CSV:

-race,-level,-hp
orc,1,8
goblin,1,6
ogre,3,24

-weapon,-damage
spear,2d6
long sword,1d8
short sword,1d6
dagger,1d4


oh thanks. So I'll just vi a file in that format and that's basically all I need?

ChristianSt
2015-06-10, 01:29 AM
oh thanks. So I'll just vi a file in that format and that's basically all I need?

From a data source perspective, yes. As long as your data is relatively nice and simple CSV is a fine choice to store your data. From your program you can then simply read the file line by line and split the line into an array an go from there.

I recommend to actually make multiple files, because storing different data in different files makes things much simpler.

If your data gets more complicated you probably want to use some other format, though they are harder to access/parse. For example XML is a quite useful format for more complicated stuff, but you basically need to include a library to do the parsing for you. Well, unless you want to write a parser :smallwink:

factotum
2015-06-10, 02:29 AM
If your data gets more complicated you probably want to use some other format, though they are harder to access/parse. For example XML is a quite useful format for more complicated stuff, but you basically need to include a library to do the parsing for you. Well, unless you want to write a parser :smallwink:

I would be inclined to go straight for XML in this instance--it's pretty much designed for a data structure like this. e.g. you could have a bunch of entries like:

<RACE>
<NAME>ORC</NAME>
<LEVEL>1</LEVEL>
<HP>8</HP>
</RACE>

...and so on, adding additional information to each record as required.

NichG
2015-06-10, 03:36 AM
Every complexity you add in the data storage format is going to add complexity both in the reading/writing capabilities in your main code, as well as in the tool choice you have available to you in order to edit your storage files. So you have to balance that complexity against the amount of data you have and how difficult it will be to work with and maintain that data using a less explicitly organized format.

E.g. if you have 10 data rows with 4 features each, and every row has every feature, XML is really overkill. But if you might eventually need 1000 rows, with some features only being associated with some rows, etc, etc...

Either way, my preference would be to choose formats that are convenient both to your code and to your favorite data entry software. So if your language has readily available libraries for reading in some particular format that you also happen to have software to edit easily, just go ahead and use that format. That's one big reason I might prefer something like CSV over XML - I can edit it in gnumeric and import it with one or two lines of code in most languages.

shawnhcorey
2015-06-10, 06:37 AM
I would be inclined to go straight for XML in this instance--it's pretty much designed for a data structure like this. e.g. you could have a bunch of entries like:

<RACE>
<NAME>ORC</NAME>
<LEVEL>1</LEVEL>
<HP>8</HP>
</RACE>

...and so on, adding additional information to each record as required.

Except that he did specify a flat file. :)

caden_varn
2015-06-10, 06:51 AM
Given a week to do the whole program I would tend to stick to something simpler like a csv. Just be absolutely sure you don't need commas in the data itself. I tend to use tab-delimited, ; delimited or |-delimited for this reason, but it won't be an issue unless you let it be.

The other advice I will give at this stage is to keep the original spec. reasonably simple - don't start with all the stats, AC, HP, equipment. Make a basic program that does one part to completion (say racial choice & stat-generation), then once this is working and tested start adding more elements if you want. This makes it much easier to have something complete to hand in in your limited timeframe, even if it does not have all the functionality you originally planned.

If you plan the whole complex thing out, you may only get halfway through before the deadline, which I suspect is going to be worse for your marks than a more basic program that actually works.

Xuincherguixe
2015-06-10, 07:06 AM
Another option, and not sure that I'd actually suggest it would be JSON. Has a lot of the same things going for it as XML but you say it with a lot less space. It's also not exclusively a JavaScript thing but the name has kind of stuck.

CSVs are probably your best bet for a simple project though.

Flickerdart
2015-06-10, 09:22 AM
For example XML is a quite useful format for more complicated stuff, but you basically need to include a library to do the parsing for you. Well, unless you want to write a parser :smallwink:
Everyone knows you can just parse XML with regex. :smallamused:

Xuincherguixe
2015-06-10, 09:27 AM
Everyone knows you can just parse XML with regex. :smallamused:

Don't mind me. I'm just going to have some post traumatic flashbacks in the corner here and sob uncontrollably.

shawnhcorey
2015-06-10, 09:37 AM
Everyone knows you can just parse XML with regex. :smallamused:

I know you're being facetious but many readers won't have the experience to realize this. To parse XML, you need a full push-down-stack-with-tokenizer parser. For Perl, it's much easier to a CPAN module.

pendell
2015-06-10, 10:00 AM
Could you provide a more thorough explanation for those still moderately new to programming?:smallsmile:

Other people have already answered, but in brief:

1) Cleartext passwords are bad because they are easily stolen. Even in source code, someone scanning the source code instantly has access to that account.

2) Hard-coding passwords is also a terrible idea. If you change the password (as you should, on a regular basis), you also have to recompile the code and distribute the new program to everywhere as an update.

There are a number of solutions to this, some better and some worse. Storing the passwords in an encrypted format is best, if you can swing it. Storing the password in a digested or hashed format (as in Unix's /etc/shadow file) is better than nothing, but still not good if you can help it. The reason is that if someone gets access to a hashed password, they can crack it by brute force, trying multiple combinations against a common hashing algorithm until a hash of a guess matches the hash in the file.

For instance let's say I have the string

joe:abedc#44

So user 'joe' has a password which hashes to 'abedc#44'.

If I'm a hacker and i have access to this, I just move the file to my local computer and pull up a hashprogram against a dictionary or set of dates or what not.

guess 'birthday' : q4wrdfasg!!
guess 'baseball' : zxfgwrwer33
guess 'flittershy' : abedc#44

SOLVED. Joe's password is 'flittershy'.

You can't do this with proper encryption, because an encryption can't be solved with a generally-available algorithm. Instead, you need the algorithm plus the specific values used as keys -- inputs to the algorithm -- the private and public keys of the encryption.

So hashing isn't really going to protect you from a serious hacker, but it's better than just leaving the passwords out in clear.

When you put the password in cleartext AND hard-code it -- well, that's just plain lazy.

...

I suppose it would make sense if you were never, ever going to change the password -- if it was something done purely to bypass an unnecessary security filter -- and if you don't care at all about the stuff the password is supposed to protect. Even then, I prefer to store anything capable of changing in a parameter .xml file or a database. That way, if it needs changing, you don't need to rebuild the entire program!

Respectfully,

Brian P.

Silverraptor
2015-06-10, 10:22 AM
Okay. Some of the perl stuff went over my head (And when I said some, I mean most of it). What I understand is to make a separate file in the format shawn put and start coding by making sure the program can initially access the program and perform the loops and everything afterwards. Also, I am trying to make this as simple as possible. My teacher said he doesn't want anything complex, so just 2-4 creatures with the bare basic of stats and items to attach to them while also having an output of those stats and items once they are created is all I need. This program isn't going to be used in conjuncture with another program later on, this is the final project in my class. The reason I'm in a rush is the rest of the class has next week to finish the project. I, however, am leaving a week early so I need to have it done before then.

factotum
2015-06-10, 10:36 AM
Except that he did specify a flat file. :)

An XML file still fulfils the definition of a flat file in computer terms--it's a single file containing all the information for your database in a mostly human-readable and human-editable format. It's no different from JSON, INI, CSV, or any other text file data format in that regard.

shawnhcorey
2015-06-10, 10:58 AM
An XML file still fulfils the definition of a flat file in computer terms--it's a single file containing all the information for your database in a mostly human-readable and human-editable format. It's no different from JSON, INI, CSV, or any other text file data format in that regard.

It is when it comes to parsing it. CSV and tab-delimited are the simplest, INI and JSON in between, and XML is the most complex. Since he only needs it for one project, I think he should go with the simplest.

kyoryu
2015-06-10, 12:15 PM
Yeah, CSV is probably the best choice in this situation.

If you really need a full text-based object serialization method, I'd always recommend JSON or YAML over XML *unless* you need others to automatically generate proxies based on an .xsd.

caden_varn
2015-06-11, 04:59 AM
Okay. Some of the perl stuff went over my head (And when I said some, I mean most of it). What I understand is to make a separate file in the format shawn put and start coding by making sure the program can initially access the program and perform the loops and everything afterwards. Also, I am trying to make this as simple as possible. My teacher said he doesn't want anything complex, so just 2-4 creatures with the bare basic of stats and items to attach to them while also having an output of those stats and items once they are created is all I need. This program isn't going to be used in conjuncture with another program later on, this is the final project in my class. The reason I'm in a rush is the rest of the class has next week to finish the project. I, however, am leaving a week early so I need to have it done before then.

THis sounds about right. You say you need:
--loops,
Reading through the file line by line shows this
--decision processes,
I assume the user will 'pick' a creature to output somehow (could be a command line parameter to make life a bit easier). This wouold take care of that
--arithmetic
Not sure what you plan here. You could do random stat generation (3d6 for ease) - that would cover loops and arithmetic
--comparison
Choosing a creature would handle this, otherwise random stat generation of 4d6 drop lowest would handle this. A bit trickier though, might be a bit more complex than you want depending on your confidence in your Perl knowledge
--output
Writing out to screen and or file handles this

Good luck, hope it goes well!

-D-
2015-06-11, 05:45 AM
Everyone knows you can just parse XML with regex. :smallamused:

Hahaha, you funny guy you.

T̴̡ͯ̀̐̑͊̇҉̥̰̺̥̯̰H͙̎̓͂ͭͅE̵̟̬̠̖̻͖ͬ̎͐̋͆͊̐̚ ̖͖̘͆ͤ̊̿͋̇͛͒ͮ͜͢R̩̪̪̥̝̯͔̰̃̓͛̒͊̇̓E̹̩ͮ̅́͐̄͗͂͠Gͪ̎͗̃ͨ̈́̂̔ ̈͏̡͇̺̟͔̩̕E̳̟͍̔̓̽̔͂X̳͍͎̊ͧ ̳̖̺͔͉̳̞ͬͯ͌͂̽ͤH̪̜͈̟̻̰̄͊͗̄ͨ̔͢U̟͔̪̟͙̙̠̼̜̅͊̾ͨ͆̍̓Ṅͯͪ͊̒ ̪͔͎̈̑G̗̖̞̜͔̓ͭ̊ͭͩ̇̎́̌E̢̤̺̘̜̜̰͚̓̓ͩ̑ͫR̴͙̭̺̬̲͑̾͒ͨ͜͝S̋̐ ̫̉̋ ̵̧̬̞̜͔̤ͫͧ̆ͤͅͅF̵̩̭̣̻͈̩̯ͥ̅͊̃̒ͨ͢ͅO̧̲̤̘̦̼̎̒̐̃͋͛̚R͒́ͨͧ̚ ̯̫̬͚͖͐ͅ ̼̩͇̫͆͒̌ͫ͂S̝̞͖ͫ̆ͪ̊̇̏ͭ͟Ỏ̷̼̥̿ͦ͒ͦ̃ͤ̀U̢̺̥̯͂̄͋ͣ̊̏L̈́͑ͣ͗͌ ̸̢͈̳͔̜̝̯̺͉̅̾̂͜S̙̱̥̬͒̅ͣ̽̽͝

Xuincherguixe
2015-06-11, 12:04 PM
Hahaha, you funny guy you.

T̴̡ͯ̀̐̑͊̇҉̥̰̺̥̯̰H͙̎̓͂ͭͅE̵̟̬̠̖̻͖ͬ̎͐̋͆͊̐̚ ̖͖̘͆ͤ̊̿͋̇͛͒ͮ͜͢R̩̪̪̥̝̯͔̰̃̓͛̒͊̇̓E̹̩ͮ̅́͐̄͗͂͠Gͪ̎͗̃ͨ̈́̂̔ ̈͏̡͇̺̟͔̩̕E̳̟͍̔̓̽̔͂X̳͍͎̊ͧ ̳̖̺͔͉̳̞ͬͯ͌͂̽ͤH̪̜͈̟̻̰̄͊͗̄ͨ̔͢U̟͔̪̟͙̙̠̼̜̅͊̾ͨ͆̍̓Ṅͯͪ͊̒ ̪͔͎̈̑G̗̖̞̜͔̓ͭ̊ͭͩ̇̎́̌E̢̤̺̘̜̜̰͚̓̓ͩ̑ͫR̴͙̭̺̬̲͑̾͒ͨ͜͝S̋̐ ̫̉̋ ̵̧̬̞̜͔̤ͫͧ̆ͤͅͅF̵̩̭̣̻͈̩̯ͥ̅͊̃̒ͨ͢ͅO̧̲̤̘̦̼̎̒̐̃͋͛̚R͒́ͨͧ̚ ̯̫̬͚͖͐ͅ ̼̩͇̫͆͒̌ͫ͂S̝̞͖ͫ̆ͪ̊̇̏ͭ͟Ỏ̷̼̥̿ͦ͒ͦ̃ͤ̀U̢̺̥̯͂̄͋ͣ̊̏L̈́͑ͣ͗͌ ̸̢͈̳͔̜̝̯̺͉̅̾̂͜S̙̱̥̬͒̅ͣ̽̽͝


Funny. I'd imagine that if one were to write a regular expression capable of parsing XML, it would look like that.

shawnhcorey
2015-06-11, 12:14 PM
Funny. I'd imagine that if one were to write a regular expression capable of parsing XML, it would look like that.

AFAIK, Perl is the only language with a regular expression engine capable of parsing XML. That's because its RE is a Turing-complete programming language in itself.

Silverraptor
2015-06-11, 12:35 PM
THis sounds about right. You say you need:
--loops,
Reading through the file line by line shows this
--decision processes,
I assume the user will 'pick' a creature to output somehow (could be a command line parameter to make life a bit easier). This wouold take care of that
--arithmetic
Not sure what you plan here. You could do random stat generation (3d6 for ease) - that would cover loops and arithmetic
--comparison
Choosing a creature would handle this, otherwise random stat generation of 4d6 drop lowest would handle this. A bit trickier though, might be a bit more complex than you want depending on your confidence in your Perl knowledge
--output
Writing out to screen and or file handles this

Good luck, hope it goes well!
Yeah. That's why I decided to form that as a project. I just need help making sure I've done it right by the time I have to turn it in.

halfeye
2015-06-11, 02:09 PM
Yeah. That's why I decided to form that as a project. I just need help making sure I've done it right by the time I have to turn it in.
You seem to be running a big risk of getting other people to do your homework for you. The disadvantage of that is not knowing what they did. You'd be better off presenting something that doesn't work, and letting people criticise it.

HalfTangible
2015-06-11, 03:35 PM
C# script in Unity:

if (GUI.Button (Rect (10, 70, 50, 30), "Click"))
Debug.Log ("Button clicked");
This code is giving me 3 errors:
-Expression denotes a `type', where a `variable', `value' or `method group' was expected (44,33)
-The best overloaded method match for `UnityEngine.GUI.Button(UnityEngine.Rect, string)' has some invalid arguments (44, 25)
-Argument `#1' cannot convert `object' expression to type `UnityEngine.Rect' (44,25)

No idea what I'm doing wrong or how to fix. Help? =(

kyoryu
2015-06-11, 03:38 PM
C# script in Unity:

if (GUI.Button (Rect (10, 70, 50, 30), "Click"))
Debug.Log ("Button clicked");
This code is giving me 3 errors:
-Expression denotes a `type', where a `variable', `value' or `method group' was expected (44,33)
-The best overloaded method match for `UnityEngine.GUI.Button(UnityEngine.Rect, string)' has some invalid arguments (44, 25)
-Argument `#1' cannot convert `object' expression to type `UnityEngine.Rect' (44,25)

No idea what I'm doing wrong or how to fix. Help? =(

new Rect(...)

caden_varn
2015-06-11, 03:59 PM
If it runs and gives he output you expect, you have done it right. Unless we are gonna start a lesson on writing test plans, that is all you need. And while test plans are required in real-world apps, I think going into that whole area is more than a bit above and beyond what you need. Get it working, test it gives the otput you expect to multiple input criteria, and it's shiny

HalfTangible
2015-06-11, 04:06 PM
If it runs and gives he output you expect, you have done it right. Unless we are gonna start a lesson on writing test plans, that is all you need. And while test plans are required in real-world apps, I think going into that whole area is more than a bit above and beyond what you need. Get it working, test it gives the otput you expect to multiple input criteria, and it's shinyWhy would I be asking for help if it was working? :smallconfused::smalltongue:


new Rect(...)

Ah, there we go! Much obliged.

crayzz
2015-06-12, 06:18 PM
I started progamming with matlab scripts. I've gone through Codecademy's Python lessons, and some of their Ruby lessons. I enjoy programming and, while my memory for proper syntax is poor, I think I'm pretty good at it. Except I don't know where to go now. I want to keep in practice (e.g. when possible, I'll write my own functions in matlab even if there is a prebuilt equivalent), but I don't really know where I might apply what I know.

So where might I go from here?

Grinner
2015-06-12, 06:56 PM
So where might I go from here?

You can generally go down or up.

By "down", I mean you can try learning about how the computer works on a lower level than what you're programming at. Perhaps you could learn C?

By "up", I mean you can try learning about some of the more advanced applications of computers. Maybe look up a tutorial for Lisp or maybe an esoteric language.

You could also get your hands dirty and start working on a project. There's no teacher like experience, after all. Maybe try writing a simple game in pygame?

Silverraptor
2015-06-12, 07:10 PM
I could use help trying to get some of my code to work correctly in perl. I'm trying to call a subroutine where I want to ask the user to enter (or effectively "guess" the password as I'm going to include the password in the code). The main thing is I want them to only have 3 chances at it before it ends the program with the message "You are out of attempts" or something similar. Could you guys take a look and tell me how to adjust it? I managed to get it allow for someone to try guessing the password, but it keeps going in an infinite loop and not the 3 attempts I want.


sub password {
print "Please enter your password: ";
chomp($password=<STDIN>);
until ($password eq "yes") {
sleep(1);
print "Incorrect password!";
chomp($password=<STDIN>);
}
print "That's the password!\n";
}

$count=0;
while (count <= 3) {
$count &password();
$count++;
if ($count == 3){print "You are out of password attempts. \n";}
}

If the code looks ugly and mashed together, its because I've been taking examples from my text book and sort of mashing them together. Again, any perl users, if you could help me with this I would be extremely grateful!:smallsmile:

crayzz
2015-06-12, 07:26 PM
I'll admit that I don't know perl at all, but this bit seems suspect:


until ($password eq "yes") {
sleep(1);
print "Incorrect password!";
chomp($password=<STDIN>);

Does it ask the user to guess the password again after they've already guess right?



I have tried learning C multiple times now. Everytime I do, something goes wrong with the IDE install. I suppose I could always try again.

Lisp sounds interesting, as does building a game, though I do find I prefer programming for practical use.

Grinner
2015-06-12, 07:45 PM
I have tried learning C multiple times now. Everytime I do, something goes wrong with the IDE install. I suppose I could always try again.

You might consider using a command-line compiler like tcc (http://bellard.org/tcc/). You can learn a lot by getting back to the basics.


Lisp sounds interesting, as does building a game, though I do find I prefer programming for practical use.

Perhaps Java? You may have learned about classes with Python, but Python doesn't actually require the use of classes. Java is all about classes, and it can do some very fun things with them.

Silverraptor
2015-06-12, 08:03 PM
I'll admit that I don't know perl at all, but this bit seems suspect:


until ($password eq "yes") {
sleep(1);
print "Incorrect password!";
chomp($password=<STDIN>);

Does it ask the user to guess the password again after they've already guess right?



Yeah, that is also a problem. I have to ctrl+c to get the program to stop. Trying to figure out how to have it stop naturally both after they guess it right or after they incorrectly guessed it 3 times.

crayzz
2015-06-12, 08:30 PM
I have downloaded GNU CLISP, and will play around with that for a bit. Java is definitely an option I am considering. I am still very open to suggestions on where to go from here.


Yeah, that is also a problem.

Alright, I am pretty sure I know the problem. Again, I don't know perl.


until ($password eq "yes") {
sleep(1);
print "Incorrect password!";
chomp($password=<STDIN>);

This loop runs until password = yes, repeatedly asking for a new password attempt. You don't want that. You want it to run until password = yes or until the user has guessed three times. The problem is that your counter sits outside this subroutine entirely. You want the counter to either a) sit inside the subroutine, or b) have an if statement instead of a loop.

If I didn't screw up the syntax, this should work:

EDIT

Deleted code as I realized it did not actually work and that I am, in fact, too tired to fix it.

Avloren
2015-06-12, 11:47 PM
I could use help trying to get some of my code to work correctly in perl. I'm trying to call a subroutine where I want to ask the user to enter (or effectively "guess" the password as I'm going to include the password in the code). The main thing is I want them to only have 3 chances at it before it ends the program with the message "You are out of attempts" or something similar. Could you guys take a look and tell me how to adjust it? I managed to get it allow for someone to try guessing the password, but it keeps going in an infinite loop and not the 3 attempts I want.


sub password {
print "Please enter your password: ";
chomp($password=<STDIN>);
until ($password eq "yes") {
sleep(1);
print "Incorrect password!";
chomp($password=<STDIN>);
}
print "That's the password!\n";
}

$count=0;
while (count <= 3) {
$count &password();
$count++;
if ($count == 3){print "You are out of password attempts. \n";}
}

If the code looks ugly and mashed together, its because I've been taking examples from my text book and sort of mashing them together. Again, any perl users, if you could help me with this I would be extremely grateful!:smallsmile:

I can't really help you with Perl syntax, but I can tell you what the logical problem is. Your code, in simplified English, says this:


Repeat the following 3 times:
Repeat the following until the password is "yes":
Ask the user for the password

See the problem? You have two loops ("while" or "until" or any variation thereof) where you want to have only one. The inner loop (your "until" statement) will repeat infinitely until it gets the right password, and then the outer loop (your "while" statement) will repeat that whole process - the entire inner loop, with the infinite repeats until it gets the right password - 3 times over. What your code really needs to say (sorry, in English again, if I knew Perl at all I'd give you real code):


Repeat the following 3 times OR until the password is "yes":
Ask the user for the password


If you have more than one total "while" or "until", you have too many loops (for this particular problem, anyway). One approach would be to eliminate the "until", and inside that subroutine just ask for a password once and return a value indicating whether or not it got the correct password. Then your while loop can decide (based on the return value) whether to increment the counter and keep trying up to 3 attempts, or accept the password and move on.

Solse
2015-06-13, 12:06 AM
You might consider using a command-line compiler like tcc (http://bellard.org/tcc/). You can learn a lot by getting back to the basics.


I second tcc. I learned to program using gcc, but tcc is great because of how lightweight it is. I've run it on small, underpowered Android devices at one point.

shawnhcorey
2015-06-13, 06:41 AM
I could use help trying to get some of my code to work correctly in perl. I'm trying to call a subroutine where I want to ask the user to enter (or effectively "guess" the password as I'm going to include the password in the code). The main thing is I want them to only have 3 chances at it before it ends the program with the message "You are out of attempts" or something similar. Could you guys take a look and tell me how to adjust it? I managed to get it allow for someone to try guessing the password, but it keeps going in an infinite loop and not the 3 attempts I want.


Try this:

#!/usr/bin/env perl

use strict;
use warnings;

sub guess_password {
my $answer = shift @_;
my $attempts = shift @_;

for my $count ( 1 .. $attempts ){
print "\nGuess the password: ";
chomp( my $response = <STDIN> );

if( $response eq $answer ){
print "That's the password!\n";
return;
}

print "Incorrect password!\n";
}

print "Failed after $attempts tries\n";
return;
}

guess_password( 'yes', 3 );

Xuincherguixe
2015-06-13, 08:03 AM
I have downloaded GNU CLISP, and will play around with that for a bit. Java is definitely an option I am considering. I am still very open to suggestions on where to go from here.

As far as free resources go, I found this book (http://www.gigamonkeys.com/book/) and this tutorial (http://art2.ph-freiburg.de/Lisp-Course) pretty good. The tutorial isn't common lisp, but it has a lot going for it. There's an interpreter that's always there you can pull up. I'm pretty inexperienced with Lisp though so I don't know all the resources out there.

Silverraptor
2015-06-13, 12:57 PM
Try this:

#!/usr/bin/env perl

use strict;
use warnings;

sub guess_password {
my $answer = shift @_;
my $attempts = shift @_;

for my $count ( 1 .. $attempts ){
print "\nGuess the password: ";
chomp( my $response = <STDIN> );

if( $response eq $answer ){
print "That's the password!\n";
return;
}

print "Incorrect password!\n";
}

print "Failed after $attempts tries\n";
return;
}

guess_password( 'yes', 3 );


This looks great!:smallsmile: Could you break it down for me so I make sure I understand it all?

shawnhcorey
2015-06-13, 05:57 PM
This looks great!:smallsmile: Could you break it down for me so I make sure I understand it all?


#!/usr/bin/env perl
# the first line is called the she-bang line
# in Linux, it tells the shell which program to run to interpret the file

use strict; # stop silly mistakes like misspelled variables
use warnings; # warning about silly mistakes like undef scalars

# prompts the user to guess a password
sub guess_password {

# shift the parameters off the parameter array @_
my $answer = shift @_;
my $attempts = shift @_;

# limit the attempts by the given parameter
for my $count ( 1 .. $attempts ){

# prompt the user
print "\nGuess the password: ";

# get the user's response and remove the trailing newline, if any
chomp( my $response = <STDIN> );

# was the user correct?
if( $response eq $answer ){

# yes, tell him so
print "That's the password!\n";

# all done, the user got it correct
return;
}
# end the if, the user was not correct

# tell him so
print "Incorrect password!\n";

# end for loop; another attempt, maybe
}
# all attempts done

# user failed; tell him so
print "Failed after $attempts tries\n";

# go back to caller
return;
}

# prompt the user to guess the password 'yes' in 3 guesses
guess_password( 'yes', 3 );

Silverraptor
2015-06-13, 07:26 PM
#!/usr/bin/env perl
# the first line is called the she-bang line
# in Linux, it tells the shell which program to run to interpret the file

use strict; # stop silly mistakes like misspelled variables
use warnings; # warning about silly mistakes like undef scalars

# prompts the user to guess a password
sub guess_password {

# shift the parameters off the parameter array @_
my $answer = shift @_;
my $attempts = shift @_;

# limit the attempts by the given parameter
for my $count ( 1 .. $attempts ){

# prompt the user
print "\nGuess the password: ";

# get the user's response and remove the trailing newline, if any
chomp( my $response = <STDIN> );

# was the user correct?
if( $response eq $answer ){

# yes, tell him so
print "That's the password!\n";

# all done, the user got it correct
return;
}
# end the if, the user was not correct

# tell him so
print "Incorrect password!\n";

# end for loop; another attempt, maybe
}
# all attempts done

# user failed; tell him so
print "Failed after $attempts tries\n";

# go back to caller
return;
}

# prompt the user to guess the password 'yes' in 3 guesses
guess_password( 'yes', 3 );


Thank you so much. I understood most of it except for the commands for the parameters. I now know those mean input parameters now thanks to you comments.:smallsmile:

shawnhcorey
2015-06-13, 07:37 PM
Thank you so much. I understood most of it except for the commands for the parameters. I now know those mean input parameters now thanks to you comments.:smallsmile:

That's one of the two popular ways of doing it. The other you will see is this:

my ( $answer, $attempts ) = @_;


You might also see this but it's very rare:

my $answer = $_[0];
my $attempts = $_[1];

HalfTangible
2015-06-15, 12:30 PM
Making a game. I want to display a pair of variables on a GUI in C# (in particular, Health / MaxHealth) that update when their values change.

It doesn't need to be fancy, I just want to show it on-screen in game.

I figure that the values will go into the update function (possibly with something that clears the screen first) but I'm still not really sure what commands to put in to display the text in a certain area.

Or how to clear a screen without wiping out the attack and spell buttons >.>

... How would I go about doing that? =(

This is what I've got so far in the GUI code itself, comments and all:


using UnityEngine;
using System.Collections;

public class BattleGUI : MonoBehaviour {

/*private string playerName;
private int HP;
private int MP;
private int HPmax;
private int MPmax;*/
private Attack Melee = new Attack();
private Laser Spell = new Laser();
//private string temp = "Test";

//private string BadName;
//private int HPBad;
//private int MPBad;
//private int HPmaxBad;
//private int MPmaxBad;

// Use this for initialization
void Start () {

/*playerName = GameInformation.PlayerName;
HP = GameInformation.Health;
HPmax = GameInformation.HealthMax;
MP = GameInformation.Mana;
MPmax = GameInformation.ManaMax;*/

//BadName = BattleStateStart.newEnemy.CharacterClassName;
//HPBad = BattleStateStart.newEnemy.Health;
//MPBad = BattleStateStart.newEnemy.Mana;
//HPmaxBad = BattleStateStart.newEnemy.HealthMax;
//MPmaxBad = BattleStateStart.newEnemy.ManaMax;

}

// Update is called once per frame
void Update () {

}

void OnGUI(){
//You can combine a for loop with an abilities list/array in
//GameInformation to create an action bar with as many buttons
//as abilities. If need be.

//Buttons for player's moves GameInformation.Move1.AbilityName
//GUI.Button (new Rect Screen.width-200.0f, Screen.height-50.0f, 75.0f, 30.0f);
//This works!
//if (GUI.Button (new Rect (10, 70, 50, 30), "Click"))

//GameInformation.Move1.AbilityName;
//GUI.Button (new Rect Screen.width-100.0f, Screen.height-50.0f, 75.0f, 30.0f);
//GameInformation.Move2.AbilityName;
//Show Health for opponent
//Show player information

if (TurnBasedCombatStateEngine.currentState == TurnBasedCombatStateEngine.BattleStates.PLAYERCHOI CE) {
DisplayPlayersChoice ();
}
}

private void DisplayPlayersChoice()
{
if (GUI.Button (new Rect (Screen.width - 200, Screen.height - 50, 75, 30), "Attack")) {
Debug.Log ("Attack (Strength: " + GameInformation.Offense + " + " + Melee.AbilityPower + ".)");
TurnBasedCombatStateEngine.currentState = TurnBasedCombatStateEngine.BattleStates.ENEMYCHOIC E;
}
if (GUI.Button (new Rect (Screen.width - 100, Screen.height - 50, 75, 30), "Laser")){
Debug.Log ("Laser (Strength: " + Spell.AbilityPower + ", Mana cost: " + Spell.ManaCost + ".)");
TurnBasedCombatStateEngine.currentState = TurnBasedCombatStateEngine.BattleStates.ENEMYCHOIC E;
}

}
}

Grinner
2015-06-15, 01:30 PM
I figure that the values will go into the update function (possibly with something that clears the screen first) but I'm still not really sure what commands to put in to display the text in a certain area.

Or how to clear a screen without wiping out the attack and spell buttons >.>

... How would I go about doing that? =(

I can't say I know much about Unity, but in games, you typically wipe the entire screen each frame and re-render everything...If I'm reading your code right, it waits until it's the player's turn and then renders a couple of buttons labelled "Attack" and "Laser"?

Where is OnGUI() called, and for that matter, is it perfectly necessary to display the player's menu during the opponent's turn?

If keeping the GUI each frame is completely necessary, you could try something like this

private void DisplayPlayersChoice()
{

if (GUI.Button (new Rect (Screen.width - 200, Screen.height - 50, 75, 30), "Attack")) {
if (TurnBasedCombatStateEngine.currentState == TurnBasedCombatStateEngine.BattleStates.PLAYERCHOI CE) {
Debug.Log ("Attack (Strength: " + GameInformation.Offense + " + " + Melee.AbilityPower + ".)");
TurnBasedCombatStateEngine.currentState = TurnBasedCombatStateEngine.BattleStates.ENEMYCHOIC E;
}
}
if (GUI.Button (new Rect (Screen.width - 100, Screen.height - 50, 75, 30), "Laser")){
if (TurnBasedCombatStateEngine.currentState == TurnBasedCombatStateEngine.BattleStates.PLAYERCHOI CE) {
Debug.Log ("Laser (Strength: " + Spell.AbilityPower + ", Mana cost: " + Spell.ManaCost + ".)");
TurnBasedCombatStateEngine.currentState = TurnBasedCombatStateEngine.BattleStates.ENEMYCHOIC E;
}
}
}

I'm not sure if that GUI.Button() call is blocking or non-blocking, though...

Edit: Oh, and I think you'd need to call DisplayPlayersChoice() within Update().

HalfTangible
2015-06-15, 02:53 PM
I can't say I know much about Unity, but in games, you typically wipe the entire screen each frame and re-render everything...If I'm reading your code right, it waits until it's the player's turn and then renders a couple of buttons labelled "Attack" and "Laser"?

If keeping the GUI each frame is completely necessary, you could try something like this

private void DisplayPlayersChoice()
{

if (GUI.Button (new Rect (Screen.width - 200, Screen.height - 50, 75, 30), "Attack")) {
if (TurnBasedCombatStateEngine.currentState == TurnBasedCombatStateEngine.BattleStates.PLAYERCHOI CE) {
Debug.Log ("Attack (Strength: " + GameInformation.Offense + " + " + Melee.AbilityPower + ".)");
TurnBasedCombatStateEngine.currentState = TurnBasedCombatStateEngine.BattleStates.ENEMYCHOIC E;
}
}
if (GUI.Button (new Rect (Screen.width - 100, Screen.height - 50, 75, 30), "Laser")){
if (TurnBasedCombatStateEngine.currentState == TurnBasedCombatStateEngine.BattleStates.PLAYERCHOI CE) {
Debug.Log ("Laser (Strength: " + Spell.AbilityPower + ", Mana cost: " + Spell.ManaCost + ".)");
TurnBasedCombatStateEngine.currentState = TurnBasedCombatStateEngine.BattleStates.ENEMYCHOIC E;
}
}
}

I'm not sure if that GUI.Button() call is blocking or non-blocking, though...
...That doesn't actually answer my question. I wanted to know how to display text on the screen that would reflect the player's current HP and Mana.

... In fact, I'm not entirely sure what's been changed :smallconfused:


Edit: Oh, and I think you'd need to call DisplayPlayersChoice() within Update().

Nah, it already displays the buttons.


Where is OnGUI() called, and for that matter, is it perfectly necessary to display the player's menu during the opponent's turn?

I'll be honest, I don't really know how OnGUI works, but it doesn't need to be called. It already displays the stuff.

Grinner
2015-06-15, 03:24 PM
...That doesn't actually answer my question. I wanted to know how to display text on the screen that would reflect the player's current HP and Mana.

... In fact, I'm not entirely sure what's been changed :smallconfused:

Again. I've never used Unity. I don't know the relevant function. All I can tell you is some basic principle of game architecture gleaned from years of reading tutorials.

To your code, I added a pair of if statements, so that if DisplayPlayerChoices() is called from Update(), it should render the GUI every frame. However, the GUI should only work if it's the player's turn. From there, it's just a matter of adding to Update() your screen clear function and whatever function will render an HP bar.

I'm sorry if I sound a little pissy right now, but I've got a few things on my mind. I'm just trying to help you out in whatever way I can.

Xuincherguixe
2015-06-15, 03:35 PM
It's been awhile since I've used Unity and the documentation wasn't complete when I looked into things. So I may get this a bit wrong

OnGUI is an event handler. So every time you click on a button or widget, OnGUI will be called.

Update is called once every frame. So if your game is running at 60 frames per second, it would be called 60 times.


Quick google search and I find labels (http://docs.unity3d.com/ScriptReference/GUI.Label.html). Think that might be what you're looking for.

factotum
2015-06-16, 01:49 AM
However, I vaguely remembered something I'd learned at some point, and changed the angle brackets around the header file to quotation marks. When I compiled this, it did exactly what I wanted it to. Where did the difference lie?

The difference lies in the order in which the preprocessor searches directories for the header files (more info available in the GCC documentation, it's too long to type out here). What that must mean is that you have two copies of ncurses.h on your system, and the preprocessor uses a different one depending on what search order it uses; one of the header files works properly, the other doesn't.

kyoryu
2015-06-21, 10:33 PM
And, although it compiled (using the command gcc foo.c -lncurses -o foo), when run it did nothing. However, I vaguely remembered something I'd learned at some point, and changed the angle brackets around the header file to quotation marks. When I compiled this, it did exactly what I wanted it to. Where did the difference lie?

#include "file" searches project files
#include <file> searches headers, and will prefer *system* headers to project ones.

So chances are there was an ncurses.h file in your project dir you wanted to use, and a system one located somewhere else.

Errata
2015-06-23, 02:55 PM
#include "file" searches project files
#include <file> searches headers, and will prefer *system* headers to project ones.

Another difference is that since it's for system headers, which you're not supposed to modify, the compiler may cache the system header info somewhere, and not actually read the file every time you compile. That's bad if it's not actually a system file, but a project file. You may modify it and expect everything to recompile with those changes, and get confused when it doesn't.

Madcrafter
2015-06-23, 04:59 PM
Does anyone here know how to open spoiler tags on this forum using javascript? I've got them to display differently (permanently opening them), but I'd rather be able to close them again.

Also, any ideas for other useful things I can do with scripting in my browser? I installed Tampermonkey for the Steam monster game, and am now looking to put it to some use.

Flickerdart
2015-06-23, 07:58 PM
Does anyone here know how to open spoiler tags on this forum using javascript? I've got them to display differently (permanently opening them), but I'd rather be able to close them again.
You can use the code inspector to find the exact functions called.




function spoiler(a) {
var spoiler = a.parentNode.parentNode.getElementsByTagName('div' )[2];
if (spoiler.className != 'spoiler-body-show'){
a.parentNode.className = 'spoiler-select-show';
spoiler.className = 'spoiler-body-show';
a.getElementsByTagName('span')[0].innerHTML = 'Hide';
}else{
a.parentNode.className = 'spoiler-select';
spoiler.className = 'spoiler-body';
a.getElementsByTagName('span')[0].innerHTML = 'Show';
}
}

function spoilershowall() {
var spoilerselect=document.getElementsByName('spoiler-select');
var spoilerbody=document.getElementsByName('spoiler-body');
for (var i=0,len=spoilerselect.length; i<len; i++) {
spoilerselect[i].className = 'spoiler-select-show';
spoilerselect[i].getElementsByTagName('span')[1].innerHTML = 'Hide';
}
for (var i=0,len=spoilerbody.length; i<len; i++) {
spoilerbody[i].className = 'spoiler-body-show';
}
}

function spoilerhideall() {
var spoilerselect=document.getElementsByName('spoiler-select');
var spoilerbody=document.getElementsByName('spoiler-body');
for (var i=0,len=spoilerselect.length; i<len; i++) {
spoilerselect[i].className = 'spoiler-select';
spoilerselect[i].getElementsByTagName('span')[1].innerHTML = 'Show';
}
for (var i=0,len=spoilerbody.length; i<len; i++) {
spoilerbody[i].className = 'spoiler-body';
}
}



You can also just use dispatchEvent on the button and tell it to click itself.

Madcrafter
2015-06-23, 10:40 PM
You can use the code inspector to find the exact functions called.Ahhh, that's where it is. I was poking through the html stuff trying to find it. I was wondering if it was as simple as renaming the class name to open/close them, and it looks like it is. Which feels really strange.

Flickerdart
2015-06-23, 11:23 PM
Ahhh, that's where it is. I was poking through the html stuff trying to find it. I was wondering if it was as simple as renaming the class name to open/close them, and it looks like it is. Which feels really strange.
It's usually not a bad idea to keep a style on your things anyway so that your code can know whether it's open or closed for various events that care about it. Now that CSS can do animations too, there's not a lot of reason to keep dynamic elements in pure JS.

Xuincherguixe
2015-06-26, 02:11 AM
I had brought up the Pony language before, was debating if I should link this video (http://www.techcast.com/events/bigtechday8/pranner-1450/) I found recently. As I'm about half way through I'm thinking yeah, some of you are going to be interested in this.

It talks about certain design choices they made and what sort of technical effects it has. I think this is going to be a really useful language.

It is fairly technical. Near as I can tell it was at aimed at people who were already pretty experienced in programming, so don't be surprised if there's some language you aren't picking up if you're new to this stuff. If the tutorial was complete I'd be recommending people start programming with this language. But it's really new so there's not a lot to work with yet.

kyoryu
2015-06-26, 02:16 PM
Actor language? It has my attention.

Xuincherguixe
2015-06-27, 01:19 AM
Actor language? It has my attention.

Yeah. I'm not deep enough into these issues that I can say one hundred percent about what the virtues of Actors over Threads. But of what I've come across it does seem like they're easier to reason about. And apparently consume less memory.

I've heard some talk that message passing is slow(er). But after watching that video it makes me think that it's because message passing was implemented in a way that might not be as fast as it could be, and other languages followed suit. In part because it had to be that way.

The message system in Pony seems to be a lot simpler than Erlang's. And it's not just messages either. Lots of things that the compiler can do because you can be certain of things. And that's because of the type system.

It's interesting stuff.

kyoryu
2015-06-28, 01:01 AM
I'm a huge fan of the Actor model. It's an actual workable concurrency model (whereas threads are mostly a hack on the procedural/imperative model).

Actor coding (and you can do similar things to actor coding in more traditional languages - Alan Kay has said that he should have called it message-oriented programming, not object-oriented programming) also has other advantages - the lack of global state means that any actor can have its behavior well defined as a set of output messages that it will send in response to a set of input messages it receives.

It's a very different model of programming (much like functional is very different), but is incredibly powerful, and the fact that it inherently multitasks and makes use of available threads, typically doesn't have locking, etc. means that most of the most common multithreading issues simply *don't exist*.

Additionally, the semantics of sending a message not only work great for local message-passing, but lend themselves towards distributed programming as well.

Xuincherguixe
2015-06-28, 09:41 PM
I'm a huge fan of the Actor model. It's an actual workable concurrency model (whereas threads are mostly a hack on the procedural/imperative model).

Actor coding (and you can do similar things to actor coding in more traditional languages - Alan Kay has said that he should have called it message-oriented programming, not object-oriented programming) also has other advantages - the lack of global state means that any actor can have its behavior well defined as a set of output messages that it will send in response to a set of input messages it receives.

It's a very different model of programming (much like functional is very different), but is incredibly powerful, and the fact that it inherently multitasks and makes use of available threads, typically doesn't have locking, etc. means that most of the most common multithreading issues simply *don't exist*.

Additionally, the semantics of sending a message not only work great for local message-passing, but lend themselves towards distributed programming as well.

Yeah, I had heard a lot of that before. I suppose seeing how Pony implements actors it's easier to see their value. I was thinking about using Akka a bit in Java or Scala, and I still might. But it's different when it's part of the language.


I also decided to read up a bit more on message passing. By the sounds of things it's slower than passing memory references but definitely has it's place. Because some times (most times) it's more important to have code that's easy to reason about than code that's fast.

Xuincherguixe
2015-06-28, 09:54 PM
I've been thinking about doing some user interface programming in Pony. So now I'm trying to decide which widget toolkit I should go with. In theory programmers.stackexchange would be a better place, but I'm not actually sure what I'm after and the stack exchange format isn't good for subjective questions.

Solse
2015-06-28, 10:32 PM
What with all this talk about actors, I decided to look up the Actor Model, and I'm wondering: what makes them different from threads? Is the idea that threads still have code that runs procedurally, while actors don't? I'm probably missing something here, but I don't really know what.

kyoryu
2015-06-28, 10:51 PM
Actors do not have shared state. Two threads might communicate by setting a variable, and then checking the value of that variable. Actors do not - they communicate by sending messages to one another.

Typically, actor-oriented languages will use thousands or more actors, each of which has a small amount of state/code. These will typically be scheduled onto whatever thread is available whenever they get triggered.

Each actor is guaranteed to have only a single thread running at one time - so you can write your individual actors as if they were strictly single-threaded.

Typically (and I believe it's part of the model definition) sending a message for an actor is an inherently asynchronous process, while *receiving* a message is synchronous.

Typical actor behavior will be:

1) receive a message (or a set of correlated messages)
2) do some modification of local state
3) send one or more messages as a result (sometimes zero)
4) define what messages the actor wants to receive next.

These units of work are almost always very small and fast. I/O is almost always done in a non-blocking way (though if I/O is modeled as sending messages to other actors, that's inherent anyway).

factotum
2015-06-29, 02:44 AM
I also decided to read up a bit more on message passing. By the sounds of things it's slower than passing memory references but definitely has it's place. Because some times (most times) it's more important to have code that's easy to reason about than code that's fast.

I'd argue that a large reason for using multi-threading is to make best use of your multi-core CPU and thus produce the fastest possible program, so extra overhead in inter-thread communications seems counterproductive. I'm also a bit puzzled about kyoryu's comment about sending a message being asynchronous but receiving being synchronous--how does that work?

The only experience I have with a message-passing system is low-level Windows coding, I'll admit, so it's possible I'm not really seeing the benefits here.

Xuincherguixe
2015-06-29, 05:02 AM
I'd argue that a large reason for using multi-threading is to make best use of your multi-core CPU and thus produce the fastest possible program, so extra overhead in inter-thread communications seems counterproductive. I'm also a bit puzzled about kyoryu's comment about sending a message being asynchronous but receiving being synchronous--how does that work?

The only experience I have with a message-passing system is low-level Windows coding, I'll admit, so it's possible I'm not really seeing the benefits here.

I get the sense that the difference in practice would be negligible.

Flickerdart
2015-06-29, 09:44 AM
Are HTML5 workers actors? I've been looking into them a bit (the stuff I do at work currently places absurd amounts of load on the UI thread) and it sounds pretty similar (asynchronous bits of small code that send messages back and forth).

kyoryu
2015-06-29, 11:23 AM
I'd argue that a large reason for using multi-threading is to make best use of your multi-core CPU and thus produce the fastest possible program, so extra overhead in inter-thread communications seems counterproductive. I'm also a bit puzzled about kyoryu's comment about sending a message being asynchronous but receiving being synchronous--how does that work?

The only experience I have with a message-passing system is low-level Windows coding, I'll admit, so it's possible I'm not really seeing the benefits here.

It works something like this:

// send a message
otherActor:Send("hi there");

// this executes immediately
receive(result);

// this doesn't execute until we receive the result
env.print(result);

A send will execute immediately, and then continue executing. However, receiving data will block (it's usually not actually a block as in a blocked thread, but semantically they're the same) until it receives the message it wants.

Grinner
2015-06-29, 01:00 PM
...A send will execute immediately, and then continue executing. However, receiving data will block (it's usually not actually a block as in a blocked thread, but semantically they're the same) until it receives the message it wants.

This is not what I was expecting...Are these calls all contained in one file? If the entire program halts when one thread actor doesn't get appropriate input, how is it benefiting from multiple cores?

factotum
2015-06-29, 03:03 PM
This is not what I was expecting...Are these calls all contained in one file? If the entire program halts when one thread actor doesn't get appropriate input, how is it benefiting from multiple cores?

I think the point is that only the actor waiting for the message blocks, the others will keep running fine. I'm sure it's possible to get a deadlock condition with actors just as it is with threads (e.g. two actors are each awaiting a message from the other, so since the receive call blocks until it gets the message, neither will ever continue), but hopefully you've designed things so that's unlikely to happen.

kyoryu
2015-06-29, 04:26 PM
I think the point is that only the actor waiting for the message blocks, the others will keep running fine. I'm sure it's possible to get a deadlock condition with actors just as it is with threads (e.g. two actors are each awaiting a message from the other, so since the receive call blocks until it gets the message, neither will ever continue), but hopefully you've designed things so that's unlikely to happen.

Correct. Only an individual actor "blocks". (In reality, it will be put in a pending queue and not have a thread servicing it at all until it receives a message, at which time it will get serviced by a thread).

-D-
2015-07-01, 08:31 AM
Yeah, I've heard some blog talking about Actor model as analogous to message/mailbox. Where each actor has a mailbox (message queue) to work through.

Xuincherguixe
2015-07-02, 04:51 AM
Yeah, I've heard some blog talking about Actor model as analogous to message/mailbox. Where each actor has a mailbox (message queue) to work through.

I'm sort of fighting with my laptop as I'm trying to install things, but chances are I'll be giving Pony a serious try in the near future. If so I'll probably make a post about it.


Predictions are that the language will mostly be easy, capabilities will feel like they're getting in the way but that it's something one can get used to, and that calling C/C++ libraries will make things awkward. I'm also thinking that can be abstracted though.

kyoryu
2015-07-02, 08:11 PM
Yeah I wanna try it but no windows installer :/

Xuincherguixe
2015-07-02, 10:03 PM
Yeah I wanna try it but no windows installer :/

I suppose if you don't want to format another partition for Linux there's always virtual box (which is an emulator)

akma
2015-07-08, 01:21 PM
I decided that from some point, I'll only use the Forth programming language for project Euler. However, using a language which I'm not used to for something hard proved impractical.
Could anyone recommend a good source for questions which I could use to get used to the syntax? Something non-trivial but not too complicated (Forth gets much harder the more variables a command requires).

Grinner
2015-07-09, 02:00 PM
I'm working on learning socket programming right now. I've got a simple TCP server working, complete with a non-blocking function for checking for connection requests. However, I've noticed something odd which I hope someone might be able to explain.

I seem to be able to spawn an indefinite number of sockets from a static array of them. I guess the array is just a set of identifiers and not the sockets themselves? Anyway, the server sends out a "Hello World"-type message to every client every cycle of the main loop. Where it gets weird is that I can apparently address sockets outside of the static array via a for-loop. Do I have a buffer overflow on my hands? Should I be concerned about this, and should I set a hard limit on the number of clients that may connect to my server?

Here's the relevant bits of code:

#define MAX_CLIENTS 3
SOCKET clients[MAX_CLIENTS];

...

int x;
for (x = 0; x < counter; x++) {
message = "hello there";
send(clients[x], message, strlen(message), 0);
}

Each time the server accepts a new connection, counter is incremented by 1, and the message loop which utilizes counter will work without problems even when counter exceeds MAX_CLIENTS.

Douglas
2015-07-09, 02:43 PM
Do I have a buffer overflow on my hands? Should I be concerned about this, and should I set a hard limit on the number of clients that may connect to my server?

Here's the relevant bits of code:

#define MAX_CLIENTS 3
SOCKET clients[MAX_CLIENTS];

...

int x;
for (x = 0; x < counter; x++) {
message = "hello there";
send(clients[x], message, strlen(message), 0);
}

Each time the server accepts a new connection, counter is incremented by 1, and the message loop which utilizes counter will work without problems even when counter exceeds MAX_CLIENTS.
I'd need a lot more information to have any chance of figuring out why this isn't crashing horribly, or at least behaving in strange and unexpected ways, but yes I believe you do have a buffer overflow here, and yes you should be concerned about it. Setting a hard limit on how many clients can connect is one way to handle it, but there are other ways too.

Grinner
2015-07-09, 02:59 PM
Setting a hard limit on how many clients can connect is one way to handle it, but there are other ways too.

Dynamic array via malloc()/realloc()?

kyoryu
2015-07-09, 03:12 PM
given the code, if you do:



send(clients[5], message, strlen(message), 0);


you are well into undefined behavior. Writing anything to clients[5] is writing off the edge of what's allocated, and there is *zero* prediction as to what can do that. It might appear to work. It might give you a buffer overrun. It could summon Cthulhu. It is inherently an error.

Keep in mind that a[b] is equivalent to *(a)+b; That is to say, it increments the pointer that a represents (c arrays are basically pointers), by 'b', and then modifies that memory. If 'b' is beyond the allocated memory, you are writing into unknown space.

Xuincherguixe
2015-07-23, 01:14 AM
Things are going a bit slower than I had planned on, but installed virtual box and made an Ubuntu virtual machine. Installed a text editor (atom) and assorted packages, went ahead and compiled a Hello World program.

Can't say I like not using an IDE, but Atom makes a big deal about how it's extensible so maybe I can turn it into one (as opposed to just having language support)

Xuincherguixe
2015-08-04, 04:59 PM
So, I thought I would try learning the enlightenment widget toolkit (https://www.enlightenment.org/) at the same time as I work with Pony. It seems like some of the repositories aren't written correctly for Ubuntu. Pony itself seems to be working alright, and I might switch over to QT or GTK+, but if I'm going to go hipster (Oh, I'm using libraries you've never heard of) may as well go all out hipster.

Do have other priorities though that I should focus on though.

Grinner
2015-08-04, 06:15 PM
Do you mind posting some sample code? I took a look at the hello-world on pony-lang.org, and I'm still not entirely clear on how the code is supposed to be formatted.

Also, in a highly-amusing turn of events, I've discovered a My Little Pony-themed esolang. It's amazing. (http://deftcrow.deviantart.com/art/FiM-Programming-Hello-World-99-Jugs-of-Cider-330736334) :smalltongue:

Xuincherguixe
2015-08-04, 06:51 PM
Yeah. If I'm honest I've barely done anything. Copied the hello world in the sand box to a text file and compiled that. Then did an include to test the C Foreign Function interface. Then went back to the sandbox and did a simple variable comparison (if a>b do something).

I wouldn't know how it should be formatted myself. I think at this point it hardly matters because there isn't really a style guide.

If I had any real content chances are it would look like it followed the Java style guidelines. Or what I was taught are the Java style guidelines. Which probably isn't right.


I propose proper pony procedure possibly places particularly perpendicular to the OCaml family.

Perhaps.