From Powershell to .NET

Status
Not open for further replies.

Z3us

Seniorius Lurkius
14
I wasn't sure whether this post should be located under the Windows section since it refers to Powershell, apologies if it should.

Anyway, I'm looking to learn about programming over the next few years to understand more about how programs are created and function behind the GUI end users see.

I'm currently a sys admin and know my way around powershell, I like to think!

Given that I know my way and around Powershell and understand Powershell is simply built on .NET, I suppose the natural progression is to move into .NET.

However I understand that .NET is simply a framework for the likes of C# and ruby etc.

Any suggestion on where my focus should be over the coming years?
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
If you want to transition your power shell into programming proper, and wish to stick with MS stack then C# is definitely the place to go.

As to how to go about learning to program that question comes up a lot here, look at past topics in here but you can distill much of it into:
* it takes time and some direction. A book online tutorial is good.
* pick something you want to implement, do it
* don't bite off more than you can chew early on. Build up in stages.

Remember that some idiomatic shell scripting would *not* make for good code, and vice versa. Do not try to write posh scripts in c# as straight translations.

Keep asking questions here (but have a search through past threads first) we like having more decent programmers in the world. :)
 

Richard Berg

Ars Legatus Legionis
43,037
Subscriptor
C# is a great language, but it requires a fair bit of OO ceremony that won't make sense to a beginner. Plus, it doesn't have a REPL.

I'd stick with Powershell for now. So long as you've got a reasonable editor with syntax highlighting and reflection/autocomplete, it should be a pretty friendly intro to the broader .NET framework, and to structured programming generally.

Regardless what language you choose, the only way to learn is thru doing. Scratch an itch, search the web for basic pieces you can paste together, and post for feedback. Or follow a pre-canned tutorial/textbook. You'll need to be comfortable with both approaches eventually.

NB: if you see this as more than a hobby, my advice changes somewhat. Pick up a solid e-text on the fundamentals (I like How to Think like Computer Scientist), read thoughtfully, and hew to the examples closely until you truly understand them.
 

Cookie.Monster

Ars Scholae Palatinae
666
Good recommendations so far! C# seems like it would be a natural fit, just keep in mind you will be going from an incredibly loose, 'let me do a bunch of work under the covers so it will behave as an admin expects' language to a language that is a bit more strict. Definitely pick up a book on the fundamentals. For a quick start, I found C# for Sharp Kids quite handy.

Worst case scenario you learn some good programming and coding fundamentals and decide not to pursue it.

Personally, scripting and small code snippets are where I draw the line. I don't have the patience or mind for real programming. That being said, PowerShell lets me dive into .NET and compiling C# at runtime in PowerShell when needed, much simpler than just building a console application. A quick example - Invoke-Sqlcmd2 uses various classes in the .NET System.Data namespace, and has a small C# snippet that replaces [DBNull]::Value with an actual null (Note: I didn't write this, just an example!)
 

w1tn3ss

Seniorius Lurkius
8
Great venture your about to proceed into, .NET is a good place to start to get the fundamentals of programming, try working on projects like bank systems, they are generally in the books when you get round to getting some, O'Reilly books are good in my experience.
Generally you will want to learn about the basics in programming, input, process, output and then move into more of how to optimise your code by implementing object orientated design and various patterns to suit the need of the project.

It's great once you get going, best of luck!! :eng101:
 

ShuggyCoUk

Ars Legatus Legionis
10,387
Subscriptor++
[url=http:/civis/viewtopic.php?p=26642945#p26642945:1phn7qmi said:
Metasyntactic[/url]":1phn7qmi]
[url=http:/civis/viewtopic.php?p=26639395#p26639395:1phn7qmi said:
Richard Berg[/url]":1phn7qmi]C# is a great language, but it requires a fair bit of OO ceremony that won't make sense to a beginner. Plus, it doesn't have a REPL.
It does now. :)

Took your time ;)
 

dragonlord

Ars Scholae Palatinae
1,123
If you want a simpler introduction to the world of OO and .Net then I recommend using VB.net. The language is as feature complete as C# as it's effectively compiled into the same code, however being more verbose it's easier to read for a beginner.

The downside (could be seen as an upside) is that most of the examples on the net are in c# so you'll have to translate them to VB. The other downside is that a lot of programmers won't see you as being of the same caliber (sp??) as them due to the history of VB in macro's and VB6, which due to their "loose" typing and very forgiving error handling (due to their interpreted nature) allowed for very slapdash code the only worked because errors didn't matter.
 

wallinbl

Ars Legatus Legionis
14,335
Subscriptor
[url=http:/civis/viewtopic.php?p=26644481#p26644481:j59ojvl9 said:
dragonlord[/url]":j59ojvl9]If you want a simpler introduction to the world of OO and .Net then I recommend using VB.net. The language is as feature complete as C# as it's effectively compiled into the same code, however being more verbose it's easier to read for a beginner.

The downside (could be seen as an upside) is that most of the examples on the net are in c# so you'll have to translate them to VB. The other downside is that a lot of programmers won't see you as being of the same caliber (sp??) as them due to the history of VB in macro's and VB6, which due to their "loose" typing and very forgiving error handling (due to their interpreted nature) allowed for very slapdash code the only worked because errors didn't matter.
If he's coming from Powershell, the C# syntax shouldn't be an issue. Stick with C# (and this is from someone that started back in the VB6/classic ASP days).
 

dragonlord

Ars Scholae Palatinae
1,123
I recommend it as being much easier to read and learn the syntax of than c#
it also has less problems with hard to find block closures and line terminator bugs (i.e. there are no line terminators and every closure has to be on a separate line.). Which means that while you're learning to program you're not having to worry about the program not running because you forgot a ';' or it's behaving strangely for the same reason.

it's also much much easier to identify which block of code you're working in due to the fact that each "block" in vb is clearly marked in english like language (e.g. function - end function, for - next, do - while/while do, etc.) while in c# all blocks are surrounded by {}.

it's much harder to write incomprehensible 1 line functions that need to be teased apart to understand due to the lack of line terminators.

On top of that, to my knowledge, there's nothing that you can write in c#.net that you can't write in vb.net
 

jbode

Ars Legatus Legionis
11,752
Subscriptor
[url=http:/civis/viewtopic.php?p=26658745#p26658745:19citz81 said:
NavyGothic[/url]":19citz81]
[url=http:/civis/viewtopic.php?p=26645047#p26645047:19citz81 said:
jxl[/url]":19citz81]Why bother with a half-measure like Visual Basic when you can big dog it with COBOL?
There are some sick and sadistic people out there. :(

Hey, if I have millions of lines of (working!) legacy code, I'm not going to be anxious to rewrite the whole thing from scratch. If this gives people a way to migrate their apps from big iron to a cloud-based solution without having to re-implement from the keel up, more power to them.
 

Paul Hill

Ars Legatus Legionis
19,890
it's much harder to write incomprehensible 1 line functions that need to be teased apart to understand due to the lack of line terminators.

I worked with VB6 and VB.NET for years - trust me, it's incredibly easy to write WHARRGARBL in VB :)
Plus you might have to work with people that stick meaningless lowercase letters on the front of their variable names and think they've done a good job naming a Boolean variable bFlag.

Yeah C#'s great, type inference is great, and for those people who think the compiler catching errors is some kind of bad thing there's always dynamic variables!
 

Bagheera

Ars Tribunus Angusticlavius
8,773
Subscriptor
That's how I got into programming. I realized all the great sysadmin things I could with Powershell. Then I realized all the great non-sysadmin things I could do with Powershell. Then I decided to learn object-oriented programming. My introduction to OOP was via Java rather than C#, but that's because my university coursework was all in Java.

I attended Western Governor's University and found it really helpful. Some of the courses map to certifications, so your sysadmin certs might get you free credits.

Beyond that, sign up on Stack Overflow immediately. They have a massive archive of programming questions with very clear answers. If you post a question, you'll get a reliable answer within a day. Here on Ars, listen to everything Richard Berg says. He's answered a zillion of my Powershell questions over the years.
 

Paul Hill

Ars Legatus Legionis
19,890
[url=http:/civis/viewtopic.php?p=26679971#p26679971:33eee8y7 said:
wallinbl[/url]":33eee8y7]
[url=http:/civis/viewtopic.php?p=26661393#p26661393:33eee8y7 said:
dragonlord[/url]":33eee8y7]On top of that, to my knowledge, there's nothing that you can write in c#.net that you can't write in vb.net
Legible lambda expressions :p

The two things I miss from VB.NET in C#:

1) Filtered exception catching (coming in C# 6 :) )
2) Being able to write templated XML directly in source.
 
[url=http:/civis/viewtopic.php?p=26667811#p26667811:1vqe8owp said:
Paul Hill[/url]":1vqe8owp]
it's much harder to write incomprehensible 1 line functions that need to be teased apart to understand due to the lack of line terminators.

I worked with VB6 and VB.NET for years - trust me, it's incredibly easy to write WHARRGARBL in VB :)
Plus you might have to work with people that stick meaningless lowercase letters on the front of their variable names and think they've done a good job naming a Boolean variable bFlag.

Yeah C#'s great, type inference is great, and for those people who think the compiler catching errors is some kind of bad thing there's always dynamic variables!

Paul, your comment suggests that you really haven't done much in VB.Net. I'm always suspicious of comments that lump VB6 (and VBA) together with VB.Net under 'VB'. The two languages are very different (hence all the howls of protest from VB devs when VB.Net was first released). I don't know exactly what you mean by "WHARRGARBL" but I guess you mean what used to be referred to as Spaghetti code. I see no reason why this would be easier to do in VB.Net (With Option Strict On as it should be) than C#, the editor is just as picky about type conversions, unused variables etc etc as it is in C#, and VB.Net was built as an OO language from the ground up, just like C# in fact, and both produce the same MSIL.

In all honesty, the downer that many devs have on VB.net is just prejudice. Often they haven't used it, and there's a bit of the herd mentality going on - well everybody says "VB" is crap so VB.Net must be as well!!

As regards "bflag", a proper VB6/VBA programmer would of course name that variable booFlag :D
 

Paul Hill

Ars Legatus Legionis
19,890
[url=http:/civis/viewtopic.php?p=26776015#p26776015:2irjzvpv said:
serendipity24[/url]":2irjzvpv]Paul, your comment suggests that you really haven't done much in VB.Net. I'm always suspicious of comments that lump VB6 (and VBA) together with VB.Net under 'VB'.

Well, tough. I've used VB since 1.0 and VB.NET and I know that VB.NET is totally different and oopey and everything, but in my experience what it pretty much used exclusively for is taking whatever the collective noun of VB coders is (I'm gonna suggest somewhat uncharitably a "Cargo") and throwing them at "rebuilding our app in .NET" without bothering to do retraining, with hilarious consequences.

I see no reason why this would be easier to do in VB.Net (With Option Strict On as it should be) than C#, the editor is just as picky about type conversions, unused variables etc etc as it is in C#

Sure but you've still got that died-in-the-wool VB coder throwing ON ERROR GOTO HELL into the codebase, or half of the coding team deciding arrays start at 1, or the senior guy thinking type checking is somehow accusing him of not being able to code properly and removing said OPTION STRICT ON in every checkin.

In all honesty, the downer that many devs have on VB.net is just prejudice. Often they haven't used it

I've used it, in some ways it's nice, there's people kicking ass with it no doubt but in my experience the developer mindset is just ugh.
 

Cookie.Monster

Ars Scholae Palatinae
666
On a side note, was at the PowerShell Summit last week, Jeffrey Snover hinted at some interesting things to come. He reviewed the Monad Manifesto origins, where we are (including self-assessments), and where he sees things headed.

A few tidbits:
  • Predicts PowerShell will go open source. Not a commitment, but coming from Jeffrey, it's a good possibility...
  • For shortcomings, specifically mentioned the developer community; last slide indicated they will be shifting focus to developers and enabling 'devops'
  • Hinted at a developer mode of some sort
  • Better developer tooling (TechEd will shed some light on this)
 

Paul Hill

Ars Legatus Legionis
19,890
[url=http:/civis/viewtopic.php?p=26799219#p26799219:svabyxqx said:
jedigo[/url]":svabyxqx]
[url=http:/civis/viewtopic.php?p=26799187#p26799187:svabyxqx said:
Paul Hill[/url]":svabyxqx]Adding chocolatey support in the base would fricken rule.
Like this?
https://github.com/OneGet/oneget/blob/master/readme.md
It will be in powershell 5.

Happy Dance ACTIVATED :)
 

Cookie.Monster

Ars Scholae Palatinae
666
Indeed... And chocolatey is just one provider. You can host your own, and they plan to add other repositories down the road (They've mentioned MS downloads, updates, Windows Store, etc. at the weekly community meeting).

From what I recall they plan to add some sort of classification to chocolatey as well, so you have the 'whatever the hell someone puts in it' community based packages, and more formal, vetted packages.

Also, Garrett mentioned he coded this for PowerShell v3. It's included in Windows Management Framework 5, but there's nothing saying you won't be able to use it with WMF 3.

Interesting stuff coming : )
 
Status
Not open for further replies.