teleren/devto huggingface dataset:
20 Useful lines of code that can be used for C# scripting in Unity | pt:2
Tags: csharp, unity3d, beginners, tutorial
Published: 2022-12-11 10:25:21

{% embed https://dev.to/rizmyabdulla/20-useful-lines-of-code-that-can-be-used-for-c-scripting-in-unity-pt1-kmh %}

1.To instantiate an object at a specific position and rotation:

```
GameObject object = Instantiate(prefab, position, rotation);
```

2.To access the components of a GameObject:

```
Rigidbody rb = gameObject.GetComponent<Rigidbody>();
```

3.To move a Rigidbody in the direction it is facing:

```
rb.velocity = transform.forward * speed;
```

4.To rotate a Rigidbody towards a target position:

```
Vector3 direction = target.position - transform.position;
rb.rotation = Quaternion.LookRotation(direction);
```

5.To apply a force to a Rigidbody in a specific direction:

```
rb.AddForce(direction * force);
```

6.To set the position of a Transform:

```
transform.position = new Vector3(x, y, z);
```

7.To set the rotation of a Transform:

```
transform.rotation = Quaternion.Euler(x, y, z);
```

8.To set the scale of a Transform:

```
transform.localScale = new Vector3(x, y, z);
```

9.To find an object in the scene by name:

```
GameObject object = GameObject.Find("ObjectName");
```

10.To find an object in the scene by type:

```
GameObject object = GameObject.FindObjectOfType<Rigidbody>();
```

11.To destroy a GameObject:

```
Destroy(gameObject);
```

12.To destroy a GameObject after a delay:

```
Destroy(gameObject, delay);
```

13.To set the value of a public variable in another script:

```
otherScript.variableName = value;
```

14.To invoke a method in another script:

```
otherScript.MethodName();
```

15.To check if a key or button is pressed:

```
if (Input.GetKeyDown(KeyCode.Space))
{
    // Perform action
}
```

16.To get the current frame rate

```
float frameRate = 1 / Time.deltaTime;
```
17.To load a scene by name:

```
SceneManager.LoadScene("SceneName");
```

18.To add a new entry to a Dictionary:

```
Dictionary<string, int> dict = new Dictionary<string, int>();
dict.Add("Key", value);
```

19.To check if an object is in a List:

```
List<GameObject> list = new List<GameObject>();
if (list.Contains(object))
{
    // Object is in the list
}
```

20.To sort a List by a property of the objects in the list:

```
list.Sort((a, b) => a.name.CompareTo(b.name));
```

Thanks For reading...
Which programming language is best for beginners to learn? (generated by AI!)
Tags: ai, programming, beginners, chatgpt
Published: 2022-12-11 10:13:31

As a beginner in the world of programming, it can be overwhelming to choose which programming language to start with. With so many options available, it can be difficult to know which one is the best fit for your goals and needs.

First, it's important to understand that a programming language is a set of instructions that a computer can understand and execute. These instructions can be used to create a wide variety of software applications, from simple mobile games to complex financial systems. Learning to program can open up a world of possibilities and opportunities, and is an increasingly valuable skill in today's technology-driven world.

When it comes to choosing a programming language to learn as a beginner, there are a few key factors to consider. First, it's important to choose a language that is widely used and has a strong community of developers. This will make it easier to find resources and support as you learn. Second, it's helpful to choose a language that is beginner-friendly, with a gentle learning curve and a clear and concise syntax. Finally, it's a good idea to choose a language that is versatile and can be used to build a wide variety of applications.

With these factors in mind, here are some of the top programming languages for beginners to learn:

1. Python: Python is widely considered to be one of the best programming languages for beginners. It has a simple and intuitive syntax, and is used in a variety of fields, from web development to scientific computing. Python is also well-supported, with a large community of developers and a wealth of online resources.

2. Java: Java is another popular programming language that is well-suited for beginners. It is widely used in the development of mobile and web applications, and has a similar syntax to other popular languages like C++ and C#. Java is also known for its stability and reliability, making it a good choice for building robust applications.

3. JavaScript: JavaScript is a must-know language for aspiring web developers. It is the primary language used for building interactive, dynamic websites, and is supported by all modern web browsers. JavaScript is also increasingly used in the development of mobile and desktop applications, thanks to frameworks like React Native and Electron.

In conclusion, there are many excellent programming languages for beginners to learn. The best language for you will depend on your goals and interests, but popular options like Python, Java, and JavaScript are all good choices to consider. No matter which language you choose, the important thing is to start learning and practicing, and to seek out resources and support from the community as you go. Good luck on your programming journey!
How to check if a list is empty in Python?
Tags: python, beginners, programming
Published: 2022-12-11 10:00:00

Considering that Python list is one of the most used data structures, it's a given that at some point the need to check if a list is empty will arise. 

There are several ways to do this, however, the most straightforward is to use a method called [Truth Value Testing](https://docs.python.org/3/library/stdtypes.html#truth-value-testing).

In Python, any object can be tested for truth value, including lists. In this context, **lists are considered truthy if they are non-empty**, meaning that at least one argument was passed to the list. So, if you want to check if a list is empty, you can simply use the `not` operator.

```py
empty_list = []
non_empty_list = [1, 2, 3]

not empty_list # True
not non_empty_list # False
```

The `not` operator is a logical operator that returns the opposite of the value it is applied to. In the above code example we can see that it returns `True` if the list is empty and `False` if the list is not empty.

While the `not` operator is the most straightforward and pythonic way to check if a list is empty, there are other ways to do this. For example, you can use the `len()` function. This function returns the length of the list, which is 0 if the list is empty.

```py
empty_list = []
non_empty_list = [1, 2, 3]

len(empty_list) == 0 # True
len(non_empty_list) == 0 # False
```

Another way is to compare the list to an empty list using the `==` operator.

```py
empty_list = []
non_empty_list = [1, 2, 3]

empty_list == [] # True
non_empty_list == [] # False
```
📦 loop and block scope. difference between var and const with image
Tags: javascript
Published: 2022-12-11 09:02:26

At first basic for loop
```javascript
for(let i = 0; i < 5; i++) {
  const num = i * 2
  console.log(num)
}

// 0 2 4 6 8
```
`const` can't reassign neither redeclare, but there is no any error.
So block scope might change each time

{% link https://dev.to/kaziusan/var-let-const-31il %}

▼ then add `setTimeout` in this loop

```javascript
for(let i = 0; i < 5; i++) {
  const num = i * 2
  setTimeout(function() {
    console.log(num)
  }, 1000)
}

// (after 1s)
// 0, 2, 4, 6, 8
```

If I use `var` ?

```javascript
for(let i = 0; i < 5; i++) {
  var num = i * 2 // ⭐ var !!!!
  setTimeout(function() {
    console.log(num)
  }, 1000)
}

// (after 1s)
// ⭐⭐ 8 8 8 8 8 
```
Why result is "8 8 8 8 8" ??
Because declare `var` in block scope is the same as declare `var` as global scope. `var` doesn't have block scope


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qjpzxijnvwrhheko1qtd.png)

```javascript
//⭐ declare var in block scope is the same as like this
var num; 
for(let i = 0; i < 5; i++) {
  num = i * 2
  setTimeout(function() {
    console.log(num)
  }, 1000)
}

// (after 1s)
// 8 8 8 8 8 
```
- **var**

`num` changes(overwrite) 8 after 1ms when setTimeout() executes

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xwqxm8g8f8amac8dny1a.png)


- **const**

`num` declares each time loop, so even though the name `num` is the same, save in different memory places 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xfmwpy9w4wbeh00x5k68.png)

---
ref. [from this course](https://www.udemy.com/course/javascript-essence/)

(note for myself)
var: setTimeout()が実行される1秒後には、`num`はもう8になっとる。var numはglobalなので、上書きされマッセ

const: loopごとに宣言されてます。numって名前一緒じゃけど、違うメモリスペースにありマッスル
Kotlin Code Smell 8 - Too Many Arguments
Tags: kotlin, codesmells, cleancode, programming
Published: 2022-12-11 09:24:17

---
title: Kotlin Code Smell 8 - Too Many Arguments
published: true
date: 2022-12-11 09:00:45 UTC
tags: kotlin,codesmells,cleancode,programming
canonical_url: https://yonatankarp.com/kotlin-code-smell-8-too-many-arguments
---

> **TL;DR:** Avoid passing more than three arguments to your functions.

## Problems

* Low maintainability.
    
* Low reusability.
    
* Coupling.
    
* Readability.
    

## Solutions

* Identify cohesive relationships among arguments.
    
* Create a "context" or related group.
    
* Consider using the [Method Object](https://wiki.c2.com/?MethodObject) Pattern.
    
* Avoid using "basic" types such as strings, arrays, and integers, and instead think in terms of objects.
    

## Exceptions

* Operations in the real world that do not require cohesive collaborators.
    

## Sample Code

### Wrong

```kotlin
class Printer {
    fun print(
        documentToPrint: String,
        paperSize: String,
        orientation: String,
        grayScales: Boolean,
        pageFrom: Int,
        pageTo: Int,
        copies: Int,
        marginLeft: Float,
        marginRight: Float,
        marginTop: Float,
        marginBottom: Float
    ): Unit = TODO()
}
```

### Right

```kotlin
class PaperSize {
    //...
}

class Document {
    //...
}

class PrintMargins {
    //...
}

class PrintRange {
    //...
}

class ColorConfiguration {
    //...
}

class PrintOrientation {
    //...
}

class PrintSetup(
    paperSize: PaperSize,
    orientation: PrintOrientation,
    color: ColorConfiguration,
    range: PrintRange,
    copiesCount: Int,
    margins: PrintMargins
)

class Printer {
    fun print(
        documentToPrint: Document,
        setup: PrintSetup
    ): Unit = TODO()
}
```

## Conclusion

To improve code quality, identify and group related arguments. Aim for real-world mappings and cohesive objects.

If a function requires too many arguments, some of them might be better suited for class construction. This is also a design issue.

---

Stay updated with my latest thoughts and ideas by registering for my [**newsletter**](https://yonatankarp.com/newsletter). Connect with me on [**LinkedIn**](https://www.linkedin.com/in/yonatankarp/) or [**Twitter**](https://twitter.com/yonatan_karp). Let's stay connected and keep the conversation going!

---

## More Info

* [Refactoring Guru](https://refactoring.guru/es/smells/message-chains)
    

## Credits

* [Code Smell 10 - Too Many Arguments](https://maximilianocontieri.com/code-smell-10-too-many-arguments) by @[Maxi Contieri⭐⭐⭐](@mcsee)
Python Programming Bootcamp #10 - ASCII and Unicode strings
Tags: python, programming, tutorial, beginners
Published: 2022-12-11 08:54:00

---
title: Python Programming Bootcamp #10 - ASCII and Unicode strings
published: true
description: 
tags: python, programming, tutorial, beginners
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
published_at: 2022-12-11 08:54 +0000
canonical_url: https://code-maven.com/programming-bootcamp-for-scientists-10
series: bootcamp
---

{% youtube HxJ3JHCd26Q %}

00:00 Solution to compare numbers
03:57 Solution to compare strings
08:00 Nóra explains her solutions using functions
13:10 Refactoring
19:27 Start the chapter [Strings](https://code-maven.com/slides/python/strings)
19:38 Single quoted and double quoted strings
21:19 Triple quoted strings ([multiline strings](https://code-maven.com/slides/python/triple-quoted-strings))
21:47 What would you do if you wanted to print a quote character? Escaping quotes. \n, \t
26:43 Is it OK to TABs instead of spaces for indenting Python code? Indentation examples. Notepad++ show whitespaces.
35:13 [String length (len)](https://code-maven.com/slides/python/string-length)
35:36 String repetition and concatenation
37:18 A character in a string.
38:00 Is a string a list? No, it's a Sequence.
39:00 [String slice](https://code-maven.com/slides/python/string-slice) (instead of substr)
41:58 Change a string - Strings are immutable
44:20 String copy
47:05 String functions and methods (len, upper, lower)
49:30 All the built-in functions of Python
50:29 [index](https://code-maven.com/slides/python/index-in-string) and rindex in string
58:24 When the string is not found we get an exception. How can we prevent it?
59:16 find in string
1:00:39 in string
1:03:51 [Encodings: ASCII, Windows-1255, Unicode](https://code-maven.com/slides/python/ascii-unicode)
1:09:32 raw strings
1:14:42 ord
1:16:16 chr - number to character
1:16:45 Exercises
Will ChatGPT replace programmers?
Published: 2022-12-11 08:42:22

**The recent release of GPT-3 has sparked speculation about whether language models could one day take over for human programmers, but is this really a realistic possibility?**

The recent release of OpenAI's GPT-3 (short for "Generative Pretrained Transformer 3") has sparked a lot of excitement and speculation in the tech world. Some have even suggested that GPT-3, and language models like it, could one day replace programmers altogether. But is this really a realistic possibility? In this blog post, we'll explore the capabilities of GPT-3 and other language models, and consider whether they truly have the potential to replace human programmers.

First, let's talk about what GPT-3 is and what it can do. GPT-3 is a large, powerful language model that has been trained on a vast amount of text data from the internet. This allows it to generate text that is often indistinguishable from text written by a human. GPT-3 has been shown to be able to perform a wide range of language-based tasks, including language translation, summarization, question answering, and even generating code.

So, does this mean that GPT-3 and other language models could one day replace programmers? The short answer is no. While GPT-3 is impressive in its ability to generate text, it is not capable of the kind of abstract thinking and problem-solving that is required for programming. Programming requires a deep understanding of a problem and the ability to come up with creative solutions to that problem. GPT-3 and other language models are good at generating text based on existing examples, but they lack the ability to truly understand a problem and come up with novel solutions.

Furthermore, even if GPT-3 and other language models were able to generate code, it would still require human oversight to ensure that the code is correct and efficient. A human programmer would need to review and debug the code generated by the language model, and this would still require a significant amount of time and effort. In other words, while language models like GPT-3 may be able to assist with certain aspects of programming, they are not capable of replacing human programmers altogether.

In conclusion, while GPT-3 and other language models are impressive in their ability to generate text, they are not capable of replacing human programmers. Programming requires a level of abstract thinking and problem-solving that these models do not possess. Even if they were able to generate code, it would still require human oversight and effort to ensure its correctness and efficiency. In short, human programmers are here to stay.
Implement factorial using MIPS
Tags: mips, assembly, beginners
Published: 2022-12-11 08:33:44

This was a computer organization class assignment. I implemented a factorial using the following algorithm: 
{% katex %}
F(n) = \begin{cases}  1, & n = 0 \\\\ F(n - 1) * n, & n \in \mathbb{N} \end{cases}
{% endkatex %}

In MIPS, I use `$a0` as the parameter *n* of *F(n)*. For example, letting `$a0` equal to `5` and jumping to the `fact` label means *F(5)*, and at the end of the recursion, the result will be stored in `$v0`.

```py
main:
    addi $a0, $zero, 5        # let the parameter n be 5
    jal fact                  # jump to fact label, i.e. calling F(5)
    j exit

fact:
    addi $sp, $sp, -8         # allocate 8 bytes to this stack
    sw $ra, 0($sp)            # save the address of the instruction that calls fact label (instruction address)
    sw $a0, 4($sp)            # save the value of n

    slti $t0, $a0, 1          # $t0 is used for conditions. If n < 1 then $t0 = 1, else $t0 = 0
    beq $t0, $zero, L1        # if $t0 == 0 then jump to branch L1
    addi $v0, $zero, 1        # let $v0 be 1
    addi $sp, $sp, 8          # let $sp point to upper stack
    jr $ra                    # jump to the next instruction of the instruction calling fact

L1:
    addi $a0, $a0, -1         # n = n - 1
    jal fact                  # jump to fact label again, like as calling F(n - 1)
    lw $a0, 4($sp)            # recover the value of n
    mul $v0, $a0, $v0         # $v0 *= $a0, like as F(n) = n * F(n - 1)
    lw $ra, 0($sp)            # recover instruction address
    addi, $sp, $sp, 8         # let $sp point to the upper stack
    jr $ra                    # jump to the next instruction of the instruction calling L1

exit:
```

The execution result of the MARS simulator looks like this:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1willvg4t43u7hisghz3.jpg)

You can see that the value of `$v0` is `0x78`, 120 in decimal, which is the result of *F(5)*.
Challenge: Your ugliest code
Tags: webdev, php, javascript, programming
Published: 2022-12-11 08:29:33

I work with web development daily. It is one of my joys, but can also be a source of great frustration. A recent frustration tracking down some logic in a third-party library led me to a discovery. It was a method declaring void as its return-value. Reasonably, one would assume that it wouldn't return any value as such. Maybe it would mutate a value, but that was all. Was this the case though? **NO**.

The method would parse some input value and then it would throw its calculated value out into the abyss, hoping there would be a catch-statement somewhere that would handle it.

I don't know if this is a common pattern and if it has any name. I suggested to one of my colleagues that we name it "the anti prop-drill": it isn't a prop, it isn't passed through step-by-step, and it is thrown in an opposite direction. I'm open to hear your suggestions, or maybe make me understand if this is a reasonable pattern.

Anyway, this inspired me to write **the ugliest** (and funniest) code I have ever written. This is *exceptional coding*!

```php
<?php

function sum(array $array)
{
    $sum = 0.0;

    try {
        $i = 0;
        while(true) {
            $value = $array[$i] ?? throw new \Exception('' . $sum);
            $sum += $value;
            $i++;
        }
    } catch (Exception $e) {
        return (float)$e->getMessage();
    }
}

$values = [3, 2.5, 0.5];
echo 'Sum of ' . implode(' + ', $values) . ' = ' . sum($values) . PHP_EOL;
```
Output: `Sum of 3 + 2.5 + 0.5 = 6`
 
>PHP doesn't automatically throw an "Array Index out of Bound" Exception. Instead it returns null. So `$array[$i] ?? throw new \Exception` checks if the value is null and if so it will throw a new exception with our `$sum` wrapped in its message.

What is the ugliest code you have achieved?
Introduction: I'm Sangam
Tags: introductions
Published: 2022-12-11 07:59:59

Hello Dev.to !!

I mostly code in python. I mostly work on Machine learning(scikit-learn,torch,tensorflow ...) and backend(FastAPI,Mongodb,postgres ...).

I've been trying to improve my skills in backend, Data engineering and MLOps. I'm also a contributor to OSS.

You can find me on :
GitHub:  [@SangamSwadiK](https://github.com/SangamSwadiK)
LinkedIn: [@SangamSwadiK](https://www.linkedin.com/in/sangam-swadi-k/)

Glad to be part of Dev.to community.
(cover image: Rice fields ready for harvest)
What are Ethereum Testnets?
Tags: web3, datascience, ethereum, programming
Published: 2022-12-11 07:31:36


These are networks used by protocol developers or smart contract developers to test both protocol upgrades as well as potential smart contracts in a production-like environment before deployment to Mainnet. Think of this as an analog to production versus staging servers.

ETH on testnets has no real value; therefore, there are no markets for testnet ETH. Since you need ETH to actually interact with Ethereum, most people get testnet ETH from faucets. Most faucets are webapps where you can input an address which you request ETH to be sent to.

Which Testnet should I use?
The two public proof-of-stake testnets (which client developers are maintaining post-merge) are Goerli and Sepolia. The Goerli network was merged with the Prater Beacon Chain testnet. The Sepolia network was created to test the transition to proof-of-stake.


## Sepolia
 
It is the recommended default testnet for application development. The Sepolia network uses a permissioned validator set. It's fairly new, meaning its state and history are both quite small. This means the network is quick to sync to and that running a node on it requires less storage. This is useful for users who want to quickly spin up a node and interact with the network directly.

It's features:

- Closed validator set, controlled by client & testing teams.
- New testnet, less applications deployed than other testnets.
- Fast to sync and running a node requires minimal disk space.

## Goerli 

It is the recommended default testnet for testing of validating and staking. The Goerli network is open for users wanting to run a testnet validator. Stakers wanting to test protocol upgrades before they are deployed to mainnet should therefore use Goerli.

It's features: 

- Open validator set, stakers can test network upgrades.
- Large state, useful for testing complex smart contract interactions.
- Longer to sync and requires more storage to run a node.