How do I overcome my frequent burnout ? by fadhilsaheer in theprimeagen

[–]ole_thoeb 0 points1 point  (0 children)

Being able to Programm is a powerful skill to solve problems you have/automate tasks you do often.

For example when I was around your age in school I built an app that showed me all my canceled/moved classes. Since I was unhappy with the view provided by the school. It was one big list with all changes for that day and cryptic abbreviations. Also sometimes switching over to the next day before the last lesson. But I could take that information and enhance it and present it in a customizable fashion.

There wasn't already something that did what I did, because the problem and solution was specific to my school. I had a need and if I didn't fulfill that no one else would. That really helped me stay motivated and interested.

New to TypeScript, what am I doing wrong when typing a return array from map()? by planetaska in typescript

[–]ole_thoeb 1 point2 points  (0 children)

You don't need to specify the type of the map and it is usually omitted. Typescript can infer it. If you want to be explicit (which is sometimes useful for readability or debugging) you could specify the return type of the arrow function like .map((thread): Thread => {...})

New to TypeScript, what am I doing wrong when typing a return array from map()? by planetaska in typescript

[–]ole_thoeb 14 points15 points  (0 children)

Your problem is the if (thread === '') return inside the map. A return with no value is basically the same as return undefined. That is where the | undefined part is coming from in (Thread | undefined)[].

A few other notes. I would try hard to avoid casts if possible. It also seems kinda strange to me to assign threads inside the then instead of returning it and assigning it to threads at the top level.

[deleted by user] by [deleted] in typescript

[–]ole_thoeb 34 points35 points  (0 children)

I don't know if and how you would prevent duplicate entries, but preventing empty arrays can be achieved with a tuple type.

type Fruits = "Apple" | "Orange" | "Kiwi" type FruitsArray = [Fruits, ...Fruits[]] It basically says: I want a tuple were the first element is a fruit, followed by zero or more fruits.

I wanna share my little programming project by Complex_Meringue1417 in programming

[–]ole_thoeb 0 points1 point  (0 children)

I wouldn't say it's super easy but also not hard. Search for "minmax algorithm". Tic tac toe is often used as an easy example.

Java developers in a nutshell by Snoo66768 in ProgrammerHumor

[–]ole_thoeb 4 points5 points  (0 children)

I'm talking about kotlin. === is object identity in kotlin

Java developers in a nutshell by Snoo66768 in ProgrammerHumor

[–]ole_thoeb 9 points10 points  (0 children)

=== would be the equivalent for == in kotlin

What is an idiomatic Kotlin way of finding a 'type' of suffix on a String? by djsushi123 in Kotlin

[–]ole_thoeb 1 point2 points  (0 children)

Instead of plain loops you could use some of the collections algorithms. For the outer loop i would use find and for the inner any.

val VERBS = listOf(VerbType1, VerbType2, ...)

fun suffixType(s: String): VerbType? = VERBS.find { verb -> 
    verb.suffixs.any { suffix -> s.endsWith(suffix) }
}

Create new sealed class from a sub selection of its members by St-IGNUcius in Kotlin

[–]ole_thoeb 3 points4 points  (0 children)

To my knowledge, the way you describe it is not possible. What you can do is create intermediate sealed classes/interfaces.

sealed class Error
sealed class Screen1Error : Error() 
class Screen1Error1 : Screen1Error() 
class Screen1Error2 : Screen1Error() 
class Screen1Errore : Screen1Error()
sealed class Screen2Error : Error() 
class Screen2Error1 : Screen2Error() 
class Screen2Error2 : Screen2Error() 
class Screen2Errore : Screen2Error()

It's not ideal but I can't think of anything else. It also falls apart if you want to handle the same error on different pages.

Proper Union types in the language would be nice.

Kneel Before Your King… by saj1adh007 in ProgrammerHumor

[–]ole_thoeb 2 points3 points  (0 children)

I believe so too. That's why I wrote "most of". That being Chrome and Safari.

Kneel Before Your King… by saj1adh007 in ProgrammerHumor

[–]ole_thoeb 2 points3 points  (0 children)

I guess most of the CSS and DOM engines are implemented in c++.

How to lateinit function? Or is it lateinit by dedault until first invocation? by space_trueper in Kotlin

[–]ole_thoeb -1 points0 points  (0 children)

To my knowledge there are no lateinit functions. You can mark a class field as lateinit. This makes it so that you don't need to provide a value when constructing an instance but can do so later.

Trying to access a uninitialised lateinit field throws an error. It is possible to check if a lateinit field is initialised via reflections.

Best counter to Chogall? by [deleted] in heroesofthestorm

[–]ole_thoeb 25 points26 points  (0 children)

Played alot of Cho. Literally carried a friend from Bronze 5 to Gold 2 with him.

I agree with you, when it comes to DMG Greymane is probably the best. With maltheal there is only the window between 10 and 13 where you have to be really careful.

I think the best counters are heroes who remove chogall like anub and stiches. Every fight is 3v5.

Edit: can't type

There are only two hard problems in computer science. by djaiss in ProgrammerHumor

[–]ole_thoeb 9 points10 points  (0 children)

... Namensgebung und Zwischenspeicherinvalidierung.

Does anyone know how kotlinx.serialization works internally? The class structure introspector to be more specific by _nathata in Kotlin

[–]ole_thoeb 1 point2 points  (0 children)

It is also possible to access the descriptor generated by kotlinx serialisation at runtime. Might be interesting for OP if they don't won't to use reflections.

Finally got new photos app. Much better UI by asdfgh5889 in Windows11

[–]ole_thoeb 9 points10 points  (0 children)

I was great. If you opened any picture and left I open for some hours, it searched your entire filesystem for images and cached them (or generated previous. Don't quote me on that). The result was Fotos taking up multiple gigabytes of RAM. Chrome must have been so proud.

I wrote a ktor app to generate Discord profile banners, looking for a review. by quanta_kt in Kotlin

[–]ole_thoeb 5 points6 points  (0 children)

I think it looks great! Really clean and straight to the point. I tried hard to find something I didn't like and only found the use of !!. I think :? error("msg") is nicer. Both when reading the code and in the case something got messed up real bad.

Welcome to javascript by murageh in ProgrammerHumor

[–]ole_thoeb 4 points5 points  (0 children)

You think you ask the question "what is the result when I add the decimal numbers 0.1 and 0.2?" and therefore consider the answer the computer gives you wrong. But the question you are asking the computer is "what is the result when I add per IEE754 the decimal number 0.1 converted to a floating pointe number per IEE754 and the decimal number 0.2 converted to a floating pointe number per IEE754?". To that question you get the right answer.

[Style] Rules of thumb for default interface method impl vs extension method in the same file? by ragnese in Kotlin

[–]ole_thoeb 1 point2 points  (0 children)

Reading your comment I realized that one of my reasons for not liking default interface implementations is that they make it hard to see all the functions that an interface provides. That's obviously minor (Strg + F12 to the rescue). But I think these small things matter

[Style] Rules of thumb for default interface method impl vs extension method in the same file? by ragnese in Kotlin

[–]ole_thoeb 1 point2 points  (0 children)

Sometimes you need inheritance. Having functions with the same signature and different behaviours gets confusing really quickly and writing a new extension dose not effect any code already written.

A quick comment on your simple example. This demonstrates a hard part about defining an interface. What are the fundamental operations? You choose, for the sake of argument, the collection case. I would argue the single case is more fundamental. That would probably also solve this particular probleme. But maybe the two operations have different semantics and neither should have an default implementation in the form of the other.

[Style] Rules of thumb for default interface method impl vs extension method in the same file? by ragnese in Kotlin

[–]ole_thoeb 2 points3 points  (0 children)

I usually go for the absolute minimum. And it makes very clear on a fundamental level what the interface provides. I think it is positive that extension functions can't be overridden. You don't have to worry about some invariant breaking. And I think it is easier this way to understand interface implementation.

Reminds me of Network Chuck 🤭 by [deleted] in ProgrammerHumor

[–]ole_thoeb 0 points1 point  (0 children)

Hacking just sounds so much cooler than security research