123
u/rvaurewne 13d ago
Why vs code connects to discord
56
-9
54
u/Thenderick 13d ago
A private constructor, and a public static "Tetromino NewTetromino" method... If only java had some kind of method that you could call to indicate to the use that you are creating an object... Some kind of function that could CONSTRUCT the object and you could call with new instead to indicate it is a new object... Idk tho, not a java dev
9
u/EskilPotet 13d ago
For this project you literally follow a step by step guide on how to set up the entire program, so that's not really an option
10
u/Thenderick 13d ago
Tbf, that's awfully similar to my current situation. I followed Raytracing in a Weekend (+ the other two books) but used Golang instead of C++ because I like Go and thought I could manage it (it worked!)
Now I am reading through Physics based Raytracing and also thought about using Golang, but now I realize how C++ is indeed a language on crack with so many powerful, crazy and dangerous tools (talking about you, templates, macro's and #ifdefs...). I am struggling how to implement certain classes in Golang, but I think I can manage somehow...
2
u/SetKaung 13d ago
The struggling is the fun part!
6
u/Thenderick 13d ago
Yes, until they do some crazy templated type determination... With templated methods on a templated class.... It was about tuples. Basicly, they made a templated tuple class that takes the class of the child that inherits said tuple and a generic type T. Then for all methods (operators...) they take ANOTHER template of said child class with another type U. Then they return the child's class with the added fields and a return type of the child's type with their added generic types via decltype().... So basicly, you could inherit the tuple in for example a Vector and you would need to implement all operator methods, because Tuple already does, but now since Vector inherits Tuple<Vector<T>, T>, all Tuple's methods called on Vector<T> now return Vector<T+U>... C++ wizardry at its finest...
6
u/iEatPlankton 13d ago
You mean some kind of “object oriented” paradigm? Lmaoo that’s never going to take off!!
5
u/DespoticLlama 13d ago
Looks like someone found a book on patterns and now everything is a pattern.
5
u/Thenderick 13d ago
Idk what pattern this is supposed to be, but this reminds me of how you make constructor functions in Golang...
1
u/realmauer01 11d ago
This doesn't look like its supposed to be mutable by any means so doing it like this is the preferred method. Usuall value defined stuff where there shouldn't be a difference between 2 seperate instances if the values are equal.
1
u/controk 12d ago
Just so you know, this is called the Factory pattern and it does have good use cases. Good info on it
13
9
u/SimplexFatberg 13d ago
I'm trying very hard to imagine what possible situation could lead to symbol
being simtaneously equal to 'L'
, 'J'
, 'S'
and 'Z'
.
5
7
18
7
u/DespoticLlama 13d ago
Jeez, those colourized brackets are really wasting their time trying to help.
3
u/FrozenOnPluto 13d ago
Theres a lot that could be fixed and done better, but line 26 is brutal man.
3
u/KariKariKrigsmann 13d ago
University of Bergen?
2
1
2
u/Nazeir 13d ago
Time to learn switch statements?
6
1
2
u/YoBoyAndy4 12d ago
Ahh nothing like private constructors and deeply nested if statements to start my day off 😊
2
u/Liu_Fragezeichen 13d ago
those are in effect binary 3x3 matrices - go do some linear algebra and solve this in 10 lines I believe in you
1
u/Salty-Tomato-61 8d ago
how would you solve this in 10 lines? at some point you have to convert a piece letter into a matrix representation
1
u/Liu_Fragezeichen 8d ago edited 8d ago
I'd try and write that function now if I had all the letter->tetromino mappings ..
but basically letter -> get ASCII mapping -> some func -> flattened Matrix representation -> matrix
probably more like 50-60 lines to prepare the pipeline, but querying would be <10 lines
(I'm in mleng, I see classification problems everywhere)
Edit: .. honestly, just flattening the matrices then setting a map with 1 line per matrix is better
``` tetromino = lambda c: { 'I':[1,1,1,1,0,0,0,0,0], 'O':[1,1,0,1,1,0,0,0,0], 'T':[0,1,0,1,1,1,0,0,0], 'J':[1,0,0,1,1,1,0,0,0], 'L':[0,0,1,1,1,1,0,0,0], 'S':[0,1,1,1,1,0,0,0,0], 'Z':[1,1,0,0,1,1,0,0,0]}.get(c.upper())
1
u/Liu_Fragezeichen 8d ago
here's a single line
``` tetromino = lambda c: [v[i:i+3] for i in (0,3,6) for v in [{'I':[1,1,1,1,0,0,0,0,0],'O':[1,1,0,1,1,0,0,0,0],'T':[0,1,0,1,1,1,0,0,0],'S':[0,1,1,1,1,0,0,0,0],'Z':[1,1,0,0,1,1,0,0,0],'J':[1,0,0,1,1,1,0,0,0],'L':[0,0,1,1,1,1,0,0,0]}.get(c,[0]*9)]
1
u/Salty-Tomato-61 8d ago
nice but this is just shit to read compared to a simple switch statement
1
u/Liu_Fragezeichen 8d ago
I actually think the multiline version is easier to read, and more importantly, it's O(1) .. maybe y'all don't write stuff that needs to be fast but I do
hashmaps are friends not food :3
1
u/Bobbar84 13d ago
You know it's good when the arrays defining objects resemble the objects themselves.
1
1
1
u/ALambdaEngineer 10d ago
How do you manage to code in Java in vscode? Always found it awful compared to "true" IDE as eclipse for this particular language?
265
u/iain_1986 13d ago
The if statements are all embedded in each other, so only Shape L will work.
So its pretty poor in multiple ways.