• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

The Coder's Lounge

296
Posts
11
Years
Yeah, my project was Java so as long as the JRE was installed, it was cross-platform and it worked really well. I haven't had the unfortunate luck of a project breaking like that, although I did have hardware issues when I was taking robotics. I ended up having power drain from some servos that ended up affecting some sensors and completely borked basic movement. Once I disconnected those servos, everything worked nicely. This was found in the middle of an all-nighter with the rest of the class though, that wasn't too great :/

I had refactored the code so many times trying to fix it, only for it to be a physical flaw... I was not impressed.

Yeah I don't know what happened, I never had a problem transferring to the Linux server before. Maybe I was just lucky and last semester's programs were simple enough that it didn't matter. At some point if I have time I'm going to see the professor and find out what the problem might've been and how to fix it because now it's just bugging me lol.

Ugh that would drive me crazy, trying to fix problems in the code only for the problem to not be the code at all.
 

string555

Banned
1,373
Posts
6
Years
I had a strange but possibly interesting idea at the end of the work day that might be a good exercise in assembly. What if I made my own simple and crude programming language, then made a compiler for it in assembly?

I realize there's a crap ton more that goes into a compiler than what I currently understand. But the general idea is that you take lines of code written in human readable form, and convert them into lines of machine code that (hopefully) does what the programmer intends, right?

So if I actually do go through with this, I think it would offer me a lot of insight into not only assembly, but also into how compilers work.

Or I'm just crazy... (@_@)
 
23,054
Posts
11
Years
  • Age 34
  • Seen today
I had a strange but possibly interesting idea at the end of the work day that might be a good exercise in assembly. What if I made my own simple and crude programming language, then made a compiler for it in assembly?

I realize there's a crap ton more that goes into a compiler than what I currently understand. But the general idea is that you take lines of code written in human readable form, and convert them into lines of machine code that (hopefully) does what the programmer intends, right?

So if I actually do go through with this, I think it would offer me a lot of insight into not only assembly, but also into how compilers work.

Or I'm just crazy... (@_@)
Just be aware that building compilers is Masters degree type of difficulty. All I know about compilers is that they create some type of object code in form of a table that yields references to libraries and stuff. And after compilation those objects get handed to the linker which then resolves those references and creates the final executable.
 
296
Posts
11
Years
Hey quick question for any of the Perl programmers on here: I keep coming across references to variables that have "fallen" out of scope but I haven't seen this particular phrasing before and can't find an explanation for what exactly that means.

Is it just referring to inaccessible variables that were declared in a separate function or within a code block? Or is there some other way for variables in perl to be out of scope?
 
Last edited:

string555

Banned
1,373
Posts
6
Years
Just be aware that building compilers is Masters degree type of difficulty. All I know about compilers is that they create some type of object code in form of a table that yields references to libraries and stuff. And after compilation those objects get handed to the linker which then resolves those references and creates the final executable.

My lack of any formal education never stopped me before. Besides, what could possibly go wrong? :P

I do have one idea to start this, but I realize that it is NOT really a compiler, it's just a tinker toy to play with the idea.

I'll start by making a made-up programming language called Jabberwocky (Or Jab for short). Jab is only capable of these simple tasks:

*Declare and work with variables (Unsigned 8-bit integers only, to keep it simple)
*Perform basic arithmetic operations with these variables and or unsigned 8-bit integers
*Use only 2 simple built-in functions for input and output

So I can make this 'compiler' (It's not really) in perl. Will it convert the Jab script into working machine code? No, lol. It's going to convert the Jab script into a NASM script, and if you use the -c switch when using the perl script, it will also compile and link the NASM script from system commands, in the same exact way the programmer would do from the command line.

This probably seems totally ridiculous, but making things fun is part of how I learn. :3

Edit: lol, here's the first ever Jab script:
Code:
?JAB
::Jabberwocky script
::Double colon declares the rest of line as comment
!func:
::Area for declaring built-in functions to be used
?inp;?outp;
::Start each name with question mark, end each with semi-colon
!vars:
::Area for declaring and possibly initializing vars
?a=1;?b=2;?c;
::Declare and initialize a and b, only declare c
!code:
::Main code
c=a+b;
outp:c,1; ::First arg output string, num, while 2nd is length of output
outp:"\n",1; ::Newline is 1 char
outp:"Enter a number: ",16;
inp:1,c; ::Input 1 byte into c
outp:c,1;
outp:"\n",1;
a=c+b;
outp:a,1;
outp:"\n",1;
?/JAB

Just so you know, the best feature in Jab is its obfuscation. {XD}
Is it just referring to inaccessible variables that were declared in a separate function or within a code block?

I think that's right, for example:
Code:
#!usr/bin/perl
use strict;

{
	my $c=5;
}

print "$c\n";

Generates this error with perl:
"Global symbol "$c" requires explicit package name at scopetest1.pl line 8."

Which seems to mean that $c is being called out of scope. There's possibly some other cases of this that I'm not thinking about, though. :X



Edit2: Lol, so I made a working 'Jab interpreter', or whatever you want to call it. I had to water down the original Jab script into a simple Hello World, since I was having issues with it. I just wanted to call it a night with something having been accomplished.

So here's the Hello World in Jab:
Code:
?JAB
::Jabberwocky "Hello, World!" script
::Double colon declares the rest of line as comment
!vars:
::No vars to declare
!func:
?outp;
!code:
outp:"Hello, World! :3\n",17;
?/JAB

Anything may be placed before and after the 'JAB' markers, for documentation and such. :O

And here's the resulting NASM script from it:
Code:
SECTION .data

	SYSCALL_WRITE equ 1
	SYSCALL_EXIT equ 60
	fmt0 db "Hello, World! :3",10,0


SECTION .text
	global main

main:
	push rbp
	mov rax, SYSCALL_WRITE
	mov rdi, 1
	mov rsi, fmt0
	mov rdx, 17
	syscall
	mov rax, SYSCALL_EXIT
	mov rdi, 0
	syscall

And finally here's the Jabberwocky interpeter itself (Be warned, messiness inside :O):
Spoiler:


P.S The formatting was fine on my side, so if it looks screwed up on anyone else's side, that's not on me. >:3
 
Last edited:
296
Posts
11
Years
Not to mention being able to dynamically optimize boolean logic using boolean short circuiting to increase performance. If anything, a good place to start is just making a simple script interpreter, those are a lot more easy to handle and doesn't require trying to create a lot of advance logic.

Scope is something that's in almost all programming languages, and there's a very interesting reason for it. I'll provide a simple explanation, and I'll also provide a more advanced explanation that helps you to understand why this is. Both samples of code are approximately equivalent.

To make it simple, a variable is only accessible in certain places. If you declare a variable within some kind of function, it's only accessible from that function (Known as a local variable). If you put it outside of a function, but somewhere in your program before your main entrypoint, it can be accessed by everyone (Known as a global variable). For instance:
Code:
//other things
string str = "hello world ";
void doStuff()
{
    int x = 1;
    x++;
    printf(str + x);
}
In this case, x is local to doStuff(), while str is accessible to both doStuff() and anything else defined after (Based upon its position in the code). Trying to access x outside of doStuff() will be flagged as out of scope. str won't, however, as long as you don't try to use it before declaring it.

As for the formal reason why, it all comes down to the assembly. Your global variables are stored at the very beginning of your file in the data declarations (.data). However, if you need to use a temporary variable (Such as an iterator in a for loop, or some kind of integer value for arithmetic), it has to be pushed into a temporary part of memory so that it can be used. The best place for this is the stack, which also does a thousand other things. So, in this instance, str would be (better off) in .data, while x would be stored in the stack. However, the stack is extremely important - it'll also tell us where we are in our program when we went to this code, and so we have to drop this temporary variable so that we can return back to the point in the stack that tells us where we were in code for when we go back, and so it disappears and ceases to exist, hence, it only exists in that function, and gives us scope. Here's a quick example (It uses some custom libraries and there's a few errors as I haven't done this in a while, but... it's quite self-explanatory):
Code:
.data
str    byte    "Hello world ", 0 ; end with a 0 so we know where the end of the string is

.code
main proc
    ; do things

    call myProc
main endp

myProc proc
    pushad ; push all general purpose registers to the stack, and save their contents - they may be important!
    push 1 ; this gets pushed to [esi - 4]
    mov eax, OFFSET str ; move the location of the hello world string into the eax register (Required for the function) for printing
    call WriteString ; write Hello World to the string
    mov eax, [esi-4] ; move the value from the stack into eax register
    inc eax ; increment the value we just moved
    call WriteInt ; write the 1 to the screen
    pop eax ; move 1 into eax and remove it from the stack so the next instruction doesn't screw up
    popad ;pop all the previous values from the stack back into their respective registers so we don't crash, effectively restoring program state prior to this function
myProc endp

Thanks! I do know what scope is (but I appreciate the 'why' explanation, which is something I haven't been given yet - I always like to know why something is the way it is, makes it easier for me to remember) I was just confused by the specific phrasing "fallen out of scope" - mainly in the particular tutorial I was looking at, where they said something along the lines of "if you still have variable x hanging around but all your other variables have fallen out of scope" which to me sounded like it might mean the other variables were in scope at the beginning of the function, but aren't anymore, analogous to closing a file and then trying to access it later on in the same function. Just made me wonder if it's a peculiar turn of phrase used in programming/perl, or if there was actually a way for variables to become out of scope without leaving the function they were declared in (and nobody else I could find using that phrasing actually said in what way the variables they were discussing were out of scope, just that they were)
 
Last edited:

string555

Banned
1,373
Posts
6
Years
I had another idea at work today (Don't worry, it's not Jabberwocky++ XD). I had made some really simple perl chat bots a while ago, and I decided to use one of them as a base. I took that code and made a new one, this time with simulated emotions. Everything seems to be in working order, although I'm sure there are some trickier to find bugs lurking in there. Here's the script so far:
Spoiler:


I don't know if PC is going to butcher the code by removing some things along with indentation, though. :X

This was fun, but I need to break down and focus on some damn Assembly. :P

Edit: Made some changes to the above code that I feel improved it. Now off to Dreamland! z Z Z
 
Last edited:
296
Posts
11
Years
So I had the weirdest error in my code yesterday, wonder if anybody with more experience than me might take a gander and figure out what happened since I don't have time to actually go to my professor's/TA's office hours before next week lol (this is just a very small segment of code because it's for a school assignment (written in C). The weird thing is I was doing exactly what the professor did, as far as I could tell, but I know at least one other person had the same thing happen.)

Spoiler:
 
Last edited:
23,054
Posts
11
Years
  • Age 34
  • Seen today
You know what I don't like? When I'm working on something and I get a nice idea on how to cleanly solve a problem. Then I look at the structure some more and realize that I can't do it due to how the system was designed. And the only remaining solution that doesn't require rewriting everything ends up being functions containing hundreds of lines of nothing but conditionals. <_<
 
296
Posts
11
Years
You know what I don't like? When I'm working on something and I get a nice idea on how to cleanly solve a problem. Then I look at the structure some more and realize that I can't do it due to how the system was designed. And the only remaining solution that doesn't require rewriting everything ends up being functions containing hundreds of lines of nothing but conditionals. <_<

Yikes. That sounds fun.
 

Leviathan

[span="font-family:ubuntu; color: whitesmoke; padd
1,103
Posts
10
Years
You know what I don't like? When I'm working on something and I get a nice idea on how to cleanly solve a problem. Then I look at the structure some more and realize that I can't do it due to how the system was designed. And the only remaining solution that doesn't require rewriting everything ends up being functions containing hundreds of lines of nothing but conditionals. <_<

Yowch. I've experienced that myself, coming up with solutions only to find I can't really apply them. It's quite a painnnn.

You know what's not fun? Trying to write an implementation chapter of a report I've got to do for my final year thesis when I'm still in the process of building my project. o/ What's extra annoying is I sent a rough draft of the chapter to my supervisor who instantly called it a 'rambling mess.' Of course I'm going to tidy it up and revise it as soon as I have my damn app project built, but that did sting. I can't code and document my work at the same time. </3
 

Leviathan

[span="font-family:ubuntu; color: whitesmoke; padd
1,103
Posts
10
Years
Ouch. I like having the cleanest possible solution when it's available. If I have to write a solution that ends up not being optimal, I'm never happy with it.

That's pretty harsh feedback. Did he at least provide pointers into where it was a "rambling mess"? I feel that having at least some feedback into what he didn't like would definitely help with a thesis.

Unfortunately, he didn't. :') And to make matters worse, when I met him for a meeting yesterday not only had he not bothered to look at them (I sent copies to him last week), he was /still/ going on about the previous work. I got so sick of listening to it, and wanted to walk out of that meeting as me and two other classmates had already spent 10 minutes of it staring at the back of my lecturer as he typed away on his computer. Ugh!

Thankfully though, I'm a lot further along in my project, coding wise. Got the app itself mostly built with one of the last things I need to do before moving into testing is figuring how to save a user's current latitude and longitude coordinates. I've gotten as far as getting the phone to tell me the lats and longs, which update as I move around, but I dunno how to capture that data and store it as strings or doubles somewhere.
 

Leviathan

[span="font-family:ubuntu; color: whitesmoke; padd
1,103
Posts
10
Years
If you're using Android, it's actually not terrible. I have some code somewhere that allows me to store content. Let me see if I can dig it up...

Ah. Try using Android's [url='https://developer.android.com/training/data-storage/shared-preferences.html"]SharedPreferences[/url]. From there, you can store data in a key-value tuple set. If need be, since you use key arguments as arbitrary strings, you can dynamically create extra entries as you plot your data, and then just retrieve the data later when you want to load it, or even just output it through adb if that's an option once you need to request that data.

Tahs for this! I think that's the route I was trying to do at one stage, yeah, but it was passing in nulls whatever way I had it set up. I'll have to double-check my code.
 
11
Posts
15
Years
Hey guys, could I be added to the list of programmers? :D

I've been programming since seventh grade, when I started learning Java. Since then, I've also learned bits and pieces of C, C++, Python, Assembly, and probably a few other languages I can't think of right now. I currently am in college as a computer engineering student.
 

Vigilance

Re-diddly-dacted
40
Posts
6
Years
  • Age 24
  • Seen May 12, 2019
Trying to learn some PHP in the near future! As of now, I've been strengthening my JavaScript skills!
 
440
Posts
14
Years
  • Age 28
  • Online now
Trying to learn some PHP in the near future! As of now, I've been strengthening my JavaScript skills!

I've been doing it as a part of my class at school right now, and I just wrote the midterm for it, actually. I think we'll be playing around with jQuery in the lab that we have today, but otherwise we've been doing basic HTML/CSS/JavaScript right now. It's not terrible tbh.
 
27,741
Posts
14
Years
Trying to learn some PHP in the near future! As of now, I've been strengthening my JavaScript skills!
PHP is a great web language and it's a shame that it's dying as is. I picked up PHP six years ago as something to work with since I wanted to parse XML data and display it in a format I liked.
 

Leviathan

[span="font-family:ubuntu; color: whitesmoke; padd
1,103
Posts
10
Years
Shame. I do love building projects with it. <3 What's replacing it btw? Python?
 
Back
Top