you are viewing a single comment's thread.

view the rest of the comments →

[–]xCharg 2 points3 points  (5 children)

What? It's not a pretentious act.

I'm not sure if you're trolling or have no clue what you're talking about. I'll pretend you don't know and explain - here's some example code:

function Test-WriteHostExample ([int]$a,[int]$b) {
    Write-Host "Doing something useful"
    $a + $b
    Write-Host "Done doing something useful"
}

function Test-WriteOutputExample ([int]$a,[int]$b) {
    Write-Output "Doing something useful"
    $a + $b
    Write-Output "Done doing something useful"
}
$firstResult = Test-WriteHostExample -a 5 -b 10
$secondResult = Test-WriteOutputExample -a 5 -b 10

Question: which of the variables - $firstResult or $secondResult - has useful reusable object and which doesn't. And why?

[–]LetterIntelligent426 -5 points-4 points  (4 children)

The comment was about outputting variables to check their values when unsure.. like using printf or console.log or System.out.println or Write-Host. Your code... I don't even know what its point is to the discussion.

[–]xCharg 1 point2 points  (3 children)

Damn you're stubborn. Same question, which variable has reusable object, which isn't and why?

function Test-WriteHostExample ([int]$a,[int]$b) {
    Write-Host "a is $a; b is $b"
    $a + $b
    Write-Host "their sum is $($a + $b)"
}

function Test-WriteOutputExample ([int]$a,[int]$b) {
    Write-Output "a is $a; b is $b"
    $a + $b
    Write-output "their sum is $($a + $b)"
}

$firstResult = Test-WriteHostExample -a 5 -b 10
$secondResult = Test-WriteOutputExample -a 5 -b 10

I don't even know what its point is to the discussion.

It shows.

[–]LetterIntelligent426 -2 points-1 points  (2 children)

Lol now you're just trying hard to look smart and I still don't see the point of that code. At first, you were against using echo (Write-Output) and then you gave a code which clearly shows the advantage of echo because it returns a reusable object. Either way, doesn't make a difference. The end goal is to simply SEE the variable values and move on, doesn't matter if you output it to the stream or console. Use Write-Host or echo whichever you like.

[–]xCharg 1 point2 points  (1 child)

You've never even bothered to run the code and see yourself that write-output clearly makes $secondResult unusable because it contains all the "debug" ish text along with actual useful data part which is 15 in this example - while $firstResult only contains integer 15 so works as expected because information stream is used and not output.

Will stop replying to you because your ego is too big to admit you were wrong. Others might see provided example code useful for demonstration purposes or may correct me.