[QUOTE=reevezy67;45794188]Not completed but I'm in the process of doing one.
There is some maths, at least in my degree, but if you can program, you can probably get through the math. I think in general there should be more practical things like logic and set operations.[/QUOTE]
Ok that makes sense. Thanks for clarifying :)
I was just wondering how complex the maths related subjects in these courses typically are. I'm not doing a Computer Science course, but I plan on enrolling in an IT course that has a subject called "IT Mathematics" or something like that.
I am massively maths-retarded and I haven't had it in high school. I enrolled in a GCSE Maths course and want to get better, but I think I would probably fail if faced with a fairly high level of number magics :pwn:
[QUOTE=meek;45793825]Hey guys. For those of you that have completed Computer Science courses or programming-related courses, just how much focus is there on maths? How advanced is the mathematics you use in programming?[/QUOTE]
Calculus is required for the CS major in my university.
Linear algebra is almost essential for anything 3D, [I]especially[/I] graphics.
[QUOTE=meek;45793825]Hey guys. For those of you that have completed Computer Science courses or programming-related courses, just how much focus is there on maths? How advanced is the mathematics you use in programming?[/QUOTE]
Programming itself has little focus on math beyond basic calculus.
The things you [I]can[/I] do in programming tho, that's a different story.
If you want to do graphics programming, or pump out your own physics engine for example, you'll have to learn some math surrounding it.
[QUOTE=rilez;45788333]What is the "best" way to name C++ variables? ex:
foo_name
fooName
FooName
fooname
What will cause me the least trouble?[/QUOTE]
camelCase for variables
(i.e: [code]int myInteger;[/code])
camelCase for parameters
(i.e: [code]static void myFunction(int parameterNumberOne, int parameterNumberTwo)[/code]
[QUOTE=proboardslol;45806005]camelCase for variables
(i.e: [code]int myInteger;[/code])
camelCase for parameters
(i.e: [code]static void myFunction(int parameterNumberOne, int parameterNumberTwo)[/code][/QUOTE]
Any reason which is not just a personal preference?
[QUOTE=Dienes;45806623]Any reason which is not just a personal preference?[/QUOTE]
This is how I learned it. the only reason it matters is so that when someone else looks at your code they know what they're looking at. if the standard happens to be PascalCase, then so be it, but from what I understand it's not
[QUOTE=proboardslol;45806694]This is how I learned it. the only reason it matters is so that when someone else looks at your code they know what they're looking at. if the standard happens to be PascalCase, then so be it, but from what I understand it's not[/QUOTE]
So I assume you "learned" it at school where the teacher forced it upon you so he wouldn't die when looking at hundreds of code samples with styles all over the place.
There is no standard, but when working in a group (e.g. a class or a company) you better agree on one common style to make it easier for everybody.
[QUOTE=Dienes;45806737]So I assume you "learned" it at school where the teacher forced it upon you so he wouldn't die when looking at hundreds of code samples with styles all over the place.
There is no standard, but when working in a group (e.g. a class or a company) you better agree on one common style to make it easier for everybody.[/QUOTE]
I wouldn't say he forced it on us. He never said "THIS IS THE WAY TO DO IT", he said that this is a convenient way to write it since ALLCAPSWOULDMAKEITHARDTOTELLTHEDIFFERENCEBETWEENWORDS andsowouldnocapsatall, so camelcase allows you to put multiple words in a variable. if you used PascalCase I don't think he would care, that's just what he taught us.
he taught us what were acceptable identifiers and what weren't acceptable identifiers, obviously, so if we really felt compelled to, we could name our identifiers some crazy ass shit, but since everything we did in class we had to share with one-another in presentations and since most of our work was group projects, we would probably want to have an agreed-upon standard, so he taught us that.
This is one of those arguments in computer programming that I just don't fucking understand. Like the whitespace debate, or the brackets debate. Who gives a shit? it doesn't take that much effort to adapt to whitespace in a for loop or having opening brackets on a new line or on the same line. you should simply stick to one standard throughout your code, but I don't understand why it's necesarry to make EVERYBODY do it one way or another.
edit: when I program in freebasic, i have caps lock on constantly since the entire language isn't case-sensitive and wont give me an error on compilation, so if I later go back in the code and don't recognize an identifier because I did it in PascalCode in one instance and camelCode in another, then I'm SOL, so I just have caps lock on the entire time, which is the classic way for BASIC to be written
[QUOTE=proboardslol;45806799]This is one of those arguments in computer programming that I just don't fucking understand. Like the whitespace debate, or the brackets debate. Who gives a shit? it doesn't take that much effort to adapt to whitespace in a for loop or having opening brackets on a new line or on the same line. you should simply stick to one standard throughout your code, but I don't understand why it's necesarry to make EVERYBODY do it one way or another.[/QUOTE]
Because if you don't enforce it you'll have a program with three different coding styles by three different people. Possibly in the same file.
[QUOTE=proboardslol;45806799][...] you should simply stick to one standard throughout your code, but I don't understand why it's necesarry to make EVERYBODY do it one way or another.[/QUOTE]
Exactly. That's why I was asking why you suggested camel-case as the one single answer to the OP's question.
[QUOTE=esalaka;45806824]Because if you don't enforce it you'll have a program with three different coding styles by three different people. Possibly in the same file.[/QUOTE]
Obviously you should enforce it on an individual basis, when working with others, but I don't understand why, across the board, people feel the need to tell other people how to write THEIR code.
The most common convention for C++ seems to be to use PascalCase for types and camelCase for variables and methods, but the standard library, STL and, as far as I know, Boost use underscores for everything.
[QUOTE=proboardslol;45806832]Obviously you should enforce it on an individual basis, when working with others, but I don't understand why, across the board, people feel the need to tell other people how to write THEIR code.[/QUOTE]
Nerds like holy wars.
I quite like it when languages have universal style guides, though - everyone knows there is One True God-Approved Way so you know what to expect regardless of the codebase you're looking at.
[QUOTE=esalaka;45808626]Nerds like holy wars.
I quite like it when languages have universal style guides, though - everyone knows there is One True God-Approved Way so you know what to expect regardless of the codebase you're looking at.[/QUOTE]
More importantly, the more standardised a language's style is, the better you can mix code from various sources (or even just linked libraries) without introducing confusion.
The reason for different naming conventions in c++ is that you avoid collisions. For example members and member function collision, parameter and members collision, type name and function collision I think. There may be more cases.
I'm just starting with Boo and I'm having problems. I can compile my code but it doesn't run like it should
[code]print "Enter the number to verify the Collatz conjecture of:"num as duck = System.Console.ReadLine()
loops as duck = 0
while (num != 1):
if (num % 2):
num=(num / 2)
print "$num is even, dividing by 2"
loops++
else:
num=(num * 3 + 1)
print "$num is even, multiplying by 3 and adding 1"
loops++
print "Completed in $loops loops"[/code]
The print statement works, and user input is requested, but when I press Enter causes Mono to crash, saying
[code]Unhandled Exception:
System.MissingMethodException: Modulus is not applicable to operands 'System.String' and 'System.Int32'. ---> System.MissingMethodException: Method not found: 'System.String.op_Modulus'.
at Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher () [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create () [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.RuntimeServices+<Invoke>c__AnonStorey11.<>m__5 () [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) [0x00000] in <filename unknown>:0
at CollatzModule.Main (System.String[] argv) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.MissingMethodException: Modulus is not applicable to operands 'System.String' and 'System.Int32'. ---> System.MissingMethodException: Method not found: 'System.String.op_Modulus'.
at Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher () [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create () [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.RuntimeServices+<Invoke>c__AnonStorey11.<>m__5 () [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args) [0x00000] in <filename unknown>:0
at Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) [0x00000] in <filename unknown>:0
--- End of inner exception stack trace ---
at Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs) [0x00000] in <filename unknown>:0
at CollatzModule.Main (System.String[] argv) [0x00000] in <filename unknown>:0[/code]
Running it on Windows does the same, but outputs this
[code]Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Boo.Lang, Version=2.0.9.5, Culture=neutral, PublicKeyToken=32c39770e9a21a67' or one of its dependencies. The system cannot find the file specified.
at CollatzModule.Main(String[] argv)[/code]
The error on Linux is because what you type into the program is being read as a string of characters, not a number. And text doesn't have a modulo operator, for obvious reasons.
To get an integer number from your input, you have to do something like this:
[code]print "Enter the number to verify the Collatz conjecture of:"num as duck = int.Parse(System.Console.ReadLine())[/code]
The error on Windows is unrelated to your code - rather, Boo does not appear to be properly installed on your system.
Okay, I've updated the code to this:
[code]print "Enter the number to verify the Collatz conjecture of:"
num as duck = (long.Parse(System.Console.ReadLine())) //Ask for user input
loops as duck = 0 //Create a variable for how many loops the program runs to verify the orbit of the input number
/*if (num == 1):
print "You entered the number 1. There is nothing to be done."
return 0*/
if (num != 1):
if (num % 2 == 0): //If the input number is even
num=(num / 2) //Divide the input number by 2
print "$num is even, dividing by 2" //Print that the number is even so it is being divided by 2
loops++ //Add 1 to the number of loops
if (num % 2 == 1)
num=(num * 3 + 1)
print "$num is even, multiplying by 3 and adding 1"
loops++ //Add 1 to the number of loops
while (num != 1): //Check if the number isn't 1. If it is, then we don't need to do anything
if (num % 2 == 0): //If the input number is even
num=(num / 2) //Divide the input number by 2
print "$num is even, dividing by 2" //Print that the number is even so it is being divided by 2
loops++ //Add 1 to the number of loops
if (num % 2 == 1):
num=(num * 3 + 1)
print "$num is even, multiplying by 3 and adding 1"
loops++ //Add 1 to the number of loops
print "Completed in $loops loops" //Tell the user how many loops it took to verify the orbit of the input number[/code]
but now the compiler is throwing this:
[code]Boo Compiler version 0.9.5.1 (3.2.8 (Debian 3.2.8+dfsg-4ubuntu1))
Dropbox/Programming/Collatz/collatz.boo(16,12): BCE0043: Unexpected token: <INDENT>.
Dropbox/Programming/Collatz/collatz.boo(16,9): BCE0043: Unexpected token: num.
Dropbox/Programming/Collatz/collatz.boo(18,16): BCE0044: expecting "EOF", found '<DEDENT>'.
3 error(s).[/code]
[code]Dropbox/Programming/Collatz/collatz.boo(16,12): BCE0043: Unexpected token: <INDENT>.[/code]
The first number (16) in this is the line number where the error happened.
It's complaining about seeing an indentation where there shouldn't be one.
Look at the line above line 16:
[code]if (num % 2 == 1)[/code]
You're missing the colon. Thus, the Boo compiler complains about seeing a new line and indentation directly following the closing parenthesis on line 15, which is not a valid follow-up to "if (num % 2 == 1)".
Okay I've applied that fix, but the program now has another issue. It just loops forever, and it gets the strings wrong. It will say things like "4 is odd, multiplying by 3 and adding 1", but then it will say "2 is even, dividing by 2", then it gets to 1 and it doesn't end the loop like it should
[editline]27th August 2014[/editline]
Fixed by adding [code]continue if num == 1[/code] at the end of the if's in the while loop. Also fixed the weird print messages by having it do the printing before it does any math.
[editline]27th August 2014[/editline]
So does Boo have some equivalent of [code]return 0;[/code] to close the program if certain conditions are met?
The "continue if num == 1" fix you applied was a workaround.
If num is even at the start of one of your loops, it is divided by two. Immediately after that, without returning to the while condition, it is checked whether the result of that is odd - your if conditions are independent of each other.
However, you can do the following.
[code]
if (conditionA):
codeA
elif (conditionB):
codeB
elif (conditionC):
codeC
else:
codeD
[/code]
"elif" is Boo's keyword for "else-if". conditionC, for example, is only checked if neither conditionA nor conditionB were true. codeD is only executed when all if conditions of that structure were false.
Regarding your second question:
Boo doesn't require you to use an entry point function/method like many other languages do. Internally it has its own which it uses to execute your code.
The .NET Framework that Boo runs in provides a System.Environment.Exit(int returnValue) method that will jump right to the end of that internal function and return returnValue.
So if you want to immediately halt program execution, just use "System.Environment.Exit(0);".
In case you're wondering what the returnValue is about: This is passed to the program that executed your program, and intended to be used in a very simple form of error handling - the value 0 is generally used to mean "successful execution", any other value specifies that an error has occured. You won't see it by simply running your program in a console, and it's not used on Windows (and GUI programs in general) a lot, but automated scripts/programs on Linux/Unix still make heavy use of it.
For the life of me I can't figure this shit out
My program has a single guy (mario) running around, grabbing the nearest block, and bringing it to the nearest destination. my code for these subroutines is thus
[sp]warning: QuickBASIC[/sp]
[code]
Sub FIND_NEAREST_BLOCK
If MARIO.BOOL_LOOKING = TRUE Then
For I As Integer = 1 To 40
For Q As Integer = 1 To 30
If BLOCKS(I,Q).BOOL_ACTIVATED = TRUE Then
If DISTANCE(MARIO.X,MARIO.Y,BLOCKS(I,Q).X,BLOCKS(I,Q).Y) < DISTANCE(MARIO.X,MARIO.Y,*MARIO.CLOSEST_BLOCK.X,*MARIO.CLOSEST_BLOCK.Y) Then
MARIO.CLOSEST_BLOCK = @BLOCKS(I,Q)
End If
EndIf
Next
Next
If MARIO.X < *MARIO.CLOSEST_BLOCK.X Then
MARIO.X+=1
ElseIf MARIO.X > *MARIO.CLOSEST_BLOCK.X Then
MARIO.X-=1
EndIf
If MARIO.Y < *MARIO.CLOSEST_BLOCK.Y Then
MARIO.Y+=1
ElseIf MARIO.Y > *MARIO.CLOSEST_BLOCK.Y Then
MARIO.Y-=1
EndIf
If MARIO.X = *MARIO.CLOSEST_BLOCK.X AND MARIO.Y = *MARIO.CLOSEST_BLOCK.Y Then
MARIO.CLOSEST_BLOCK = @MARIO.THROWAWAY
MARIO.BOOL_LOOKING = FALSE
MARIO.BOOL_GRABBING = TRUE
EndIf
EndIf
End Sub
Sub FIND_NEAREST_DESTINATION
If MARIO.BOOL_GRABBING = TRUE Then
For I As Integer = 0 To 40
For Q As Integer = 0 To 30
BLOCKS(I,Q).X = MARIO.X
BLOCKS(I,Q).Y = MARIO.Y-20
If DESTINATION_ARRAY(I,Q).BOOL_ACTIVATED = TRUE Then
If DISTANCE(MARIO.X,MARIO.Y,DESTINATION_ARRAY(I,Q).X,DESTINATION_ARRAY(I,Q).Y) <DISTANCE(MARIO.X,MARIO.Y,*MARIO.CLOSEST_DESTINATION.X,*MARIO.CLOSEST_DESTINATION.Y) Then
MARIO.CLOSEST_DESTINATION = @DESTINATION_ARRAY(I,Q)
EndIf
EndIf
Next
Next
If MARIO.X < *MARIO.CLOSEST_DESTINATION.X Then
MARIO.X+=1
ElseIf MARIO.X > *MARIO.CLOSEST_DESTINATION.X Then
MARIO.X-=1
EndIf
If MARIO.Y < *MARIO.CLOSEST_DESTINATION.Y Then
MARIO.Y+=1
ElseIf MARIO.Y > *MARIO.CLOSEST_DESTINATION.Y Then
MARIO.Y-=1
EndIf
If MARIO.X = *MARIO.CLOSEST_DESTINATION.X And MARIO.Y = *MARIO.CLOSEST_DESTINATION.Y Then
*MARIO.CLOSEST_BLOCK.BOOL_ACTIVATED = FALSE
MARIO.CLOSEST_BLOCK = @MARIO.THROWAWAY
*MARIO.CLOSEST_DESTINATION.BOOL_ACTIVATED = FALSE
MARIO.CLOSEST_DESTINATION = @MARIO.THROWAWAY
MARIO.BOOL_GRABBING = FALSE
MARIO.BOOL_LOOKING = TRUE
EndIf
EndIf
End Sub
[/code]
The MARIO.CLOSEST_BLOCK and MARIO.CLOSEST_DESTINATION are both pointers. When mario reaches a block, he's supposed to "deactivate" it, so he can't try to grab it again, and when he reaches a destination, he's supposed to "deactivate" that too, so he never tried to bring a block back there.
Thing is, he successfully deactivates the destinations, but NOT the blocks, so he reads the last block he grabbed as the closest block, no matter what I do! he grabs the same block and brings it back to the previous location
I know I'm pretty much clogging this thread up now, but is it possible to create a grid for a Windows.Forms application, where each control has its own cell in the grid? Kinda like JavaFX's GridPane system
It's called a TableLayoutPanel or something, it's in the toolbox. I'll have a look later if you can't find it :p
I can't actually find anything in the Toolbox because I'm using gedit :v:
[editline]28th August 2014[/editline]
I've added it into the code but I'm getting this error:
[code]collatz-gui.boo(11,19): BCE0023: No appropriate version of 'System.Windows.Forms.TableLayoutControlCollection.Add' for the argument list '(System.Type, int, int)' was found.[/code]
Here is my code:
[code]import System.Windows.Forms //Import Windows Forms
Window = Form(Text: "Collatz orbiter") //Create the Form and set its title
Table = TableLayoutPanel(ColumnCount:2, RowCount:3) //Create a table to put the objects in
NumberToVerifyHelp = Label(Text:"Number to verify:") //Create a label to tell the user what the text box is for
Table.Controls.Add(NumberToVerifyHelp, 1, 1) //Add the label to the Form
NumberToVerifyBox = TextBox //Create a text box so that the user can enter the number that they want verified
Table.Controls.Add(NumberToVerifyBox, 2, 1) //Add the text box to the Form
VerifyButton = Button(Text:"Verify") //Create a button that the user can click when they have enter their number to be verified in the text box
Table.Controls.Add(VerifyButton, 1, 2) //Add the button to the Form
Window.Controls.Add(Table) // Add the table to the Form
Application.Run(Window) //Show the Form[/code]
If I comment out the part that creates the Text Box and adds it to the table, the code compiles and runs as it should
Fixed by replacing [code]NumberToVerifyBox = TextBox[/code] with [code]NumberToVerifyBox = TextBox()[/code]
Yeah i just noticed you where working in boo :P TextBox() is probably the boo equivalent of new TextBox()
[QUOTE=proboardslol;45824349]For the life of me I can't figure this shit out
My program has a single guy (mario) running around, grabbing the nearest block, and bringing it to the nearest destination. my code for these subroutines is thus
[sp]warning: QuickBASIC[/sp]
(code)
The MARIO.CLOSEST_BLOCK and MARIO.CLOSEST_DESTINATION are both pointers. When mario reaches a block, he's supposed to "deactivate" it, so he can't try to grab it again, and when he reaches a destination, he's supposed to "deactivate" that too, so he never tried to bring a block back there.
Thing is, he successfully deactivates the destinations, but NOT the blocks, so he reads the last block he grabbed as the closest block, no matter what I do! he grabs the same block and brings it back to the previous location[/QUOTE]
Your block placement code is a bit confusing. Maybe this (and/or destination placement) is where the problem is. Can you try this with static two-dimensional arrays for blocks and destinations?
I.e. take out
[code] BLOCKS(I,Q).X = MARIO.X
BLOCKS(I,Q).Y = MARIO.Y-20[/code]
and whatever equivalent for DESTINATION_ARRAY there may be, and replace them with smaller hardcoded arrays?
[QUOTE=DrTaxi;45827697]Your block placement code is a bit confusing. Maybe this (and/or destination placement) is where the problem is. Can you try this with static two-dimensional arrays for blocks and destinations?
I.e. take out
[code] BLOCKS(I,Q).X = MARIO.X
BLOCKS(I,Q).Y = MARIO.Y-20[/code]
and whatever equivalent for DESTINATION_ARRAY there may be, and replace them with smaller hardcoded arrays?[/QUOTE]
So predetermine where the blocks will be/go, having the marios check for those locations, regardless of proximity?
Putting a quick button on my desktop to skip to the next song using a VBScript.
[code]set wshshell = WScript.CreateObject("WScript.shell")
wshshell.SendKeys("{VK_MEDIA_NEXT_TRACK}")[/code]
For some unknown reason, the virtualkeys don't work.
Returns an 'Invalid procedure call or argument'
Sorry, you need to Log In to post a reply to this thread.