CodingWithTom
CodingWithTom
  • 30
  • 28 957
How to create a permanent On-Screen Clock for Windows
Here I show how to make a permanent on screen clock in windows. You can change the position and it will always be on top, even when playing games or youtube.
Source code:
github.com/hcsalmon1/On-Screen-Clock
If you would like to learn chess, you can check out my game Chess Tools on steam:
store.steampowered.com/app/2741350/Chess_Tools/
Переглядів: 65

Відео

Zig - A 12-Minute Overview! Everything You Need to Get Started!
Переглядів 3152 місяці тому
A very short summary of Zig. Basically all you need to know to start using it. Timestamps: 0:00 Intro 0:06 Creating variables 0:40 Basic Types 1:17 Text Types 2:16 Console output 2:55 Printing specific types 3:47 Functions 4:34 If statements 5:15 Switch statements 6:13 For loops 7:27 While loops 7:36 Structs, unions, enums and errors 8:17 Handling errors 10:10 Using other zig files 10:44 Runnin...
Beginner's Guide to Zig Part 22 - Passing by value and reference
Переглядів 1813 місяці тому
When you should pass by reference or by value in zig Timestamps: 0:00 Intro 0:06 Passing an integer by ref or value 2:12 Passing a struct by ref or value 4:51 String example, how this can cause errors 6:21 Error example 6:40 Try to work out the error 9:33 Passing const or var variables by reference If you would like to learn chess, you can check out my game Chess Tools on steam: store.steampowe...
Complete Beginner tries to Learn Rust from scratch!
Переглядів 1343 місяці тому
As I don't know anything about Rust I thought it would be interesting for people to watch me suffer learning it. I'll continue this series if people want. Timestamps: 0:00 Intro, my experience in Rust 1:17 List of projects 1:28 Hello world 2:10 Incrementing an array 8:09 Showing user age in months 18:05 Password Generator 24:11 Outro If you would like to learn chess, you can check out my game C...
Statically and Dynamically Typed Languages Explained | Coding Concepts
Переглядів 2473 місяці тому
In this video I explain languages that have designated types and ones with undesignated types. Timestamps: 0:00 Introduction 0:09 What are Data Types? 1:51 Statically Typed Languages 2:13 Java examples 5:57 Dynamically Typed Languages 6:21 Python Example 11:19 Statically Typed Positives and Negatives 12:44 Dynamically Typed Positive and Negatives 13:56 Some Problems with Dynamic languages If yo...
Procedural, Object Oriented and Functional Programming Explained | Coding Concepts
Переглядів 11 тис.3 місяці тому
In this video I give an explanation and examples of the three most popular programming paradigms. Timestamps: 0:00 Introduction 0:13 Procedural Definition 0:41 Procedural Code 2:14 OOP definition 2:39 What are objects? 4:21 Object Oriented Code 6:35 Functional Definition 6:53 What is recursion? 8:55 Functional Code 11:14 Procedural Positives and Negatives 12:52 Object Oriented Positives and Neg...
Stack and Heap Memory | Coding Concepts
Переглядів 1,8 тис.3 місяці тому
Here I explain the basic difference between the stack and the heap in programming. Timestamps: 0:00 Introduction 0:13 Stack memory 0:42 Stack Example 1 3:44 Stack Example 2 4:47 Heap Memory 5:01 Heap Example 7:36 Stack Overflow Error 8:12 Memory Leaks 9:11 Some Languages and how they control memory 10:25 Summary of stack and heap memory If you would like to learn chess, you can check out my gam...
Beginner's Guide to Zig Part 21 - Creating a Generic Linked List
Переглядів 2993 місяці тому
Here I show how to make a linked list using only integers. Then a generic linked list. Timestamps: 0:00 Introduction 0:22 Linked list with only integers 0:53 Explaining each function 3:43 Showing the results 4:35 Generic Linked list for any type 6:51 Showing the results of the generic linked list 8:00 Lots of the standard library are anonymous structs Link to the code used in this series: githu...
Beginner's Guide to Zig Part 20 - Iterators and Anonymous structs
Переглядів 1753 місяці тому
Here I explain basic iterators and give an introduction to anonymous structs Timestamps: 0:00 Introduction 0:40 Custom Iterator with a single delimiter 2:14 Custom Iterator with slices 3:26 The inbuilt iterators 5:40 Anonymous Structs Link to the code used in this series: github.com/hcsalmon1/Zig-Tutorial-Project If you would like to learn chess, you can check out my game Chess Tools on steam: ...
How Zig Improved C! (Updated)
Переглядів 3,8 тис.3 місяці тому
This is an updated version of a previous video to fix the errors that I made and give better examples. Timestamps: 0:00 Introduction 0:05 Remake explanation 0:14 What is Zig? 0:24 One: Index out of Range example 2:42 Two: Null pointers 4:18 Three: Parsing integers with errors 7:36 Find possible errors in zig 8:05 Four: Function order and importing other files 10:25 Summary If you would like to ...
Beginner's Guide to Zig Part 19 - How to find error Lists, errdefer and more about optionals
Переглядів 1223 місяці тому
Here I show how to find error lists and show more about optionals Timestamps: 0:00 Introduction 0:10 How to find a list of possible errors 1:05 Using catch directly 1:50 errdefer 2:15 Some other error lists 4:30 Optionals in more detail Link to the code used in this series: github.com/hcsalmon1/Zig-Tutorial-Project If you would like to learn chess, you can check out my game Chess Tools on steam...
Beginner's Guide to Zig Part 18 - Making a release build
Переглядів 744 місяці тому
Here I show how to simply make a release build without using the build system Timestamps: 0:00 Introduction 1:01 Build options 1:41 ReleaseSafe 2:20 ReleaseFast 2:49 ReleaseSmall 3:11 Debug 3:54 Comparing the difference with my zig chess engine Link to the code used in this series: github.com/hcsalmon1/Zig-Tutorial-Project If you would like to learn chess, you can check out my game Chess Tools ...
Beginner's Guide to Zig Part 12 - Printing, converting and parsing floats (reupload)
Переглядів 964 місяці тому
Here I cover floats, how to print, convert and parse them Timestamps: 0:00 Introduction 0:15 Simple float types 1:40 Converting floats 4:01 Parsing floats and converting weight Link to the code used in this series: github.com/hcsalmon1/Zig-Tutorial-Project If you would like to learn chess, you can check out my game Chess Tools on steam: store.steampowered.com/app/2741350/Chess_Tools/
Beginner's Guide to Zig Part 17 - Build System - How to build for different platforms
Переглядів 2404 місяці тому
Here I show how to build a project for different platforms Timestamps: 0:00 Introduction 1:03 How to setup a project directory 1:26 How to build this project 2:12 How to build for multiple systems 5:10 CrossTarget of many platforms and CPUs 6:55 Zig has a lot of build commands 7:29 Building for different platforms 8:39 Summary Where I got half the code: ziglang.org/learn/build-system/ Link to t...
Beginner's Guide to Zig Part 16 - How to track memory allocations
Переглядів 3734 місяці тому
Here I show how to track memory allocations and detect leaks Timestamps: 0:00 Introduction 0:26 Tracking Allocator 1:48 I tried to make a Strict struct 2:53 How to track memory 6:08 Summary of the Tracking Allocator Link to the code used in this series: github.com/hcsalmon1/Zig-Tutorial-Project If you would like to learn chess, you can check out my game Chess Tools on steam: store.steampowered....
Beginner's Guide to Zig Part 15 - Threading
Переглядів 2304 місяці тому
Beginner's Guide to Zig Part 15 - Threading
Beginner's Guide to Zig Part 14 - Opening and parsing a file
Переглядів 3074 місяці тому
Beginner's Guide to Zig Part 14 - Opening and parsing a file
Beginner's Guide to Zig Part 13 - Compiling C code and converting C to Zig
Переглядів 2014 місяці тому
Beginner's Guide to Zig Part 13 - Compiling C code and converting C to Zig
I compared the performance of 9 programming languages!
Переглядів 2,9 тис.4 місяці тому
I compared the performance of 9 programming languages!
Beginner's Guide to Zig Part 11 - Switch statements
Переглядів 1534 місяці тому
Beginner's Guide to Zig Part 11 - Switch statements
Beginner's Guide to Zig Part 10 - Testing and Expect
Переглядів 1424 місяці тому
Beginner's Guide to Zig Part 10 - Testing and Expect
Beginner's Guide to Zig Part 9 - ArrayList - Dynamic arrays
Переглядів 1924 місяці тому
Beginner's Guide to Zig Part 9 - ArrayList - Dynamic arrays
Beginner's Guide to Zig Part 8 - Pointers and Optionals
Переглядів 2524 місяці тому
Beginner's Guide to Zig Part 8 - Pointers and Optionals
Beginner's Guide to Zig Part 7 - Comptime - How to make generics
Переглядів 3804 місяці тому
Beginner's Guide to Zig Part 7 - Comptime - How to make generics
Beginner's Guide to Zig Part 6 - Allocators and Memory
Переглядів 8414 місяці тому
Beginner's Guide to Zig Part 6 - Allocators and Memory
Beginner's Guide to Zig Part 5 - Structs, unions and enums
Переглядів 2474 місяці тому
Beginner's Guide to Zig Part 5 - Structs, unions and enums
Beginner's Guide to Zig Part 4 - Errors
Переглядів 3164 місяці тому
Beginner's Guide to Zig Part 4 - Errors
Beginner's Guide to Zig Part 3 - Converting Variables, finding index and integer overflows
Переглядів 4554 місяці тому
Beginner's Guide to Zig Part 3 - Converting Variables, finding index and integer overflows
Beginner's Guide to Zig Part 2 - Slices, Printing, If statements and loops
Переглядів 8604 місяці тому
Beginner's Guide to Zig Part 2 - Slices, Printing, If statements and loops
Beginner's Guide to Zig Part 1 - Functions, Variables, Printing, Build system
Переглядів 3 тис.4 місяці тому
Beginner's Guide to Zig Part 1 - Functions, Variables, Printing, Build system

КОМЕНТАРІ

  • @shawn576
    @shawn576 16 днів тому

    Why did you declare average as an integer?

  • @ericmisha
    @ericmisha 21 день тому

    In your example where number:u8 = 254 You can, as shown in video, "roll over boundary": number +% 10 // number is 8 But you can also use so called "sentinel" to "stop at (higher or lower) boundary": number +| 10 // number is 255 which is the max for u8

  • @ericmisha
    @ericmisha 21 день тому

    (assuming a,b,c,d are booleans for the sake of simplicity) Instead of: if (a || b) use: if (a or b) Instead of: if (a && b) use: if (a and b) You can also combined them as you'd expect, for example: if ((a and b) or (c and d))

  • @skiiwars8991
    @skiiwars8991 Місяць тому

    Does including an exclamation point for functions returning void mean that the function could return either void or an error? And if so, would running if(result) |val| else |err| Always go to the else statement (assuming zig allows comparing void or casting void to bool) Is this case different or does it work the same as any other type?

    • @CodingWithTom-tn7nl
      @CodingWithTom-tn7nl Місяць тому

      I don't think you can capture the variable like this: if (result) |val| You can't use a void type, so capturing won't work. You can do this though: if (result) { std.debug.print("No errors ", .{}); } else |err| { std.debug.print("Error {} ", .{err}); } If you just return from that function call, then 'result' will be void and not an error so will print "No errors". Using a variable in an if like this: if (result) This simply mean if the variable isn't an error. It won't matter the type, void or not.

  • @wassim-akkari
    @wassim-akkari Місяць тому

    I think the matrix could be done this way in zig: const matrix = [_][3]i32{ .{ 1, 2, 3 }, .{ 4, 5, 6 }, .{ 7, 8, 9 }, }; or // const matrix: [3][3]i32 = .{ .{ 1, 2, 3 }, .{ 4, 5, 6 }, .{ 7, 8, 9 }, };

  • @ivolol
    @ivolol 2 місяці тому

    Having your camera in the top left instead of top right was definitely a poor choice. You might like microsoft-windows-terminal its better version of command prompt

  • @artemhnilov
    @artemhnilov 2 місяці тому

    Great channel! Thank you!

  • @SilasDuarte-e9k
    @SilasDuarte-e9k 2 місяці тому

    Zig is the king 👑😎

  • @privacyvalued4134
    @privacyvalued4134 2 місяці тому

    8:50 "Which gets very annoying when you want to test stuff." This is the sort of thing I do all the time. I already hate Go for this nonsense. If a developer is debugging code, let it just build and run. While someone is developing software, they have all kinds of cruft they are churning out - half finished thoughts/ideas but need to test. It is NOT an error to not use a declared variable. Dump out a warning and then carry on. I'm now out on Zig too. Compilers should get out of developer's way and let them write software however they want to write it.

  • @privacyvalued4134
    @privacyvalued4134 2 місяці тому

    0:58 "But has a lot of flaws. Things like header files." Huh? I've never once considered header files to be a "flaw" of C (or C++). The macro preprocessor that results in nightmarish, unreadable gibberish? Absolutely. The C/C++ macro preprocessor is fundamentally broken by design and should have been redesigned decades ago to not be terrible. The concept of header files themselves are not really an issue. In fact, you have an @import at the top of your code, which is the same basic concept that you are complaining about being in C/C++.

    • @CodingWithTom-tn7nl
      @CodingWithTom-tn7nl 2 місяці тому

      My problem with c/c++ is not the fact that you have to import things. That's easy to do (once you've actually made a header file). Let's say you have 100 functions in a cpp file and you want to use them all in another file. You will need to manually copy the names of every functions into a header file so you can use them. This is unnecessarily tedious. Then there are linker errors, the problems with trying to create global variables and the requirement to put functions above other functions that reference them. In Zig you just put 'pub' before functions and variables and you can use them in other files. And I've never gotten a linker error. Another advantage to zig is everything is separate from each other. If you have two files with a function/variable with the same name, it won't create an error, as you access them similarly to classes.

  • @flatmapper
    @flatmapper 2 місяці тому

    Why to use Zig if we have already hyping Rust expansion

    • @CodingWithTom-tn7nl
      @CodingWithTom-tn7nl 2 місяці тому

      -Zig is easier to learn -Zig offers full memory management, so you can choose when to heap allocate or not. In Rust heap allocations are done for you. -Zig is slightly faster, depending on the program -Zig can easily call and compile C and C++ code -Zig can compile for any platform without needing to actually compile on that system

    • @ozzy-fr7vj
      @ozzy-fr7vj 2 місяці тому

      Memory allocation patterns Try rust non linear data structures like binary tree To make the this work in rust you have to wrap it refcell to push mutable check to runtime And wrap refcell in rc to allow multiple owner then wrap in option Hence option<rc<refcell<treenode>>> is the final type Now try implementing a little bit complex algo like morris traversal The code will be an absolute mess with this, all of this just to avoid error prone malloc and free, instead try a arena allocation now this extremely simplifies the code and lifetime are also known just one allocation and free are needed the tangled mess of malloc and tree along with raii is also gone Till rust support this feature in stable version, right now it’s in nightly and there seems to be no push allow different allocations pattern in rust Language like zig and c will still remain superior to rust

  • @aidan-131
    @aidan-131 2 місяці тому

    nice vid mate, cheers

  • @Jediahgames
    @Jediahgames 3 місяці тому

    Why the hell would you use Stringbuilder for that?

  • @SirRichard94
    @SirRichard94 3 місяці тому

    Your FP example and conclusions are not very good. The cost of recursion can be minimized with language support of tail end optimization. And you didnt show some of the most important features which hare first class functions, lambdas and closures which would be useful for this program. Sum could be a reduce operation. You'd likely separate the writing away from the output function and also make it with a reduce. Something kind of like this. Pseudocode: let sum = reduce(numbers, 0, +) let avg = sum / count(numbers) let output = reduce(numbers, "[ " , (a, b) => a ++ b ++ ", ") ++ "] average = " ++ to_string(avg) ++ ", sum = "++ to_string(sum) ++ "/n" print(output)

  • @randomgamevideos241
    @randomgamevideos241 3 місяці тому

    i agree with you, normally i try to avoid recursion unless it is the only solution i see, i prefer loops over recursions, i can definitely say my code is a mix of all three styles ( when the style is needed ).

  • @madlep
    @madlep 3 місяці тому

    Great video. One little nitpick about binary representation of negative numbers: The example here is using "ones' complement" to encode the numbers (highest bit indicates negative, all other bits act the same), but virtually all CPUs designed since the 1960s will use "twos' complement" instead. So "11000001" would actually be -63 on a modern computer with twos complement (-128 + 64 + 1), NOT -65, like it would be with ones complement (-64 + -1)

    • @CodingWithTom-tn7nl
      @CodingWithTom-tn7nl 3 місяці тому

      I realized this afterwards after watching another video and it was too late to change it. I'll keep it in mind for future videos.

  • @madlep
    @madlep 3 місяці тому

    10:28 It’s not so much that functional “gets a bit weird”, it’s more that this code doesn’t really make use of the language tools available. You almost never want to manually manage recursion when you’re iterating over a collection when you’re doing FP, and instead would want to use higher order `map` / `reduce` etc functions provided by the language or a library. I’m not an expert on C#, but from what I understand `Select()` and `Aggregate()` function call would do the trick here.

  • @SchoolyB
    @SchoolyB 3 місяці тому

    Procedural FTW

  • @Nellak2011
    @Nellak2011 3 місяці тому

    --------- My Procedural style: 4 LOC, with mutation and straightforward logic const main = () => { const nums = std.getInput("enter array of numbers") // or however it is done let sum = 0 for (const num of nums) { sum += num } console.log(`Total: ${sum} Average: ${sum / nums.length}`) } --------- My Functional style: 4 LOC, with no mutations and concise logic const average = nums => nums.reduce((acc, el) => {sum: acc.sum + el, avg: (acc.sum + el)/nums.length}, {sum: 0, avg: 0}) const display = ({sum, avg}) => console.log(`Total: ${total} Average: ${average}`) const main = () => { const nums = std.getInput("enter array of numbers") // or however it is done display(average(nums)) } --------- My OOP style (I never use it so it may have syntax issues):16 LOC, with mutations and convoluted logic class displayNumber { let sum, average = 0 constructor(nums) { let newSum = 0 for (const num of nums) { newSum += num } this.sum = newSum this.average = newSum / nums.length } display = () => console.log(`Total: ${this.sum} Average: ${this.average}`) } const main = () => { const nums = std.getInput("enter array of numbers") // or however it is done?? let displayNumber = new displayNumber(nums) displayNumber.display() } ---------- FP > Procedural > OOP

  • @Whatthetrash
    @Whatthetrash 3 місяці тому

    Odin mentioned! :)

  • @alexanderzikal7244
    @alexanderzikal7244 3 місяці тому

    I learn Rust now also. Doing it a little Bit slower. Reading the rust-Book first.

  • @CodingWithTom-tn7nl
    @CodingWithTom-tn7nl 3 місяці тому

    I did, kind of, find out what a trait is in Rust after the video. It's basically like a template or interface in other languages. So the compiler was expecting a certain variable and I was giving it the wrong one, so it didn't fulfil the trait. That's how I understand it anyway.

  • @yes5421
    @yes5421 3 місяці тому

    I’m a freshman going into uni and I’ve studied for the Java oracle certification a couple years ago, so I am familiar with the concepts theoretically however never implemented them into an actual project. What project should I do with Java to be familiar and gain my memory back of Java as I am a bit rusty but remember concepts and am familiar with OOPS programming.

    • @arcurnow
      @arcurnow 3 місяці тому

      Woof, that’s a tricky one. Hopefully someone else can give you a better answer, but I’d say build something you’re interesting in. That’ll help keep you going. Identify a problem and invent a solution. Can be something that’s already been solved a thousand times over, but that doesn’t matter cuz it’s not the point. An example from my own experience. During the COVID lockdown rock climbers couldn’t easily go to the climbing gym to train. I built an app that allowed people to upload pictures of climbs from their gym along with the solution to said climb that other climbers could study and guess the betas (one of the correct routes up the climbing problem). The user could click a hold and define what kind of hold it was (ie right hand starting hold) and if it was a correct part of the beta they could move on to the next climbing move (left heel hook on this hold… on and on with the rest of the moves. All of it was shared and posted in a social media style. It only ever ran locally on my machine but it was interesting and kept me going through the confusing / difficult parts. Maybe thinking in terms of “find a problem and solve it” might get the juices flowing. Good luck young sir!

  • @abgvedr
    @abgvedr 3 місяці тому

    It wont be a lot slower with abstractions.

  • @kcvinu
    @kcvinu 3 місяці тому

    What the.... You are using SEMICOLONS for Odin ? Dude that's unnecessary!!! And in Odin, if you want a new line for every printf, use fmt.printfln(). You can use function parameters like this -- foo :: proc(p1, p2, p3 : int) { } And for constants, use, nodes :: 15 And I am 100% sure your odin code can be improved a lot.

    • @CodingWithTom-tn7nl
      @CodingWithTom-tn7nl 3 місяці тому

      From coding in c# and unity, I've had it hammered into to me to write semicolons all the time, so in languages that let me, I will always do it. I even write them in python. For some reason it helps me read code faster because if the line has a semicolon, I instantly know it's some kind of instruction and not an if statement, for loop, function etc. I sometimes get compile errors when trying to set things as constants in Odin: if level == NUMBER_OF_CITIES { final_distance := currentDistance + distanceMatrix[lastIndex][route_data.current_route[0]]; if (final_distance < minDistance) { minDistance = final_distance; for i := 0; i < NUMBER_OF_CITIES; i += 1 { bestRoute[i] = route_data.current_route[i]; } } return; } If I change final_distance to constant: final_distance :: currentDistance + distanceMatrix[lastIndex][route_data.current_route[0]]; I get a compile error: perf.odin(50:27) Error: 'currentDistance + distanceMatrix[lastIndex][route_data.current_route[0]]' is not a compile-time known constant You can't just use constants wherever you want in Odin, they need to be compile time known. Other people could probably improve every language in this list honestly.

    • @kcvinu
      @kcvinu 3 місяці тому

      @@CodingWithTom-tn7nl Let me take a look on your Odin code in the repo. I'll help you to improve that. BTW, I can offer a C3 version to compare if you want. Please let me know.

  • @nartoomeon9378
    @nartoomeon9378 3 місяці тому

    hmm... 6:35 there's something wrong here, because functional programming don't require immutable vars. Almost all functional lang-s are statically typed, but that doesn't mean they have immutable vars. The key feature is *pure functions* , higher order functions and possibly, monads. Pure function-is a function without side effects, in other words, same input-same output. Purity gives a more readable code, where user clearly see all possible outputs of a function. In the first example 6:58 we have a mutable variable, but it exist in separate name scope, so the function is pure! it doesnt change anything from outer scope.

  • @nangld
    @nangld 3 місяці тому

    Rewrite Rust in Zig!!!

  • @fungibungi5568
    @fungibungi5568 3 місяці тому

    clear and straightforward ❤

  • @samconnelly7630
    @samconnelly7630 3 місяці тому

    Here is my attempt at the functional programming example. I made sure to include the same bug where there was an extra comma after the number. This is in Haskell. EDIT: UA-cam doesn't render code snippets. module Main where printOutput :: [Int] -> IO () printOutput x = do putStrLn $ "The sum of: " ++ (foldl (++) "" $ map (\x -> (show x) ++ ", ") x) ++ "= " ++ (show $ sum x) putStrLn $ "The average: " ++ show (toInteger $ floor $ median $ map fromIntegral x) median :: Fractional a => [a] -> a median x = (sum x) / (fromIntegral $ length x) main :: IO () main = printOutput [1,9,2,4,2,5,8,1,4,6]

  • @nasccped
    @nasccped 3 місяці тому

    Awesome video dude! ❤

  • @paulzupan3732
    @paulzupan3732 3 місяці тому

    The object-oriented example is not very good. I can't believe that you coupled the notion of summing numbers to the number data itself. I would have created a NumberSumCalculator class which takes in a NumberArray along with an implementation of a NumberAdder interface. What if you wanted different strategies for adding numbers together? After all, there are many different ways to combine two numbers, and you want your code to be flexible, maintainable, and readable. You'd probably also want a NumberAverageCalculator interface, since there are multiple ways to find the average of a list of numbers. Not to mention that you coupled creating the output with the number data as well. I think the best solution would be a NumberDataOutputWriter class which takes in some sort of Writer interface (you might not want to print it to standard out, you could print to a file, write to a string, et cetera), as well as an object that implements both the NumberSumCalculator and NumberAverageCalculator interfaces so that you can get at that data. Overall, your solution is not scalable, readable, maintainable, flexible, or robust. 0/10. (edit) I’m sorry if this sounded too serious, I’m just kidding. I really enjoyed the video.

  • @stzi7691
    @stzi7691 3 місяці тому

    Normally I do not like to comment, but this is too much trash! I see that you probably just put the Rust part in ChatGPT or Copilot. An Unsafe println!()? Really? The rest inside an unsafe block? Honestly? Was this ChatGPT on booze? Sorry. Critizising a language just because you do not know how to properly code in it is like cursing beer bottles to be crap because they are not good for wearing them as glasses. But this gives me hope that LLMs will NEVER EVER replace programmers.

  • @Psi141
    @Psi141 3 місяці тому

    Underrated af

  • @LatticeCodes
    @LatticeCodes 3 місяці тому

    Your visuals are nice, good explanations!

  • @xzazen
    @xzazen 3 місяці тому

    fyi the function PrintNumbers(int i, int max) is not strictly a pure function (it does not give the same output for the same set of inputs) because you have a side-effect - Console.WriteLine() is IO bound and could cause an exception, in C# you probably would have to roll your own IO monad (essentially a container) and return the IO(result) or IO(error) to make it a pure function. The benefit is that you can remove stateful exception handling which is outside of the function and have "railway-oriented" exception handling.

    • @CodingWithTom-tn7nl
      @CodingWithTom-tn7nl 3 місяці тому

      The point is to use a functional style of programming in your code which has a benefit of making errors easier to find. I've never actually seen IO output fail and throw an exception, so I'm not sure how much benefit you are getting from doing this.

    • @etooamill9528
      @etooamill9528 3 місяці тому

      ​@@CodingWithTom-tn7nl if the program output is piped linux style in another program input and the receiving program crashes, does the output fail if you keep trying to write to it?

    • @lemna9138
      @lemna9138 3 місяці тому

      ​@CodingWithTom-tn7nl surely you've seen a network call or filesystem interaction fail before?

  • @MrlegendOr
    @MrlegendOr 3 місяці тому

    Save yourself 20 minutes of bulls****. This guy uses ChatGPT to compare performance. 🙃

  • @mohanedomer9081
    @mohanedomer9081 3 місяці тому

    man 12:00 is the best :)

  • @neoplumes
    @neoplumes 3 місяці тому

    It's very hard to trust the results of the tests when the code was written by chat gpt.

  • @DnBComplex
    @DnBComplex 3 місяці тому

    Amazing video.

  • @gJonii
    @gJonii 3 місяці тому

    Your fp example was oddly made in a way that seems harder to read than the default example everyone gives, where calculatetotal would take two parameters, list of numbers and total. You'd slice the first element off the list, add it to total, and do it like that. There's also really no point in using recursion imo, the reason it's popular is because Haskell etc have first-class support for it. Language you used here doesn't have that(was it C#? I didn't recognize it). However, that language likely has built-in reduce-method. Universality of these operations is a big selling point of FP, and by specifically avoiding showcasing it, you're seemingly purposefully trying to make FP seem worse than it is, by doing the example code in bad style, insisting on recursion when it's not really needed, and insisting on not using the universal patterns when universality of those patterns is a big selling point of the language. Also, the whole createoutput would've also been able to use the exact same reduce-operator, further showcasing this "simple universal tools serve you often quite well"

    • @CodingWithTom-tn7nl
      @CodingWithTom-tn7nl 3 місяці тому

      Yes it's C#. There are inbuilt functions for what I'm doing, like array.Sum() which, in c#, actually does exactly what I did with the for loop, just in a generic way. I'm trying to explain the concepts of these paradigms and if I just use inbuilt functions without actually showing how they work doesn't explain much. You can't always use a built in function for what you're doing and for those situations, in function programming you generally use recursion or lambda expressions. I wanted to use a simple example so most people can understand what's happening, but that also means there are usually inbuilt functions for that. The simplest way to write it: public static void Main() { int[] numbers = {1,9,2,4,2,5,8,1,4,6}; int total = numbers.Sum(); int average = total / numbers.Length; string output = $"The sum of: {string.Join(", ", numbers)} = {total} Average = {average}"; Console.WriteLine(output); } I gaurantee that in c# array.Sum and string.Join don't follow functional programming principles, so it kind of defeats the point anyway.

    • @gJonii
      @gJonii 3 місяці тому

      @@CodingWithTom-tn7nl Sum is specific-purpose tool. For functional approach using the generic tools like reduce, based on my quick googling, you would use `numbers.Aggregate((acc, x) => acc + x)`(C# seems to have decided to call its version of reduce "Aggregate"). It's true that you do have that already with Sum-method, which is less interesting, but map, reduce and filter are extremely basic and universal fp tools, which many FP languages do have their own specific syntax for. For C# and such, you often expect them to rather show up as some standard library functions, like here Aggregate. Using them isn't really cheating, it's demonstrating the style that fp encourages and expects, using combinators(like reduce), which get passed as a parameter a function that contains the logic. You likely could even implement reduce on your own in a couple of lines? Not sure if C# allows such generic higher order functions, but if it does, that shouldn't be more than one or two lines. I'm also not sure you want to use recursion. With Haskell it's a feature of the language, that recursion has excellent support, but languages that don't have that level of support, you probably want to implement the primitives like reduce with loops. That's what Haskell does too, decomposes recursion into loops. If your language doesn't do that, avoiding loops is imo a bit of a cargo cult thing rather than FP thing, at least if performance is a consideration.

    • @gJonii
      @gJonii 3 місяці тому

      To clarify, the point imo is, you want the functional primitives to be performant enough, implemented in whatever works best. These would include tools like map, reduce, filter, and such. After you have these basic tools however, you would not really need loops, since these tools handle whatever use cases you have for looping.

  • @DavidSosa-n8u
    @DavidSosa-n8u 3 місяці тому

    Love these vids, idk how I stumped upon your account but it’s very helpful

  • @ScibbieGames
    @ScibbieGames 3 місяці тому

    8:03, just not true, you can set it equal to undefined. Alternatively you can also do [1]u32{0} ** 20 9:00 I don't really understand why you aren't simply using slices.

  • @lucascogrossi2974
    @lucascogrossi2974 3 місяці тому

    Cool video cheers

  • @ThomazMartinez
    @ThomazMartinez 3 місяці тому

    So is stack then memory of CPU when they have L3 caches and so on? And heap is in RAM?

    • @CodingWithTom-tn7nl
      @CodingWithTom-tn7nl 3 місяці тому

      Both stack and heap memory are stored in RAM. They are just in stored in a different part so might not be close together. When data is accessed often, it can be put into the cache on the CPU. This is quicker than accessing data from RAM so has a performance benefit. Both stack and heap memory data can both be stored in cache memory but stack memory is usually accessed more often and more likely to be put into cache. Data is always stored in RAM and is copied into cache memory to increase performance.

    • @ThomazMartinez
      @ThomazMartinez 3 місяці тому

      @@CodingWithTom-tn7nl oh, but why then stack is faster? and good reference on web i can read about this?

    • @CodingWithTom-tn7nl
      @CodingWithTom-tn7nl 3 місяці тому

      @@ThomazMartinez Stack memory takes no time to create. Creating a stack variable: -Move the stack pointer down -Set the data Heap memory takes a lot more to create: Creating a heap variable: -Ask the operating system for more memory. You need to specify the size of the memory and the operating system needs to find a spare block of memory of that size. -Wait for the memory to be given to you. -Create a variable that references to the heap memory on the stack. -Set the data Generally creating the variable is the slow part. When it comes to accessing and changing the data it can depend and sometimes the difference is very small. As stack memory is closer together and accessed more often it is more likely to be stored in cache memory which increases performance.

    • @ThomazMartinez
      @ThomazMartinez 3 місяці тому

      @@CodingWithTom-tn7nl wow thank you so much for all this info, looking forward for more content like this,

  • @ThomazMartinez
    @ThomazMartinez 3 місяці тому

    I'm comming from JS, so Vector is new thing, what is diff between vector and array?

    • @CodingWithTom-tn7nl
      @CodingWithTom-tn7nl 3 місяці тому

      in c++ a vector is an array that can change in size. So you can add and remove elements. For standard arrays in c/c++ you can't change the size of them. In Javascript all arrays can be resized which means they are heap allocated. It works very differently in compiled vs interpreted languages.

  • @ThomazMartinez
    @ThomazMartinez 3 місяці тому

    when does something go into stack or heap? maybe video?

    • @CodingWithTom-tn7nl
      @CodingWithTom-tn7nl 3 місяці тому

      This depends on the language. c/c++: variables will be on the stack unless you specify. Javascript and other garbage collected langauges: basic types: Number, Boolean, BigInt - stored on the stack arrays and objects - stored on the heap but have references on the stack. In some languages classes are stored on the heap and structs on the stack but it always depends on the language. This is all done for you in garbage collected languages.

  • @ThomazMartinez
    @ThomazMartinez 3 місяці тому

    so delete only removes from heap but not stack and for stack it does not matter?

    • @CodingWithTom-tn7nl
      @CodingWithTom-tn7nl 3 місяці тому

      Delete will free the heap memory that you specify. Also the reference to that heap memory will be uninitialized on the stack: int* number = new int; //creates heap memory *number = 1; //sets the value std::cout << "Number address: " << number << ' '; //Print the address std::cout << "Value at address: " << *number << ' '; //Print the value delete number; //frees the heap memory std::cout << "Number address after delete: " << number << ' '; Output: Number address: 00000287DFDC7430 Value at address: 1 Number address after free: 0000000000008123 Stack variables are freed when they can't be use anymore. It's automatic. All the stack memory is freed when the program ends.

  • @ThomazMartinez
    @ThomazMartinez 3 місяці тому

    Heap and stack both stored in RAM yes?

    • @CodingWithTom-tn7nl
      @CodingWithTom-tn7nl 3 місяці тому

      Yes, they are essentially the same thing just stored in a different part of ram, but the mechanics are different. Stack memory is automatically given to you and freed automatically when the program ends. Heap memory needs to be asked for and won't be freed automatically.

  • @ThomazMartinez
    @ThomazMartinez 3 місяці тому

    Can you try C3 also pls?

  • @JonatanMachado
    @JonatanMachado 3 місяці тому

    Great explanation ❤