Computer Hope

Software => Computer programming => Topic started by: Geek-9pm on February 10, 2009, 11:15:27 PM

Title: For a newbie, C++ or Java or what?
Post by: Geek-9pm on February 10, 2009, 11:15:27 PM
For a newbie, C++ or Java or what?

If a youngster comes to me and skds me what computer language should he study as his first or main language, What should I say.
Some of the things I had used are no longer very popular.

They say that the first language a person learns can influence his ability to write useful and practical programs that are easy to debug and maintain.
A few years ago Structured Programming was the order of the day.
But many popular programs do not enforce good structure. So they tell me. Never had time to make the program look nice. Just had to get it done.

It seems that now the thing today is use C++. Or maybe Java. (Do you spell it with a capital J?)  l.

So what should I tell a youngster? 
If I told him my most productive, commercial work was in
 DBASE, BASIC and Assembly his eyes might start to roll.
And he might say "That is so retro!"  ::)

Nobody even knows what Pl/M was.
So I did not put it in my list.


So what can I say? Anybody?
Title: Re: For a newbie, C++ or Java or what?
Post by: BC_Programmer on February 10, 2009, 11:39:34 PM
I'm almost tempted to say "batch programming" here LOL  ;D

if I was just starting, I'd go with VB .NET... I've ended up using VB6 for a long time, but I only really got into it while it was "waning" so to speak in favour of .NET- it was released in 98, after all.


So what should I tell a youngster? 
If I told him my most productive, commercial work was in
 DBASE, BASIC and Assembly his eyes might start to roll.
And he might say "That is so retro!"  ::)

If  he says that, then he knows the history of programming languages, and thus your task is completed  8)

C++ isn't really a good first language- but it is a natural step up after one learns C as a first programming language.
Title: Re: For a newbie, C++ or Java or what?
Post by: Ironman on February 11, 2009, 06:21:16 PM
Personally I believe learning C is a waste of time. Although C is a smaller, less complex language than C++, and is consequently easier to master. However, it is probably easier to get up to speed with C++, if you make effective use of the standard library. Some find C to be more elegant than C++, others think it to be too "unsafe". C++ programmers generally feel that it has features that make it easier to write good, robust, readable and maintainable code in than in C.

If you do decide to learn C++, there is little point in learning C itself first. Personally I would learn Java first(that's what I did) and then try C++. If you know Java well you then already know a lot of C++ already.
Title: Re: For a newbie, C++ or Java or what?
Post by: ultimatum on February 14, 2009, 06:13:25 PM
Quote
If you know Java well you then already know a lot of C++ already.

Same applies to C#. I've compared the two and the syntax is very similar in writing and plain simple. I find C# and Java to very easy to read unlike C++. But that's just me or may because I started learning C# before anything else.
Title: Re: For a newbie, C++ or Java or what?
Post by: BC_Programmer on February 14, 2009, 06:30:47 PM
that makes sense- C# is what Microsoft turned their J++ product into after the Sun lawsuit. Further enforcing this idea is the fact that the Early .NET Beta's had a new JVC compiler, IIRC.

C++ programmers generally feel that it has features that make it easier to write good, robust, readable and maintainable code in than in C.

If you know Java well you then already know a lot of C++ already.

I disagree myself on both of these points- within reason. C++ can be used for maintainable code.... But this ability drops off dramatically when those C++ classes need to be exposed through COM. the number of classes doubles after adding this, via the inclusion of various Class Factories as well as the requirement of each class to implement a defined set of interfaces, Such as IUnknown and IDispatch. Wether this is made any easier by ATL is another question entirely.

Additionally, Java and C++ use completely different paradigms.


C++ allows you to write C compatible code- IE- no classes or objects. Java requires ALL codfe to be written in classes.

C++ requires the programmer to manage memory. Java does so automatically via garbage collection.

C++ allows multiple inheritance, Java allows only one inheritance- multiple implementation of interfaces only. this is good, though, since if your inheriting from multiple classes, something is usually designed badly.

Lastly, C++ allows unmanaged pointers, whereby java will only let you make garbage collected references. Again- good for programming, but having the language run in a VM and constantly check references to object methods/fields can be the deal-breaker for time-critical applications.


This is why I've always thought of Java as much more similar to Visual Basic. I'd even go so far as to say that VB6 is to COM what Java is to CORBA.

Title: Re: For a newbie, C++ or Java or what?
Post by: Ironman on February 27, 2009, 10:04:29 AM
There are differences in Java and C++, but many(not all) concepts are the same in both languages; for example the concepts of data structures; trees, sets, maps, are extremely similar in both languages. What is was trying to say when I said
Quote
If you know Java well you then already know a lot of C++ already.
I meant to say one could could make a fairly easy transition from C++ to learn Java. But I still stand by my statement that learning C is a waste of time. You may want to look over or read some things about C, but taking a class entirely about C is a waste of time.
Title: Re: For a newbie, C++ or Java or what?
Post by: macdad- on February 27, 2009, 11:35:04 AM
for a beginner it should be BASIC or some dialect of it..(in my opinion)
Title: Re: For a newbie, C++ or Java or what?
Post by: Geek-9pm on February 27, 2009, 11:49:06 AM
The academic people are down on BASIC.
It, ah, sounds so,  ah ... basic.
Title: Re: For a newbie, C++ or Java or what?
Post by: BC_Programmer on February 27, 2009, 11:57:43 AM
BASIC... that rules out anything after VB6.
Title: Re: For a newbie, C++ or Java or what?
Post by: macdad- on February 27, 2009, 05:55:52 PM
BC,

VB6 is just as great as .NET in my opinion(it doesnt bloat up your system as much as VB6)  ;)
Title: Re: For a newbie, C++ or Java or what?
Post by: BC_Programmer on February 27, 2009, 08:01:06 PM
BC,

VB6 is just as great as .NET in my opinion(it doesnt bloat up your system as much as VB6)  ;)

 :o

do you mean that the other way around?

MSVBVM60.DLL: around 3MB

.NET framework- ~23MB - for the redistributable.


Installing these is totally different. all of Visual Studio 6 takes around 500MB- all of Visual Studio .NET (pretty much any version) usually weighs in around 3GB.

Like I said if you think VB .NET and version <=VB6 are similar you haven't used VB6 even close to as deeply as I have... although I imagine that's a given. I'm just not about to throw out thousands of modules and classes just to jump on the latest microsoft bandwagon, because god knows when Microsoft will release some "new thing" that we all have to use.
Title: Re: For a newbie, C++ or Java or what?
Post by: Geek-9pm on February 27, 2009, 08:20:14 PM
Quote
VB6 is just as great as .NET

I think VB6 is better that .NET,
 becaue ,NET is a cruel, oppressive monster that
Microsoft wants to impose of on everyone.

So that leaves out C++.

As for plain C, just as hard to learn as Assembler.
But without the advantages. Some Academic people say it is not a true High-Level language and does not encourage clear, logical development for use in a work group. Neither C or ASM is suitable for a teaching language.

That you for your comments. After reading this,
I would urge a newbie to go for Java.
It is wildly used, and has structure.  :D

Too bad I did not learn it.

Title: Re: For a newbie, C++ or Java or what?
Post by: BC_Programmer on February 27, 2009, 08:24:01 PM
Quote
VB6 is just as great as .NET

I think VB6 is better that .NET,
 becaue ,NET is a cruel, oppressive monster that
Microsoft wants to impose of on everyone.


OMG! Geek...

We AGREE on something 100%! I think this deserves a toast!  ;D

Title: Re: For a newbie, C++ or Java or what?
Post by: Geek-9pm on February 27, 2009, 08:44:35 PM
I will has me some Gin over ice.
Has me own bottle!
  :-*
Title: Re: For a newbie, C++ or Java or what?
Post by: macdad- on February 28, 2009, 10:52:13 AM
DONT get me wrong! i still use VB6, didnt you notice my post?

BC,

VB6 is just as great as .NET in my opinion(it doesnt bloat up your system as much as VB6)  ;)
Title: Re: For a newbie, C++ or Java or what?
Post by: BC_Programmer on February 28, 2009, 11:07:49 AM
what doesn't bloat up the system as much as VB6? it sure as heck isn't .NET...


usercontrols? ActiveX designers? Creating these is the only way to truly know pain.

Well that and modifying class instance Vtables...
Title: Re: For a newbie, C++ or Java or what?
Post by: macdad- on February 28, 2009, 11:09:12 AM
VB6 doesnt bloat up my rig like .NET does.

but still, VB6 is great
Title: Re: For a newbie, C++ or Java or what?
Post by: BC_Programmer on February 28, 2009, 11:11:23 AM
wanna see more impossibly complex code?  ;D
Title: Re: For a newbie, C++ or Java or what?
Post by: macdad- on February 28, 2009, 11:12:46 AM
no now.
Title: Re: For a newbie, C++ or Java or what?
Post by: BC_Programmer on February 28, 2009, 11:44:40 AM
no now.

Alright, I'll show you some simple code then.

Code: [Select]
Public Function GetDriveForNtDeviceName( _
   ByVal sDeviceName As String) As String
Dim sFoundDrive As String
Dim strdrives As String
Dim DriveStr() As String
Dim vDrive As String, i As Long, ret As Long
strdrives = Space$(256)
ret = GetLogicalDriveStrings(255, strdrives)
strdrives = Trim$(Replace$(strdrives, vbNullChar, " "))
DriveStr = Split(strdrives, " ")
   'For Each vDrive In GetDrives()
   For i = 0 To UBound(DriveStr)
    vDrive = DriveStr(i)
      If StrComp(GetNtDeviceNameForDrive(vDrive), sDeviceName, vbTextCompare) = 0 Then
         sFoundDrive = vDrive
         Exit For
      End If
   Next i
   
   GetDriveForNtDeviceName = sFoundDrive
   
End Function


Wait. whoops. I guess it's a matter of opinion...
Title: Re: For a newbie, C++ or Java or what?
Post by: macdad- on February 28, 2009, 11:55:59 AM
i think i get the Code, does it step through each existing Drive on a sys and list the Existing Drives?
Title: Re: For a newbie, C++ or Java or what?
Post by: BC_Programmer on February 28, 2009, 12:58:12 PM
actually, what it does is right in the name of the function  :P

GetDriveForNtDeviceName

for example passing in "\Device\HarddiskVolume1" on my PC returns "C:\"

same for "\Device\Floppy0" returning "A:\"
Title: Re: For a newbie, C++ or Java or what?
Post by: macdad- on February 28, 2009, 04:04:39 PM
atleast i knew that it was related to someone's drives
Title: Re: For a newbie, C++ or Java or what?
Post by: BC_Programmer on February 28, 2009, 08:59:26 PM
Only because of "GetLogicalDriveStrings"

I could have aliased the function to be, like, "lpGetFluffyKittyCount" or something.

THAT would make for some very confusing File library code...
Title: Re: For a newbie, C++ or Java or what?
Post by: macdad- on March 01, 2009, 03:44:28 PM
Hmm....lets see..here's my Slot Machine Game written entirely in VB6:

Code: [Select]
Dim s1 As Integer
Dim s2 As Integer
Dim s3 As Integer

Private Declare Function BeepAPI Lib "kernel32" Alias "Beep" (ByVal dwFrequency _
    As Long, ByVal dwMilliseconds As Long) As Long

Private Sub btnPull_Click()
If bag.Text = "0" Then
 MsgBox ("Your Broke! Game Over"), , "Game Over"
 End
Else
If Coins.Text = "" Then
MsgBox ("Insert a coin to play"), , "No Coin"
Else
bag = bag - 1
Randomize
s1 = Int(Rnd * 4)
s2 = Int(Rnd * 4)
s3 = Int(Rnd * 4)
BeepAPI 600, 100
'picture 1



If s1 = 0 Or s1 = 3 Then
Pic1.Picture = LoadPicture(App.Path & "\b.bmp")
End If
If s1 = 1 Then
Pic1.Picture = LoadPicture(App.Path & "\c.bmp")
End If
If s1 = 2 Then
Pic1.Picture = LoadPicture(App.Path & "\s.bmp")
End If
'picture 2
If s2 = 0 Or s2 = 3 Then
Pic2.Picture = LoadPicture(App.Path & "\b.bmp")
End If
If s2 = 1 Then
Pic2.Picture = LoadPicture(App.Path & "\c.bmp")
End If
If s2 = 2 Then
Pic2.Picture = LoadPicture(App.Path & "\s.bmp")
End If
'picture 3
If s3 = 0 Or s3 = 3 Then
Pic3.Picture = LoadPicture(App.Path & "\b.bmp")
End If
If s3 = 1 Then
Pic3.Picture = LoadPicture(App.Path & "\c.bmp")
End If
If s3 = 2 Then
Pic3.Picture = LoadPicture(App.Path & "\s.bmp")
End If
If s1 = 1 And s2 = 1 And s3 = 1 Then
 BeepAPI 800, 100
 BeepAPI 900, 100
 MsgBox ("You Win 5 Coins!"), , "Win"
bag = 5 + bag
End If
If s1 = 2 And s2 = 2 And s3 = 2 Then
 BeepAPI 800, 100
 BeepAPI 900, 100
 MsgBox ("Jack-Pot! 20 Coins!"), , "Win"
 bag = 20 + bag
End If
End If
End If
End Sub

Private Sub Form_Load()
bag.Text = bag
bag = 50
End Sub



[attachment deleted by admin]
Title: Re: For a newbie, C++ or Java or what?
Post by: Geek-9pm on March 01, 2009, 05:20:43 PM
Wat about Java?
If a newbie was to learn Java, what materials should he use?
(Not JavaScript, please!)
What IDE?
What text book?
What Web Sites?
Why don't the teach Java in high school courses?
And I don't want to see any more:
Code: [Select]
Dim s1 As Integer
Dim s2 As Integer
Dim s3 As Integer
That is so pointless.
Title: Re: For a newbie, C++ or Java or what?
Post by: BC_Programmer on March 01, 2009, 08:50:59 PM
And I don't want to see any more:
Code: [Select]
Dim s1 As Integer
Dim s2 As Integer
Dim s3 As Integer
That is so pointless.


yes... easier to do:
Code: [Select]
Dim s1%,s2%,s3%

Actually, really it isn't as much typing, since you can type "Dim s1 as I" and then space, due to autocomplete. Although a much better way would be

Code: [Select]
Dim s(1 to 3) as Integer




Anyways... for a Java IDE there is a free version available from sun, "NetBeans" I believe. If I recall it had some steep performance issues, though. I don't know of any Java textbooks myself- just get them to stay away from those insulting "learn Java in 24 hours!" type books  ::).
Title: Re: For a newbie, C++ or Java or what?
Post by: Geek-9pm on March 01, 2009, 09:01:33 PM
Quote
learn Java in 24 hours!"

...was that anything like "Learn Red Hat Linux in 21 Days" ?
Got rid of that book after two years.

===========================
VB6 is able to do variant types, -Right?
So it should know if you need Integer or not.
(Or am I thinking VB script.)
Just don't dim anything!. It should work anyway!
And if it goes slower, it is more fun!

Title: Re: For a newbie, C++ or Java or what?
Post by: BC_Programmer on March 01, 2009, 09:19:04 PM
Quote
learn Java in 24 hours!"

...was that anything like "Learn Red Hat Linux in 21 Days" ?
Got rid of that book after two years.


See what I mean? That's the quality of all of them, pretty much.


VB6 is able to do variant types, -Right?
So it should know if you need Integer or not.
(Or am I thinking VB script.)
Just don't dim anything!. It should work anyway!
And if it goes slower, it is more fun!
[/color]


In the default configuration VB6 will allow you to not need to declare any variables. However- Standard practice is to include "Option Explicit" at the top of all Form,Class, and Code modules. This is to avoid tricky typo errors being almost impossible to catch:

Code: [Select]

Private Function Multiply(ByVal Multiplicand1,ByVal Multiplicand2,Byval Multiplicand3)

Multiply = Multiplicand1 * Multiplicand2 * Multiplicend3

end Function


notice the typo? Well, if Option Explicit is on, so will VB... otherwise it will become a puzzle why every single return from the function is 0, regardless of the input.

That was a simple example though- in far more complicated procedures it becomes torture trying to find ann the implicitly declared variables. This is why it's easier, in the long run, the declare all variables.

I only use Variant for Procedure parameters that can accept multiple types, Or when I need to use the "Decimal" type, which is only valid via Variant variables.

Also it will go MUCH slower being dimmed as Variant/Implicitly as you've stated; although that isn't the real issue, one could easily change the default variable type via a DefInt,DefLng,DefSng,DefDbl,DefStr metacommand at the top of a module... but it simply makes it easier to debug.
Title: Re: For a newbie, C++ or Java or what?
Post by: macdad- on March 02, 2009, 06:57:45 AM
i wrote it like a year ago, and i didn't realize you could do that(besides the array method)

but still its pretty good, eh?
Title: Re: For a newbie, C++ or Java or what?
Post by: BC_Programmer on March 02, 2009, 09:10:26 AM
meh. I'm in no position to judge it anymore; heck I discarded my first project. My second project, I still have. a Spaceship game called "blackspace"... except it's mostly programmed in VB2 and a few things won't load properly... I seem to get a "Statement too complex" error when trying to load almost all of my old projects. (64 projects in my VBPROJ directory- and 165 within a "OLDSTUFF" folder beneath that. my "gravgame", a few projects I made for printing passwords on labels for the start of a school year... which fell through because the goofs higher up in the school district didn't send the excel spreadsheet on time.

Anyway, good memories mostly... although when I look at the code I almost barf, it makes me realize how much farther I can still go- I thought I was pretty good when I wrote, for example, a "Schedule" app for booking the non-dedicated computer labs at my old school, but I could practically rewrite the whole thing in a day now, and still it would be better.


Title: Re: For a newbie, C++ or Java or what?
Post by: Geek-9pm on March 02, 2009, 09:33:50 AM
This is all very interesting.  And it could illustrate why a Microsoft language is not a good place for a newbie to start out.
At first, the Microsoft Basic implementations were quite attractive.  But then as the operating system changed, Microsoft decided to make even more changes to Visual Basic.  More than perhaps needed to be a Basic language..
A student language has a strong structure and can do what it needs to do without the need to implement something different or deviant from the original design of that language.
Besides, there is usually some type of trapdoor available in most implementations to break out from the structure and do something in another language.  In the older versions of BASIC you could peek and poke and then call machine code and outperform some oddball thing.
Thank you all for your input.   :D
Title: Re: For a newbie, C++ or Java or what?
Post by: BC_Programmer on March 02, 2009, 09:47:12 AM
This is all very interesting.  And it could illustrate why a Microsoft language is not a good place for a newbie to start out.
At first, the Microsoft Basic implementations were quite attractive.  But then as the operating system changed, Microsoft decided to make even more changes to Visual Basic.  More than perhaps needed to be a Basic language..
A student language has a strong structure and can do what it needs to do without the need to implement something different or deviant from the original design of that language.
Besides, there is usually some type of trapdoor available in most implementations to break out from the structure and do something in another language.  In the older versions of BASIC you could peek and poke and then call machine code and outperform some oddball thing.
Thank you all for your input.   :D

you can still use ASM with VB6-

in fact I use it to subclass windows without crashing.

The trick is in the API call- you are "supposed" to pass in a pointer to a procedure that windows will call- but if you instead point it to a string variable with assembled ASM then it will actually execute the machine code that is present in the string variable.

But why the slimy hack? VB has an "AddressOf" operator, after all. The idea is to make it possible for class instances to subclass window messages, rather then require a Module to contain the WindowProc() and route the message to the proper Class instance based on the hwnd or something. Additionally it prevents the VB6 IDE from crashing during testing, since the ASM code remains in memory and is thus a valid JMP location throughout; before this "hack" the addressOf method was unstable during debugging, since pushing the stop button would mean that the  module containing the windowproc is unloaded- but windows still calls it for messages on the window, such as the WM_CLOSE message; it calls nonexistent code and crashes. HARD...


As far as "outperforming" the standard routines- this is generally quite easy via API routines. For example, instead of using DIR$, one can use the FindFirstFile(),FindNextFile() and FindClose() functions. This has the benefit of allowing recursive calls which aren't directly possible with DIR$() without cacheing folder names and recursing on them at the end of the procedure.

After dabbling with ASM for the subclassing code... well I think any future ASM work will avoid the windows platform...
Title: Re: For a newbie, C++ or Java or what?
Post by: macdad- on March 02, 2009, 07:15:51 PM
Visual basic just seems to have added alot more that it's ancestor and smaller dialects of it.