UPDATE: I just noticed that Flawr was indeed the creator of Javagony. The creator of the language was mentioned at the bottom of the article rather than the top.
“That weird little question mark operator that nobody uses” Excuse me, the ternary operator is an incredibly useful tool in compacting code while still leaving it (mostly) perfectly legible
This will run forever: private static void runOne() { System.out.print(1); try { runOne(); } catch(StackOverflowError e) { runOne(); } } Eventually you will hit a StackOverflowError which is caught and replaced with a new call. Since you just had a stack overflow, the print() will cause a stack overflow but this time it is in the catch block and not the try block, which means the stack continues unwinding removing a runOne() from the stack. Eventually there will be enough stack space to run a full runOne() call, which will repeat forever.
Good idea. Until your computer simply runs out of memory. I think there might be a way to increase the amount of memory to use up before stack overflow? Or, write a native method that manually deletes a all those method calls from the stack (won't work with backwards recursion then). Well, unless java has its own special call stack, which it probably does.
The truth machine doesn't crash if you implement thread-able objects. If you call start() on a thread it behaves on its own and you can dispose of the current thread, which means no overflow! class Recursive implements Runnable { @Override public void run() { System.out.println("1"); new Thread(new Recursive()).start(); try { Thread.currentThread().join(); } catch (InterruptedException e) { e.printStackTrace(); } } }
I am late, yes, but why do you execute "Thread.currentThread().join();"? It does nothing. It joins thread x with thread x. It's like a nop instruction, just way more complicated xD.
Because of the `join`, you're not freeing the calling thread, so it doesn't get discarded. You'll probably run out of RAM or your system will crash because there are too many threads quite fast. One solution would be to have the new thread join the previous one (currently it's doing the opposite)
Wait a minute, on a second look, Javagony is basically just a way to program in functional style in Java, given the recursion and all that, which is awesome.
java is already bad.bunch of oop nonsense where the suffixes make as much sense as the ones in kayfbopt.stupid ppl talking about "clean code" and "cooperation" and "readability".real programmers use c++. (/priveleged static register intern unique_ptr*(std::heap,[=]template(T IRandomlyFoundThisSortaStuffInTheStandardLibraryItIsGood){return (unsigned long long long long)"Yes,this type is made up,and no,you shouldn't be converting const char* to a big number using builtin conversions";} sortaSerious)
You sir are a great content creator I love your humor and your paper Mario gags, i have just 6 months learning programming mainly in java and i'm happy that i can enjoy so much this piece of art.
finally someone said it! I, as a functional programmer, got so exited at the idea of a tail recursive 99 bottles of beer that I completely forgot about decrements
In the blackjack example you also may have used Math.sqrt(b-21), which is imo more clear. If b is 22 or more, then the expression would evaluate to a negative number and sqrt would throw an exception.
You can also check if an integer is greater than a number through recursion: How to check if a number is negative or positive through incursion: Create two variables that are copies of the integer you want to check. Subtract 1 from the first copy and add 1 to the other. Use a try catch to check if one of the copies has reached zero. A < B A - B = C Therefore C < 0
Victor Tran random fact (even though you probably already know this): Java has "goto" as a reserved keyword, but it has no purpose. The same applies to "const".
@@quack3891 there is no preprocessor in Java, so macros, includes, #if do not work and there is no alternative to them. In Java you can imitate constants using static final variables. They probably will be used at compile time thanks to compiler optimizations, but that is not 100% true.
For the more/less check, i think you could do it like this: Check if a > b. a=7 b=16 Int a = 1/ (int) Math.sqrt(a - b); That should also trigger the exception. If a is < than b, the answer is negative. If you sqrt a negative number, it gives a NaN (Int) converts NaN to 0 1/0 triggers exception Cool vids you got m8, keep it up!
@@branthebrave maybe but I figured it might be useful since we have try catch, the labels can be the try or catch. It couldn't be a method call since it just moves it back up I believe. I have no idea though, never used labels with try-catch
By the definition of Javagony, yes. In fact, ifs can be replaced with: try { assert (expression); {true block} } catch (AssertionError e) { {false block} }
How to abuse streams api to get past the restrictions: T o; // object to test of type T, T extends Object try { Arrays.asList(o).stream().filter(/* condition goes here */).collect(Collectors.toList()).get(0); // if block } catch (IndexOutOfBoundsException e) { // else block }
like this String str1 = "Test"; String str2 = "test"; int compare = str1.compareTo(str2); try{ int x = 1/compare; System.out.println("not equal"); }catch(Exception e){ System.out.println("eqaul"); }
I have my (hopefully) very last compsci final in 8 hours. Anyway, the name is pretty clever, but there are *far* better ways to torture yourself in Java.
new if statement: class Function { abstract void function(); } class Func1 extends Function { @Override void function() { // do something } } class Func2 extends Function { @Override void function() { // do something else } } static void main() { Function[] functions = new Function[]{new Function1(), new Function2()}; bool statement = true; functions[(int)statement].function(); }
Yeah you definitely forgot about goto statement you literally forgot it in the pre text of javagony and since it wasn't in the pre text so i cn use it and make a bit more efficient..
I might be a bit late but here's my take: public class Main { public static void main(String[] args) { xIf(1 == 2, () -> { System.out.println("True"); }, () -> { System.out.println("False"); }); } public static void xIf(boolean condition, Action ifTrue, Action ifFalse) { int divideBy = Boolean.valueOf(condition).compareTo(Boolean.FALSE); try { int x = 1 / divideBy; ifTrue.run(); } catch(Exception e) { ifFalse.run(); } } static interface Action { void run(); } }
If-else statements and switch cases are considered harmful and should not be used ever, anywhere. They're SLOW as all hell. Ternary operator, however, is fairly fine somehow, and it's a shame that you don't use it, because you should if possible instead of if-elses. Ternary operator, however, by definition only takes three arguments, so if you have a more complex case to deal with, you should check out a video here on UA-cam called something to the tune of "Branchless programming" or something like that. Branching logic loads CPU with frequently useless computations the results of which it has to ultimately flush. Getting rid of if-elses is one of the reasons pure functional languages are so damn fast, but by far not the only one of course.
Obviously the real way to print 1 infinitely is to delay so it never overflows before the heat death of the universe....or the next likely power outage.
This challenge to me is ruined by the fact you can call functions like Math. .... which have loops in them already, it should be only functions you've written and maybe system.out.println also doing it without trycatches would be more interestin too imo
@@jordanweir7187 The halting problem I suppose. I just don't know how you'd do it. Like with labels, finally, Threading, streams, or class structure abuse?
You can get conditions with || and && as well. (am at 1:23 at the moment) boolean notUsed001 = condition && doStuffIfConditionIsTrue(); doStuffIfConditionIsTrue just must return a boolean
@@Truttle1 Stick to your guns brother. Love the Channel, just subscribed. I think it is really a volume problem. I end up turning my volume up and down throughout the video. Lol
On 1:08 >Java is basically unusable now Well.. you know... Java is completely unusable even with these operators. It is not a programming language, it's just a bunch of restrictions and limitations for a programmer. It's a castrated C++ or C#, because it doesn't allow you to do basic things like operator overloading. You can not even write a small program that will not eat all your memory.
UPDATE: I just noticed that Flawr was indeed the creator of Javagony. The creator of the language was mentioned at the bottom of the article rather than the top.
uyfg
Is branchless programing allowed?
He didin't create the language, he just modified a language.
“That weird little question mark operator that nobody uses”
Excuse me, the ternary operator is an incredibly useful tool in compacting code while still leaving it (mostly) perfectly legible
This will run forever:
private static void runOne() {
System.out.print(1);
try {
runOne();
} catch(StackOverflowError e) {
runOne();
}
}
Eventually you will hit a StackOverflowError which is caught and replaced with a new call. Since you just had a stack overflow, the print() will cause a stack overflow but this time it is in the catch block and not the try block, which means the stack continues unwinding removing a runOne() from the stack. Eventually there will be enough stack space to run a full runOne() call, which will repeat forever.
AFAICT, that doesn't run forever, but does run for an extremely long time. It prints O(2^n) ones, where n is roughly how deep the stack can get.
sim1R sim1L
Good idea. Until your computer simply runs out of memory. I think there might be a way to increase the amount of memory to use up before stack overflow? Or, write a native method that manually deletes a all those method calls from the stack (won't work with backwards recursion then). Well, unless java has its own special call stack, which it probably does.
@@SimonClarkstone so what does it do on the last 1 huh?
This channel basically confirms my ability to learn about random things rather than important ones.
Keep it uppp
"I curse you to, when you use Java you experience a ton of agony!"
Don't need a curse for that
These videos bring me joy. You're really smart, kid, and you manage to make these videos interesting as well.
The truth machine doesn't crash if you implement thread-able objects.
If you call start() on a thread it behaves on its own and you can dispose of the current thread, which means no overflow!
class Recursive implements Runnable {
@Override
public void run() {
System.out.println("1");
new Thread(new Recursive()).start();
try {
Thread.currentThread().join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
I am late, yes, but why do you execute "Thread.currentThread().join();"?
It does nothing. It joins thread x with thread x.
It's like a nop instruction, just way more complicated xD.
Shut up nerd
Because of the `join`, you're not freeing the calling thread, so it doesn't get discarded. You'll probably run out of RAM or your system will crash because there are too many threads quite fast.
One solution would be to have the new thread join the previous one (currently it's doing the opposite)
@@elzearcontelly2651 I appreciate the input, at the time of writing that comment it seems i didn't fully understand .join()
could do a Thread Sleep to really slow it down until you run out of memory while still making the app seem responsive to a human
"Standard Java IDE like Eclipse or NetBeans"
_Angry IntelliJ noises_
Intelij is the best don't @ me
Angry vim noises
i don’t use java, but emacs gang
IntelliJ master race!
@@whythosenames Vim itself isn't an IDE, more like a text editor.
"That question-mark operator I never use"
**Sad ternary operator sound**
Wait a minute, on a second look, Javagony is basically just a way to program in functional style in Java, given the recursion and all that, which is awesome.
"That "l" is a lowercase L"
reminds me of OiI
the OiI in lowercase is oii
IlIlIlIlIlIl
oiI
Whats the point of Javagony? Its already agony without any changes.
Agreed.
java is already bad.bunch of oop nonsense where the suffixes make as much sense as the ones in kayfbopt.stupid ppl talking about "clean code" and "cooperation" and "readability".real programmers use c++.
(/priveleged static register intern unique_ptr*(std::heap,[=]template(T IRandomlyFoundThisSortaStuffInTheStandardLibraryItIsGood){return (unsigned long long long long)"Yes,this type is made up,and no,you shouldn't be converting const char* to a big number using builtin conversions";} sortaSerious)
The real Javagony is you putting the starting brace on the next line.
No, it's that he's catching the general Exception rather than (in this case) an ArithmeticException
Java is already javagony
You sir are a great content creator I love your humor and your paper Mario gags, i have just 6 months learning programming mainly in java and i'm happy that i can enjoy so much this piece of art.
Developer of that made java even pore painful to write. he's a true wizard.
Are streams allowed though? Because if so, the challenge is pretty easy.
3:13 The answer to that is tail recursion btw
finally someone said it! I, as a functional programmer, got so exited at the idea of a tail recursive 99 bottles of beer that I completely forgot about decrements
Or make your own stream library out of try catches :)
@@branthebrave Seems like attacking a fly with a cannon, but you could in fact do that
You can also use a new blacklimit[21] to get an ArrayIndexOutOfBounds for larger index.
This was well-named. There's something about the whole try-catch system that just makes my head hurt.
Javagony: Surprisingly usable!
In the blackjack example you also may have used Math.sqrt(b-21), which is imo more clear. If b is 22 or more, then the expression would evaluate to a negative number and sqrt would throw an exception.
I just realized that this is slooooooow, sorry.
It gives NaN for me and doesnt throw an exception for some reason
Like, you can convert nan to 0 and divide by it no problem, but still
You can also check if an integer is greater than a number through recursion:
How to check if a number is negative or positive through incursion:
Create two variables that are copies of the integer you want to check. Subtract 1 from the first copy and add 1 to the other. Use a try catch to check if one of the copies has reached zero.
A < B
A - B = C
Therefore
C < 0
Can't wait for cgony
It will be harder and more anniying
You are so underrated! People need to see your content, it's amazing!
4:24 OH NO HE'S SELF AWARE
"When you use java, you experience a ton of agony!"
Yeah?
Ah yes java with double the agony, since java is agony by itself
i love how i know enough about java to read the code but not enough to write it.
i hear a Waterflame fan, electroman adventures is a banger
==, >=,
If only goto statements existed :(
Victor Tran random fact (even though you probably already know this): Java has "goto" as a reserved keyword, but it has no purpose. The same applies to "const".
Well I didn't know about the const keyword ;)
@@Truttle1 wait so you can't even #define it or anything like that to make it do stuff?
@@quack3891 there is no preprocessor in Java, so macros, includes, #if do not work and there is no alternative to them. In Java you can imitate constants using static final variables. They probably will be used at compile time thanks to compiler optimizations, but that is not 100% true.
@@Daniikk1012 huh, interesting, never knew that
the question mark operator you never use is the ternary operator and condenses a 5 line else if statement into one line
Since this video came out I started using it way more.
weirdly enough, this has helped me understand try catch better.
You can parse Integers without the need of try catch? Awesome.
tbh the name is the best part
Astronomy487 Java with a twist of agony!
I don't know java so I dont know if this would work but for the blackjack program couldnt you just cast the expression a > b (inverse of a
For the more/less check, i think you could do it like this:
Check if a > b. a=7 b=16
Int a = 1/ (int) Math.sqrt(a - b);
That should also trigger the exception.
If a is < than b, the answer is negative.
If you sqrt a negative number, it gives a NaN
(Int) converts NaN to 0
1/0 triggers exception
Cool vids you got m8, keep it up!
Or, since √x has no real answer for x
Regular Java IS agony
2:24 nextInt(); exists
Wow this is really Javagony, he's using Eclipse and mentioned NetBeans
You could create a Timer to emulate the while loop, but what fun is that
5:36
My first thought would be to try 1/max(27-21, 0)
which works lol
edit: My solution is better than the one in the video, lolololol
did you mean "x"?
okay but what about streams?
3:17 just pop the top value from the stack and discard it within the loop, then you can go forever
You could also use asserts as a more conventional if statement
And I thought Javagony was just Java...
3:55 Electroman adventure music starts. Where are all geometry dash players?
was half expecting labels but I assume desperation != heresy
You'd need some more conditional control, like if, for them to be useful here, otherwise it's basically a method call. I think.
@@branthebrave maybe but I figured it might be useful since we have try catch, the labels can be the try or catch. It couldn't be a method call since it just moves it back up I believe.
I have no idea though, never used labels with try-catch
Only doing recursion is also a style of programming language. If you are a fan, look at prolog
What if the AP college board Gets there hands on this
Can you use Boolean expressions, then use or cast it as an int? So if an expression is false then dividing 1 by it would throw an exception
By the definition of Javagony, yes. In fact, ifs can be replaced with:
try {
assert (expression);
{true block}
} catch (AssertionError e) {
{false block}
}
I'm pretty sure Math.addExact() uses an if statement tho. Perhaps another way of checking would be with recursion
I'm pretty sure dividing uses an if statement too.
@@official-obama dividing does not use an if statement, it is a jvm instruction
@@arjix8738 yeah, but i'm pretty sure jvm uses an if statement
@@official-obama I don't know about that, but real assembly has an instruction for division.
I can't see why an if statement is necessary.
@@arjix8738
if(b != 0) {
return a/b;
} else {
freak_out();
}
I couldn't find the Pastebin link in the description, but if you did, you'll most likely paste there as a guest user.
Kevin Bhasi just added it
couldnt you also use a logarithm to check if a number is greater/less than another
Why does it exist? Because why not!
Is there a "goto" functionality in java like in c/c++? That would've fixed the stack overflow error right?
There isn't
goto is a thing in procedural languages mostly. C++ is a superset of C so it supports it even though it is technically not procedural.
Math.addExsct is in java? Made?
How to abuse streams api to get past the restrictions:
T o; // object to test of type T, T extends Object
try {
Arrays.asList(o).stream().filter(/* condition goes here */).collect(Collectors.toList()).get(0);
// if block
} catch (IndexOutOfBoundsException e) {
// else block
}
I literally learned about try earlier today
yea u did, i remember that
was half-expecting it to be only labels instead of try catch
This is just normal Java.
Is short-circuit banned as well?
technically x > y is still allowed...
is compareTo allowed
like this
String str1 = "Test";
String str2 = "test";
int compare = str1.compareTo(str2);
try{
int x = 1/compare;
System.out.println("not equal");
}catch(Exception e){
System.out.println("eqaul");
}
5:03 *1 B O T T L E S*
Hate to be that guy but Arithmetic is spelled incorrectly at 1:50
I understand this without knowing java
Doesn't Java have goto? And isn't that *not* banned?
is there a pythagony?
python but the only operators are square and sqrt
I have my (hopefully) very last compsci final in 8 hours.
Anyway, the name is pretty clever, but there are *far* better ways to torture yourself in Java.
Using Eclipse? Good man.
Why not loop infinitely by consuming an infinite stream?
That would be cheating since it's implemented with banned statements.
@@ConcerninglyWiseAlligator and Math too
and 1/(value)
Is Java like C#, empty spaces don't matter?
Yes
new if statement:
class Function {
abstract void function();
}
class Func1 extends Function {
@Override
void function() {
// do something
}
}
class Func2 extends Function {
@Override
void function() {
// do something else
}
}
static void main() {
Function[] functions = new Function[]{new Function1(), new Function2()};
bool statement = true;
functions[(int)statement].function();
}
Yeah you definitely forgot about goto statement you literally forgot it in the pre text of javagony and since it wasn't in the pre text so i cn use it and make a bit more efficient..
The real agony comes from the fact that you arent using IntelliJ
1:00 What do you mean, switch case is useless?
I might be a bit late but here's my take:
public class Main
{
public static void main(String[] args) {
xIf(1 == 2, () -> {
System.out.println("True");
}, () -> {
System.out.println("False");
});
}
public static void xIf(boolean condition, Action ifTrue, Action ifFalse) {
int divideBy = Boolean.valueOf(condition).compareTo(Boolean.FALSE);
try {
int x = 1 / divideBy;
ifTrue.run();
} catch(Exception e) {
ifFalse.run();
}
}
static interface Action {
void run();
}
}
make a video about JSF***, which is simply JavaScript, but you are only allowd six different characters: []()!+
If-else statements and switch cases are considered harmful and should not be used ever, anywhere. They're SLOW as all hell.
Ternary operator, however, is fairly fine somehow, and it's a shame that you don't use it, because you should if possible instead of if-elses. Ternary operator, however, by definition only takes three arguments, so if you have a more complex case to deal with, you should check out a video here on UA-cam called something to the tune of "Branchless programming" or something like that. Branching logic loads CPU with frequently useless computations the results of which it has to ultimately flush. Getting rid of if-elses is one of the reasons pure functional languages are so damn fast, but by far not the only one of course.
Obviously the real way to print 1 infinitely is to delay so it never overflows before the heat death of the universe....or the next likely power outage.
bro what about goto
it exists in the language, but it's usage is explicitly prohibited
This challenge to me is ruined by the fact you can call functions like Math. .... which have loops in them already, it should be only functions you've written and maybe system.out.println
also doing it without trycatches would be more interestin too imo
How would you do it "without try-catches"?
@@branthebrave wat problem would u like me to try out without trycatches?
@@jordanweir7187 The halting problem I suppose. I just don't know how you'd do it. Like with labels, finally, Threading, streams, or class structure abuse?
@@branthebrave thats kind of a big problem, i meant like one of these examples he gives in the video like the truth machine or something
@@jordanweir7187 Lol. Try the truth machine one 1 infinitely or 0
pain
i was expecting javascript and agony. slightly disappointed
Now do a javagonyScript lol
You can get conditions with || and && as well. (am at 1:23 at the moment)
boolean notUsed001 = condition && doStuffIfConditionIsTrue();
doStuffIfConditionIsTrue just must return a boolean
Shouldn't you comment your code to explain what you're doing-ya know best practices and all...
No. If you need comments then your code is hard to understand, but this may be.
Why not just use while(){}?
You have informative, well produced, interesting videos; I just wish you would stop with the horrid cartoon characters. Lol keep up the good work.
I've been trying to limit how much I use the cartoon characters, but I probably won't completely get rid of them.
@@Truttle1 Stick to your guns brother. Love the Channel, just subscribed. I think it is really a volume problem. I end up turning my volume up and down throughout the video. Lol
On 1:08
>Java is basically unusable now
Well.. you know... Java is completely unusable even with these operators. It is not a programming language, it's just a bunch of restrictions and limitations for a programmer. It's a castrated C++ or C#, because it doesn't allow you to do basic things like operator overloading. You can not even write a small program that will not eat all your memory.
1st read java-gony instead of jav-agony
Reply to me
No
is there no tail call optimization?